UNPKG

5.57 kBJavaScriptView Raw
1var __create = Object.create;
2var __defProp = Object.defineProperty;
3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4var __getOwnPropNames = Object.getOwnPropertyNames;
5var __getProtoOf = Object.getPrototypeOf;
6var __hasOwnProp = Object.prototype.hasOwnProperty;
7var __export = (target, all) => {
8 for (var name in all)
9 __defProp(target, name, { get: all[name], enumerable: true });
10};
11var __copyProps = (to, from, except, desc) => {
12 if (from && typeof from === "object" || typeof from === "function") {
13 for (let key of __getOwnPropNames(from))
14 if (!__hasOwnProp.call(to, key) && key !== except)
15 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16 }
17 return to;
18};
19var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20 // If the importer is in node compatibility mode or this is not an ESM
21 // file that has been converted to a CommonJS file using a Babel-
22 // compatible transform (i.e. "__esModule" has not been set), then set
23 // "default" to the CommonJS "module.exports" for node compatibility.
24 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25 mod
26));
27var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28var stdin_exports = {};
29__export(stdin_exports, {
30 SVG_PATH_REGEX: () => SVG_PATH_REGEX,
31 URL_REGEX: () => URL_REGEX,
32 collator: () => collator,
33 getDirnameFromImportMeta: () => getDirnameFromImportMeta,
34 getIconDataPath: () => getIconDataPath,
35 getIconSlug: () => getIconSlug,
36 getIconsData: () => getIconsData,
37 getIconsDataString: () => getIconsDataString,
38 getThirdPartyExtensions: () => getThirdPartyExtensions,
39 htmlFriendlyToTitle: () => htmlFriendlyToTitle,
40 normalizeColor: () => normalizeColor,
41 normalizeNewlines: () => normalizeNewlines,
42 slugToVariableName: () => slugToVariableName,
43 svgToPath: () => svgToPath,
44 titleToHtmlFriendly: () => titleToHtmlFriendly,
45 titleToSlug: () => titleToSlug
46});
47module.exports = __toCommonJS(stdin_exports);
48var import_promises = __toESM(require("node:fs/promises"));
49var import_node_path = __toESM(require("node:path"));
50var import_node_url = require("node:url");
51const import_meta = {};
52const TITLE_TO_SLUG_REPLACEMENTS = {
53 "+": "plus",
54 ".": "dot",
55 "&": "and",
56 \u0111: "d",
57 \u0127: "h",
58 \u0131: "i",
59 \u0138: "k",
60 \u0140: "l",
61 \u0142: "l",
62 \u00DF: "ss",
63 \u0167: "t"
64};
65const TITLE_TO_SLUG_CHARS_REGEX = new RegExp(
66 `[${Object.keys(TITLE_TO_SLUG_REPLACEMENTS).join("")}]`,
67 "g"
68);
69const TITLE_TO_SLUG_RANGE_REGEX = /[^a-z\d]/g;
70const URL_REGEX = /^https:\/\/[^\s"']+$/;
71const SVG_PATH_REGEX = /^m[-mzlhvcsqtae\d,. ]+$/i;
72const getDirnameFromImportMeta = (importMetaUrl) => import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
73const getIconSlug = (icon) => icon.slug || titleToSlug(icon.title);
74const svgToPath = (svg) => svg.split('"', 8)[7];
75const titleToSlug = (title) => title.toLowerCase().replaceAll(
76 TITLE_TO_SLUG_CHARS_REGEX,
77 (char) => TITLE_TO_SLUG_REPLACEMENTS[char]
78).normalize("NFD").replaceAll(TITLE_TO_SLUG_RANGE_REGEX, "");
79const slugToVariableName = (slug) => {
80 const slugFirstLetter = slug[0].toUpperCase();
81 return `si${slugFirstLetter}${slug.slice(1)}`;
82};
83const titleToHtmlFriendly = (brandTitle) => brandTitle.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll(/./g, (char) => {
84 const charCode = char.codePointAt(0);
85 return charCode > 127 ? `&#${charCode};` : char;
86});
87const htmlFriendlyToTitle = (htmlFriendlyTitle) => htmlFriendlyTitle.replaceAll(
88 /&#(\d+);/g,
89 (_, number_) => String.fromCodePoint(Number.parseInt(number_, 10))
90).replaceAll(
91 /&(quot|amp|lt|gt);/g,
92 (_, reference) => ({ quot: '"', amp: "&", lt: "<", gt: ">" })[reference]
93);
94const getIconDataPath = (rootDirectory = getDirnameFromImportMeta(import_meta.url)) => {
95 return import_node_path.default.resolve(rootDirectory, "_data", "simple-icons.json");
96};
97const getIconsDataString = (rootDirectory = getDirnameFromImportMeta(import_meta.url)) => {
98 return import_promises.default.readFile(getIconDataPath(rootDirectory), "utf8");
99};
100const getIconsData = async (rootDirectory = getDirnameFromImportMeta(import_meta.url)) => {
101 const fileContents = await getIconsDataString(rootDirectory);
102 return JSON.parse(fileContents).icons;
103};
104const normalizeNewlines = (text) => {
105 return text.replaceAll("\r\n", "\n");
106};
107const normalizeColor = (text) => {
108 let color = text.replace("#", "").toUpperCase();
109 if (color.length < 6) {
110 color = [...color.slice(0, 3)].map((x) => x.repeat(2)).join("");
111 } else if (color.length > 6) {
112 color = color.slice(0, 6);
113 }
114 return color;
115};
116const getThirdPartyExtensions = async (readmePath = import_node_path.default.join(
117 getDirnameFromImportMeta(import_meta.url),
118 "README.md"
119)) => normalizeNewlines(await import_promises.default.readFile(readmePath, "utf8")).split("## Third-Party Extensions\n\n")[1].split("\n\n", 1)[0].split("\n").slice(2).map((line) => {
120 let [module2, author] = line.split(" | ");
121 module2 = module2.split('<img src="')[0];
122 return {
123 module: {
124 name: /\[(.+)]/.exec(module2)[1],
125 url: /\((.+)\)/.exec(module2)[1]
126 },
127 author: {
128 name: /\[(.+)]/.exec(author)[1],
129 url: /\((.+)\)/.exec(author)[1]
130 }
131 };
132});
133const collator = new Intl.Collator("en", {
134 usage: "search",
135 caseFirst: "upper"
136});