MCPcopy Create free account
hub / github.com/editablejs/editable / main

Function main

packages/breaker/src/generate_data.ts:18–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16process.exit(0)
17*/
18const main = async () => {
19 const UNICODE_VERSION = '14.0.0';
20
21 let nextClass = 1;
22 const classes: Record<string, number> = { Other: 0 };
23 const trie = new UnicodeTrieBuilder(classes.Other, 0);
24
25 // collect entries in the table into ranges to keep things smaller.
26 {
27 const url = `https://www.unicode.org/Public/${UNICODE_VERSION}/ucd/auxiliary/GraphemeBreakProperty.txt`;
28 const data = await (await fetch(url)).text();
29 let match: RegExpExecArray | null = null;
30 const re = /^([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s*;\s*([A-Za-z_]+)/gm;
31 match = re.exec(data);
32 while (match) {
33 const start = match[1];
34 const end = match[2] ? match[2] : start;
35 const type = match[3];
36 if (classes[type] == null) {
37 classes[type] = nextClass++;
38 }
39 trie.setRange(parseInt(start, 16), parseInt(end, 16), classes[type]);
40 match = re.exec(data);
41 }
42 }
43
44 const extpict = nextClass;
45 classes['ExtPict'] = nextClass++;
46 {
47 //const url = 'https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt' // Date: 2020-01-28, 20:52:38 GMT
48 const url = 'https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt'; // Date: 2020-01-28, 20:52:38 GMT
49 const data = await (await fetch(url)).text();
50 let match: RegExpExecArray | null = null;
51 const re = /^([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s*;\s*([A-Za-z_]+)/gm;
52 match = re.exec(data);
53 while (match) {
54 const start = match[1];
55 const end = match[2] ? match[2] : start;
56 const type = match[3];
57 if (type === 'Extended_Pictographic') {
58 trie.setRange(parseInt(start, 16), parseInt(end, 16), extpict);
59 }
60 match = re.exec(data);
61 }
62 }
63
64 const output = { trie: trie.toBuffer().toString('base64'), classes };
65 // write the trie and classes to a file
66 fs.writeFileSync(
67 `src/classes-v${UNICODE_VERSION}.ts`,
68 `const data = ${JSON.stringify(output)};\nexport default data;`,
69 );
70
71 const key = [];
72 for (const n in classes) {
73 key.push(n);
74 }
75 console.log(`const { ${key.join(', ')}} = classes-v${UNICODE_VERSION}.classes`);

Callers 1

generate_data.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…