-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgen-mdi-list.mjs
50 lines (41 loc) · 1.19 KB
/
gen-mdi-list.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import fs from "fs";
import readline from "readline";
const codepoints = {};
const availableIcons = [];
let fileStream = fs.createReadStream("node_modules/material-icons/css/_codepoints.scss");
let rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
for await (const line of rl) {
const r = /^\s*"(\w+)": (\w+)/.exec(line);
if (r != null) {
codepoints[r[1]] = r[2];
}
}
fileStream.close();
fileStream = fs.createReadStream("node_modules/material-icons/index.d.ts");
rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
for await (const line of rl) {
const r = /^\s*"(\w+)"/.exec(line);
if (r != null) {
availableIcons.push(r[1]);
}
}
fileStream.close();
console.log(`import { type MaterialIcon } from "material-icons/index.d";`);
console.log("");
console.log("type IconListItem = Record<MaterialIcon, number>;");
console.log("");
console.log("export const iconCodepoints: IconListItem = {");
for (const icon of availableIcons) {
if (icon in codepoints) {
console.log(` "${icon}": 0x${codepoints[icon]},`);
}
}
console.log("};");
console.log("");
console.log('export { type MaterialIcon } from "material-icons/index.d";');