-
Notifications
You must be signed in to change notification settings - Fork 17
/
dump-inner-parts.js
executable file
·51 lines (43 loc) · 1.49 KB
/
dump-inner-parts.js
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
51
// check that every character is part of the trivial "parts" set
// (performed automatically by make.js)
import {PRINTER, NF, IDNA} from './unicode-version.js';
import {readFileSync} from 'node:fs';
import {print_section } from './utils.js';
// valid from idna
//let {valid} = IDNA;
// valid from spec
let {groups} = JSON.parse(readFileSync(new URL('./output/spec.json', import.meta.url)));
let valid = new Set(groups.flatMap(g => [...g.primary, ...g.secondary]));
let tally = [];
let all_inner = new Set();
let valid_parts = new Set([...valid, ...NF.nfd(valid)]);
for (let cp0 of valid) {
let parts = NF.inner_parts(cp0);
while (tally.length <= parts.length) tally.push(0);
tally[parts.length]++;
if (!parts.length) continue;
console.log(`${PRINTER.desc_for_cp(cp0)} (${parts.length})`);
for (let cp of parts) {
all_inner.add(cp);
console.log(` ${PRINTER.desc_for_cp(cp)}`);
if (!valid_parts.has(cp)) {
throw new Error('missing part');
}
}
}
console.log(`Total: ${all_inner.size}`);
console.log();
print_section('Length Distribution');
for (let i = 0; i < tally.length; i++) {
console.log(` ${i} = ${tally[i]}`);
}
function debug(cp) {
console.log(` NFC: ${PRINTER.desc_for_cps(NF.nfc([cp]))}`);
console.log(` NFD: ${PRINTER.desc_for_cps(NF.nfd([cp]))}`);
console.log(`Parts: ${PRINTER.desc_for_cps(NF.inner_parts(cp))}`);
console.log();
}
console.log();
print_section('Known Examples');
debug(0xAC01); // hangul
debug(0x390); // greek