@kensio/pinyinjs 1.9.9 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +7 -0
- package/README.md +27 -8
- package/data/core.entries +21 -21
- package/data/full.entries +17396 -17396
- package/data/manifest.json +9 -7
- package/data/standard.entries +3625 -3625
- package/dist/cli/lookup-commands.d.ts.map +1 -1
- package/dist/cli/lookup-commands.js +2 -44
- package/dist/cli/lookup-commands.js.map +1 -1
- package/dist/cli/lookup-entry.d.ts +12 -0
- package/dist/cli/lookup-entry.d.ts.map +1 -0
- package/dist/cli/lookup-entry.js +55 -0
- package/dist/cli/lookup-entry.js.map +1 -0
- package/dist/dictionary/artifact-format.d.ts +20 -1
- package/dist/dictionary/artifact-format.d.ts.map +1 -1
- package/dist/dictionary/artifact-format.js +37 -0
- package/dist/dictionary/artifact-format.js.map +1 -1
- package/dist/dictionary/artifact-read.d.ts.map +1 -1
- package/dist/dictionary/artifact-read.js +3 -7
- package/dist/dictionary/artifact-read.js.map +1 -1
- package/dist/dictionary/artifact.d.ts.map +1 -1
- package/dist/dictionary/artifact.js +2 -2
- package/dist/dictionary/artifact.js.map +1 -1
- package/dist/dictionary/build-assertions.d.ts.map +1 -1
- package/dist/dictionary/build-assertions.js +2 -0
- package/dist/dictionary/build-assertions.js.map +1 -1
- package/dist/dictionary/cedict-senses.d.ts +4 -3
- package/dist/dictionary/cedict-senses.d.ts.map +1 -1
- package/dist/dictionary/cedict-senses.js +7 -4
- package/dist/dictionary/cedict-senses.js.map +1 -1
- package/dist/dictionary/dictionary-entry.d.ts +8 -0
- package/dist/dictionary/dictionary-entry.d.ts.map +1 -1
- package/dist/dictionary/dictionary-entry.js +3 -1
- package/dist/dictionary/dictionary-entry.js.map +1 -1
- package/dist/dictionary/entry-invariants.d.ts +6 -0
- package/dist/dictionary/entry-invariants.d.ts.map +1 -1
- package/dist/dictionary/entry-invariants.js +0 -27
- package/dist/dictionary/entry-invariants.js.map +1 -1
- package/dist/dictionary/entry.d.ts +8 -0
- package/dist/dictionary/entry.d.ts.map +1 -1
- package/dist/dictionary/entry.js.map +1 -1
- package/dist/dictionary/locale-invariants.d.ts +3 -0
- package/dist/dictionary/locale-invariants.d.ts.map +1 -0
- package/dist/dictionary/locale-invariants.js +52 -0
- package/dist/dictionary/locale-invariants.js.map +1 -0
- package/dist/dictionary/locale.d.ts +5 -1
- package/dist/dictionary/locale.d.ts.map +1 -1
- package/dist/dictionary/locale.js +6 -1
- package/dist/dictionary/locale.js.map +1 -1
- package/dist/dictionary/merge-types.d.ts +10 -0
- package/dist/dictionary/merge-types.d.ts.map +1 -1
- package/dist/dictionary/merge-types.js +2 -0
- package/dist/dictionary/merge-types.js.map +1 -1
- package/dist/dictionary/merge-word.js +7 -6
- package/dist/dictionary/merge-word.js.map +1 -1
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +5 -1
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/dictionary/standard-readings.d.ts +42 -0
- package/dist/dictionary/standard-readings.d.ts.map +1 -0
- package/dist/dictionary/standard-readings.js +113 -0
- package/dist/dictionary/standard-readings.js.map +1 -0
- package/dist/dictionary/taiwan-notes.d.ts +13 -0
- package/dist/dictionary/taiwan-notes.d.ts.map +1 -0
- package/dist/dictionary/taiwan-notes.js +26 -0
- package/dist/dictionary/taiwan-notes.js.map +1 -0
- package/dist/dictionary/taiwan-reading.d.ts +22 -2
- package/dist/dictionary/taiwan-reading.d.ts.map +1 -1
- package/dist/dictionary/taiwan-reading.js +94 -25
- package/dist/dictionary/taiwan-reading.js.map +1 -1
- package/dist/dictionary/taiwan-settle.d.ts +22 -0
- package/dist/dictionary/taiwan-settle.d.ts.map +1 -0
- package/dist/dictionary/taiwan-settle.js +47 -0
- package/dist/dictionary/taiwan-settle.js.map +1 -0
- package/dist/search/match-readings.d.ts +2 -2
- package/dist/search/match-readings.d.ts.map +1 -1
- package/dist/search/match-readings.js +12 -7
- package/dist/search/match-readings.js.map +1 -1
- package/dist/sources/moe-workbook.d.ts +10 -0
- package/dist/sources/moe-workbook.d.ts.map +1 -0
- package/dist/sources/moe-workbook.js +89 -0
- package/dist/sources/moe-workbook.js.map +1 -0
- package/dist/sources/moe.d.ts +58 -0
- package/dist/sources/moe.d.ts.map +1 -0
- package/dist/sources/moe.js +79 -0
- package/dist/sources/moe.js.map +1 -0
- package/dist/sources/xlsx.d.ts +20 -0
- package/dist/sources/xlsx.d.ts.map +1 -0
- package/dist/sources/xlsx.js +78 -0
- package/dist/sources/xlsx.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading cells out of a spreadsheet's XML, as an `.xlsx` workbook stores
|
|
3
|
+
* them: a worksheet of cells, and a table of the strings they share.
|
|
4
|
+
*
|
|
5
|
+
* Only as much of the format as 教育部's downloads use. Formulas, styles and
|
|
6
|
+
* the other sheets of a workbook are never read.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The header row of a worksheet.
|
|
10
|
+
*/
|
|
11
|
+
export const HEADER_ROW = /<row r="1"[\s\S]*?<\/row>/u;
|
|
12
|
+
/**
|
|
13
|
+
* One cell of a worksheet: its attributes and whatever is inside it.
|
|
14
|
+
*/
|
|
15
|
+
const CELL = /<c ([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/gu;
|
|
16
|
+
/**
|
|
17
|
+
* One entry of the shared string table.
|
|
18
|
+
*/
|
|
19
|
+
const SHARED_STRING = /<si>([\s\S]*?)<\/si>/gu;
|
|
20
|
+
/**
|
|
21
|
+
* The text runs of a string, which rich text splits into several.
|
|
22
|
+
*/
|
|
23
|
+
const TEXT_RUN = /<t(?: [^>]*)?>([^<]*)<\/t>/gu;
|
|
24
|
+
/**
|
|
25
|
+
* Undo the escaping XML applies to text.
|
|
26
|
+
*/
|
|
27
|
+
function unescapeXml(text) {
|
|
28
|
+
return text
|
|
29
|
+
.replaceAll("<", "<")
|
|
30
|
+
.replaceAll(">", ">")
|
|
31
|
+
.replaceAll(""", '"')
|
|
32
|
+
.replaceAll("'", "'")
|
|
33
|
+
.replaceAll("&", "&");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The text of a cell's string, joining its runs.
|
|
37
|
+
*/
|
|
38
|
+
function textOf(xml) {
|
|
39
|
+
return unescapeXml([...xml.matchAll(TEXT_RUN)].map((run) => run[1] ?? "").join(""));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read the workbook's shared string table.
|
|
43
|
+
*/
|
|
44
|
+
export function readSharedStrings(xml) {
|
|
45
|
+
return [...xml.matchAll(SHARED_STRING)].map((entry) => textOf(entry[1] ?? ""));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Read a worksheet's cells into rows, keeping only the columns asked for.
|
|
49
|
+
*/
|
|
50
|
+
export function readRows(sheetXml, strings, wanted) {
|
|
51
|
+
const rows = new Map();
|
|
52
|
+
for (const cell of sheetXml.matchAll(CELL)) {
|
|
53
|
+
const attributes = cell[1] ?? "";
|
|
54
|
+
const reference = /\br="([A-Z]+)(\d+)"/u.exec(attributes);
|
|
55
|
+
const column = reference?.[1];
|
|
56
|
+
if (column === undefined || wanted?.has(column) === false) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const body = cell[2] ?? "";
|
|
60
|
+
const value = /<v>([^<]*)<\/v>/u.exec(body)?.[1];
|
|
61
|
+
let text;
|
|
62
|
+
if (/\bt="s"/u.test(attributes)) {
|
|
63
|
+
text = strings[Number(value)] ?? "";
|
|
64
|
+
}
|
|
65
|
+
else if (value === undefined) {
|
|
66
|
+
text = textOf(body);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
text = unescapeXml(value);
|
|
70
|
+
}
|
|
71
|
+
const row = Number(reference?.[2]);
|
|
72
|
+
const cells = rows.get(row) ?? new Map();
|
|
73
|
+
cells.set(column, text.trim());
|
|
74
|
+
rows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