MCPcopy Create free account
hub / github.com/fontsource/fontsource / readIcons

Function readIcons

registry/scripts/google-icons.ts:114–154  ·  view source on GitHub ↗
(
	snapshot: GitSnapshot,
	path: string,
)

Source from the content-addressed store, hash-verified

112};
113
114const readIcons = (
115 snapshot: GitSnapshot,
116 path: string,
117): { manifest: FamilyIcons; modified: string } => {
118 const categoryCatalog = readIconCategories(snapshot);
119 const contents = snapshot.read(path);
120 const icons = contents
121 .toString('utf8')
122 .trim()
123 .split(/\r?\n/)
124 .map((line, index) => {
125 const match = line.match(/^(\S+)\s+([0-9a-fA-F]+)$/);
126 if (!match?.[1] || !match[2]) {
127 throw new Error(`${path}:${index + 1} is not a codepoint mapping`);
128 }
129 return {
130 name: match[1],
131 codepoint: Number.parseInt(match[2], 16),
132 categories: categoryCatalog.categories.get(match[1]),
133 };
134 })
135 .toSorted(
136 (left, right) =>
137 compareStrings(left.name, right.name) ||
138 left.codepoint - right.codepoint,
139 );
140 const changed = snapshot.lastChanged(path);
141 return {
142 manifest: familyIconsSchema.parse({
143 inputModes: ['codepoint', 'name-ligature'],
144 icons,
145 categoriesSource: categoryCatalog.source,
146 source: {
147 revision: changed.revision,
148 path,
149 sha256: sha256(contents),
150 },
151 }),
152 modified: changed.date,
153 };
154};
155
156const supportsCodepoint = (
157 ranges: Awaited<ReturnType<typeof inspectFont>>['unicodeRanges'],

Callers 1

writeFamilyFunction · 0.85

Calls 5

compareStringsFunction · 0.90
sha256Function · 0.90
readIconCategoriesFunction · 0.85
toStringMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected