@kensio/pinyinjs 1.9.9 → 1.10.1

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.
Files changed (107) hide show
  1. package/NOTICE +7 -0
  2. package/README.md +28 -9
  3. package/data/core.entries +49 -48
  4. package/data/core.freq +0 -0
  5. package/data/core.keys +1 -0
  6. package/data/full.counts +0 -0
  7. package/data/full.entries +17438 -17431
  8. package/data/full.freq +0 -0
  9. package/data/full.keys +7 -0
  10. package/data/manifest.json +19 -17
  11. package/data/script.map +5 -3
  12. package/data/standard.entries +3653 -3652
  13. package/data/standard.freq +0 -0
  14. package/data/standard.keys +1 -0
  15. package/dist/cli/lookup-commands.d.ts.map +1 -1
  16. package/dist/cli/lookup-commands.js +2 -44
  17. package/dist/cli/lookup-commands.js.map +1 -1
  18. package/dist/cli/lookup-entry.d.ts +12 -0
  19. package/dist/cli/lookup-entry.d.ts.map +1 -0
  20. package/dist/cli/lookup-entry.js +55 -0
  21. package/dist/cli/lookup-entry.js.map +1 -0
  22. package/dist/dictionary/artifact-format.d.ts +20 -1
  23. package/dist/dictionary/artifact-format.d.ts.map +1 -1
  24. package/dist/dictionary/artifact-format.js +37 -0
  25. package/dist/dictionary/artifact-format.js.map +1 -1
  26. package/dist/dictionary/artifact-read.d.ts.map +1 -1
  27. package/dist/dictionary/artifact-read.js +3 -7
  28. package/dist/dictionary/artifact-read.js.map +1 -1
  29. package/dist/dictionary/artifact.d.ts.map +1 -1
  30. package/dist/dictionary/artifact.js +2 -2
  31. package/dist/dictionary/artifact.js.map +1 -1
  32. package/dist/dictionary/build-assertions.d.ts.map +1 -1
  33. package/dist/dictionary/build-assertions.js +2 -0
  34. package/dist/dictionary/build-assertions.js.map +1 -1
  35. package/dist/dictionary/cedict-senses.d.ts +4 -3
  36. package/dist/dictionary/cedict-senses.d.ts.map +1 -1
  37. package/dist/dictionary/cedict-senses.js +7 -4
  38. package/dist/dictionary/cedict-senses.js.map +1 -1
  39. package/dist/dictionary/character-defaults.d.ts +8 -0
  40. package/dist/dictionary/character-defaults.d.ts.map +1 -1
  41. package/dist/dictionary/character-defaults.js +20 -0
  42. package/dist/dictionary/character-defaults.js.map +1 -1
  43. package/dist/dictionary/dictionary-entry.d.ts +8 -0
  44. package/dist/dictionary/dictionary-entry.d.ts.map +1 -1
  45. package/dist/dictionary/dictionary-entry.js +3 -1
  46. package/dist/dictionary/dictionary-entry.js.map +1 -1
  47. package/dist/dictionary/entry-invariants.d.ts +6 -0
  48. package/dist/dictionary/entry-invariants.d.ts.map +1 -1
  49. package/dist/dictionary/entry-invariants.js +0 -27
  50. package/dist/dictionary/entry-invariants.js.map +1 -1
  51. package/dist/dictionary/entry.d.ts +8 -0
  52. package/dist/dictionary/entry.d.ts.map +1 -1
  53. package/dist/dictionary/entry.js.map +1 -1
  54. package/dist/dictionary/locale-invariants.d.ts +3 -0
  55. package/dist/dictionary/locale-invariants.d.ts.map +1 -0
  56. package/dist/dictionary/locale-invariants.js +52 -0
  57. package/dist/dictionary/locale-invariants.js.map +1 -0
  58. package/dist/dictionary/locale.d.ts +5 -1
  59. package/dist/dictionary/locale.d.ts.map +1 -1
  60. package/dist/dictionary/locale.js +6 -1
  61. package/dist/dictionary/locale.js.map +1 -1
  62. package/dist/dictionary/merge-types.d.ts +16 -0
  63. package/dist/dictionary/merge-types.d.ts.map +1 -1
  64. package/dist/dictionary/merge-types.js +2 -0
  65. package/dist/dictionary/merge-types.js.map +1 -1
  66. package/dist/dictionary/merge-word.js +7 -6
  67. package/dist/dictionary/merge-word.js.map +1 -1
  68. package/dist/dictionary/merge.d.ts.map +1 -1
  69. package/dist/dictionary/merge.js +18 -4
  70. package/dist/dictionary/merge.js.map +1 -1
  71. package/dist/dictionary/reference-readings.d.ts +21 -0
  72. package/dist/dictionary/reference-readings.d.ts.map +1 -0
  73. package/dist/dictionary/reference-readings.js +86 -0
  74. package/dist/dictionary/reference-readings.js.map +1 -0
  75. package/dist/dictionary/standard-readings.d.ts +42 -0
  76. package/dist/dictionary/standard-readings.d.ts.map +1 -0
  77. package/dist/dictionary/standard-readings.js +113 -0
  78. package/dist/dictionary/standard-readings.js.map +1 -0
  79. package/dist/dictionary/taiwan-notes.d.ts +13 -0
  80. package/dist/dictionary/taiwan-notes.d.ts.map +1 -0
  81. package/dist/dictionary/taiwan-notes.js +26 -0
  82. package/dist/dictionary/taiwan-notes.js.map +1 -0
  83. package/dist/dictionary/taiwan-reading.d.ts +22 -2
  84. package/dist/dictionary/taiwan-reading.d.ts.map +1 -1
  85. package/dist/dictionary/taiwan-reading.js +94 -25
  86. package/dist/dictionary/taiwan-reading.js.map +1 -1
  87. package/dist/dictionary/taiwan-settle.d.ts +22 -0
  88. package/dist/dictionary/taiwan-settle.d.ts.map +1 -0
  89. package/dist/dictionary/taiwan-settle.js +47 -0
  90. package/dist/dictionary/taiwan-settle.js.map +1 -0
  91. package/dist/search/match-readings.d.ts +2 -2
  92. package/dist/search/match-readings.d.ts.map +1 -1
  93. package/dist/search/match-readings.js +12 -7
  94. package/dist/search/match-readings.js.map +1 -1
  95. package/dist/sources/moe-workbook.d.ts +10 -0
  96. package/dist/sources/moe-workbook.d.ts.map +1 -0
  97. package/dist/sources/moe-workbook.js +89 -0
  98. package/dist/sources/moe-workbook.js.map +1 -0
  99. package/dist/sources/moe.d.ts +58 -0
  100. package/dist/sources/moe.d.ts.map +1 -0
  101. package/dist/sources/moe.js +79 -0
  102. package/dist/sources/moe.js.map +1 -0
  103. package/dist/sources/xlsx.d.ts +20 -0
  104. package/dist/sources/xlsx.d.ts.map +1 -0
  105. package/dist/sources/xlsx.js +78 -0
  106. package/dist/sources/xlsx.js.map +1 -0
  107. package/package.json +1 -1
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Taking the readings out of a 教育部 dictionary's workbook.
3
+ *
4
+ * The workbook has seventeen columns, and only the headword, the order of its
5
+ * readings, its 漢語拼音 and its variant reading are read. Definitions,
6
+ * examples, synonyms and the rest are never parsed. See `moe.ts` for what is
7
+ * done with the readings.
8
+ */
9
+ import { HEADER_ROW, readRows, readSharedStrings } from "./xlsx.js";
10
+ /**
11
+ * The columns this package reads, by the name the header row gives them.
12
+ *
13
+ * Found by name rather than by letter, because the two dictionaries lay their
14
+ * columns out differently: 《重編國語辭典修訂本》 has 漢語拼音 in column L and
15
+ * 《國語辭典簡編本》 in column J. A release that drops one fails the build
16
+ * rather than reading the wrong column.
17
+ */
18
+ const HEADERS = {
19
+ word: "字詞名",
20
+ order: "多音排序",
21
+ pinyin: "漢語拼音",
22
+ variantKind: "變體類型",
23
+ variant: "變體漢語拼音",
24
+ };
25
+ /**
26
+ * The kinds of variant reading that are readings of the word itself.
27
+ */
28
+ const VARIANT_KINDS = new Set(["又音", "語音", "讀音", "或讀"]);
29
+ /**
30
+ * Turn a dictionary's worksheet into a table of headword, order and reading.
31
+ *
32
+ * Done once, when the download is cached, so the build reads a small table and
33
+ * never the 125 MB of XML the spreadsheet is made of. The output is one
34
+ * tab-separated line per reading, with a fourth column where the entry gives
35
+ * a variant reading, and the header row is dropped.
36
+ */
37
+ export function tabulateMoeWorkbook(sharedStringsXml, sheetXml) {
38
+ const strings = readSharedStrings(sharedStringsXml);
39
+ const header = readRows(HEADER_ROW.exec(sheetXml)?.[0] ?? "", strings).get(1);
40
+ // 變體類型 carries its legend in the header, and the two dictionaries'
41
+ // legends differ, so a header is matched on how it starts.
42
+ const columnOf = (name) => {
43
+ const found = [...(header ?? [])].find(([, text]) => text.startsWith(name))?.[0];
44
+ if (found === undefined) {
45
+ throw new Error(`教育部 dictionary has no ${name} column`);
46
+ }
47
+ return found;
48
+ };
49
+ const columns = {
50
+ word: columnOf(HEADERS.word),
51
+ order: columnOf(HEADERS.order),
52
+ pinyin: columnOf(HEADERS.pinyin),
53
+ variantKind: columnOf(HEADERS.variantKind),
54
+ variant: columnOf(HEADERS.variant),
55
+ };
56
+ const rows = readRows(sheetXml, strings, new Set(Object.values(columns)));
57
+ const lines = [];
58
+ for (const [row, cells] of rows) {
59
+ const word = cells.get(columns.word) ?? "";
60
+ const pinyin = cells.get(columns.pinyin) ?? "";
61
+ if (row === 1 || word === "" || pinyin === "") {
62
+ continue;
63
+ }
64
+ const kind = cells.get(columns.variantKind) ?? "";
65
+ const variant = VARIANT_KINDS.has(kind)
66
+ ? (cells.get(columns.variant) ?? "")
67
+ : "";
68
+ lines.push([
69
+ word,
70
+ orderOf(cells.get(columns.order)),
71
+ spaced(pinyin),
72
+ ...(variant === "" ? [] : [spaced(variant)]),
73
+ ].join("\t"));
74
+ }
75
+ return `${lines.join("\n")}\n`;
76
+ }
77
+ /**
78
+ * A headword's 多音排序, which is blank for a headword with one reading.
79
+ */
80
+ function orderOf(order) {
81
+ return order === undefined || order === "" ? "0" : order;
82
+ }
83
+ /**
84
+ * A reading with its syllables separated by single spaces.
85
+ */
86
+ function spaced(pinyin) {
87
+ return pinyin.replaceAll(/\s+/gu, " ");
88
+ }
89
+ //# sourceMappingURL=moe-workbook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moe-workbook.js","sourceRoot":"","sources":["../../src/sources/moe-workbook.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,WAAW,EAAE,MAAM;IACnB,OAAO,EAAE,QAAQ;CACT,CAAC;AAEX;;GAEG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,gBAAwB,EACxB,QAAgB;IAEhB,MAAM,OAAO,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,MA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.
3
+ *
4
+ * `concise` is 《國語辭典簡編本》, which describes current usage, and
5
+ * `revised` is 《重編國語辭典修訂本》, which adds the literary and historical.
6
+ */
7
+ export type MoeDictionary = "concise" | "revised";
8
+ /**
9
+ * One reading 教育部 gives a headword.
10
+ */
11
+ export interface MoeReading {
12
+ readonly dictionary: MoeDictionary;
13
+ /**
14
+ * Where the reading stands among the headword's readings.
15
+ *
16
+ * 0 for a headword with one reading. A headword with several numbers them
17
+ * from 1, and 1 is the reading the dictionary lists first: 和 is `hé` at 1
18
+ * and `hàn` at 5, 期 `qí` at 1 and `qī` at 2.
19
+ */
20
+ readonly order: number;
21
+ /**
22
+ * The reading as tokens {@link import("../dictionary/reading.js").readAlignedReading}
23
+ * accepts, one per syllable, with 儿化 split off as its own `r5` token.
24
+ */
25
+ readonly readings: readonly string[];
26
+ /**
27
+ * A second reading the dictionary gives the same entry, where it gives one.
28
+ *
29
+ * Only the kinds that are readings of the word: 又音, an alternative, and
30
+ * the 語音 and 讀音 pair of colloquial and literary readings. 變, which
31
+ * records a tone change in connected speech such as 一 before a fourth tone,
32
+ * is left out, since the merge stores tones before sandhi.
33
+ */
34
+ readonly variant?: readonly string[];
35
+ }
36
+ /**
37
+ * Read the table {@link tabulateMoeWorkbook} writes, keyed by headword.
38
+ *
39
+ * Headwords are 繁體, as Taiwan writes them. A headword's readings come back
40
+ * in the dictionary's own order.
41
+ */
42
+ export declare function parseMoeReadings(text: string, dictionary: MoeDictionary): ReadonlyMap<string, readonly MoeReading[]>;
43
+ /**
44
+ * Two dictionaries' readings as one.
45
+ *
46
+ * 《國語辭典簡編本》 is the one that describes current usage, and for a word
47
+ * both list it wins. 《重編國語辭典修訂本》 is four times its size and records
48
+ * the literary and historical readings too, so where the two list a word it is
49
+ * often the older one that the larger dictionary leads with: 玩 is `wàn` there
50
+ * before `wán`, 鹽 `yàn` before `yán`, and 它們 is `tuō men`. Only the words
51
+ * the concise dictionary leaves out are taken from it.
52
+ *
53
+ * A character keeps the readings of both, the concise dictionary's first.
54
+ * The merge only ever asks whether a character's reading is listed, and the
55
+ * concise dictionary leaves out some current ones: it has no 差 `chà`.
56
+ */
57
+ export declare function preferReadings(first: ReadonlyMap<string, readonly MoeReading[]>, second: ReadonlyMap<string, readonly MoeReading[]>): ReadonlyMap<string, readonly MoeReading[]>;
58
+ //# sourceMappingURL=moe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moe.d.ts","sourceRoot":"","sources":["../../src/sources/moe.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAqBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,aAAa,GACxB,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC,CAqB5C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC,EACjD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC,GACjD,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC,CAO5C"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The readings of 教育部's two dictionaries of the 國語 standard,
3
+ * 《國語辭典簡編本》 and 《重編國語辭典修訂本》.
4
+ *
5
+ * Read from the table `moe-workbook.ts` takes out of each download, which holds
6
+ * a headword, the order of its readings, its 漢語拼音 and any variant reading,
7
+ * and nothing of the dictionaries' own text. See docs/dictionaries for why the
8
+ * readings alone are taken and what the licence says about them.
9
+ */
10
+ import { isSingleCharacter } from "../script/characters.js";
11
+ import { readSyllable } from "../syllable/syllable.js";
12
+ import { ERHUA_TOKEN } from "../dictionary/reading.js";
13
+ /**
14
+ * Split a reading into the tokens the merge aligns against a headword.
15
+ *
16
+ * 教育部 writes 儿化 on the syllable, as `yī huǐr` for 一會兒, where the merge
17
+ * expects CC-CEDICT's shape of a syllable followed by `r5`. A syllable that
18
+ * reads as 儿化 is split back into that shape, which leaves 兒 with a token to
19
+ * account for it; `ér` and `èr` are syllables of their own and stay whole.
20
+ */
21
+ function tokensOf(pinyin) {
22
+ return pinyin
23
+ .split(" ")
24
+ .filter((token) => token !== "")
25
+ .flatMap((token) => readSyllable(token)?.erhua === true
26
+ ? [token.slice(0, -1), ERHUA_TOKEN]
27
+ : [token]);
28
+ }
29
+ /**
30
+ * Read the table {@link tabulateMoeWorkbook} writes, keyed by headword.
31
+ *
32
+ * Headwords are 繁體, as Taiwan writes them. A headword's readings come back
33
+ * in the dictionary's own order.
34
+ */
35
+ export function parseMoeReadings(text, dictionary) {
36
+ const readings = new Map();
37
+ for (const line of text.split("\n")) {
38
+ const [word = "", order = "", pinyin = "", variant = ""] = line.split("\t");
39
+ if (word === "" || pinyin === "") {
40
+ continue;
41
+ }
42
+ const headword = word.normalize("NFC");
43
+ const listed = readings.get(headword) ?? [];
44
+ listed.push({
45
+ dictionary,
46
+ order: Number(order) || 0,
47
+ readings: tokensOf(pinyin),
48
+ ...(variant !== "" && { variant: tokensOf(variant) }),
49
+ });
50
+ readings.set(headword, listed);
51
+ }
52
+ for (const listed of readings.values()) {
53
+ listed.sort((left, right) => left.order - right.order);
54
+ }
55
+ return readings;
56
+ }
57
+ /**
58
+ * Two dictionaries' readings as one.
59
+ *
60
+ * 《國語辭典簡編本》 is the one that describes current usage, and for a word
61
+ * both list it wins. 《重編國語辭典修訂本》 is four times its size and records
62
+ * the literary and historical readings too, so where the two list a word it is
63
+ * often the older one that the larger dictionary leads with: 玩 is `wàn` there
64
+ * before `wán`, 鹽 `yàn` before `yán`, and 它們 is `tuō men`. Only the words
65
+ * the concise dictionary leaves out are taken from it.
66
+ *
67
+ * A character keeps the readings of both, the concise dictionary's first.
68
+ * The merge only ever asks whether a character's reading is listed, and the
69
+ * concise dictionary leaves out some current ones: it has no 差 `chà`.
70
+ */
71
+ export function preferReadings(first, second) {
72
+ const merged = new Map(second);
73
+ for (const [word, readings] of first) {
74
+ const extra = isSingleCharacter(word) ? (second.get(word) ?? []) : [];
75
+ merged.set(word, [...readings, ...extra]);
76
+ }
77
+ return merged;
78
+ }
79
+ //# sourceMappingURL=moe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moe.js","sourceRoot":"","sources":["../../src/sources/moe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAuCvD;;;;;;;GAOG;AACH,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,MAAM;SACV,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC;SAC/B,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACjB,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI;QACjC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC;QACnC,CAAC,CAAC,CAAC,KAAK,CAAC,CACZ,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,UAAyB;I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C;IAC/B,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,20 @@
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 declare const HEADER_ROW: RegExp;
12
+ /**
13
+ * Read the workbook's shared string table.
14
+ */
15
+ export declare function readSharedStrings(xml: string): readonly string[];
16
+ /**
17
+ * Read a worksheet's cells into rows, keeping only the columns asked for.
18
+ */
19
+ export declare function readRows(sheetXml: string, strings: readonly string[], wanted?: ReadonlySet<string>): Map<number, Map<string, string>>;
20
+ //# sourceMappingURL=xlsx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xlsx.d.ts","sourceRoot":"","sources":["../../src/sources/xlsx.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,QAA+B,CAAC;AAsCvD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAIhE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAC3B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0BlC"}
@@ -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("&lt;", "<")
30
+ .replaceAll("&gt;", ">")
31
+ .replaceAll("&quot;", '"')
32
+ .replaceAll("&apos;", "'")
33
+ .replaceAll("&amp;", "&");
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.set(row, cells);
75
+ }
76
+ return rows;
77
+ }
78
+ //# sourceMappingURL=xlsx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xlsx.js","sourceRoot":"","sources":["../../src/sources/xlsx.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAEvD;;GAEG;AACH,MAAM,IAAI,GAAG,uCAAuC,CAAC;AAErD;;GAEG;AACH,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAE/C;;GAEG;AACH,MAAM,QAAQ,GAAG,8BAA8B,CAAC;AAEhD;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI;SACR,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;SACvB,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;SACvB,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC;SACzB,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC;SACzB,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,WAAW,CAChB,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,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AAC;QACtC,CAAC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;QACzD,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/pinyinjs",
3
- "version": "1.9.9",
3
+ "version": "1.10.1",
4
4
  "description": "Chinese hanzi to pinyin conversion",
5
5
  "repository": "https://github.com/KensioSoftware/pinyinjs",
6
6
  "homepage": "https://pinyinjs.dev",