@kensio/pinyinjs 1.7.5 → 1.7.7
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/README.md +128 -123
- package/data/full.entries +2637 -2637
- package/data/manifest.json +9 -9
- package/data/script.map +168 -3
- package/data/standard.entries +8 -8
- package/dist/decode/chang-complement.d.ts +19 -0
- package/dist/decode/chang-complement.d.ts.map +1 -0
- package/dist/decode/chang-complement.js +113 -0
- package/dist/decode/chang-complement.js.map +1 -0
- package/dist/decode/chang-context.d.ts +29 -0
- package/dist/decode/chang-context.d.ts.map +1 -0
- package/dist/decode/chang-context.js +99 -0
- package/dist/decode/chang-context.js.map +1 -0
- package/dist/decode/chang-rule.d.ts +47 -0
- package/dist/decode/chang-rule.d.ts.map +1 -0
- package/dist/decode/chang-rule.js +188 -0
- package/dist/decode/chang-rule.js.map +1 -0
- package/dist/decode/confidence.d.ts +11 -3
- package/dist/decode/confidence.d.ts.map +1 -1
- package/dist/decode/confidence.js +11 -3
- package/dist/decode/confidence.js.map +1 -1
- package/dist/decode/convert-pipeline.d.ts.map +1 -1
- package/dist/decode/convert-pipeline.js +5 -4
- package/dist/decode/convert-pipeline.js.map +1 -1
- package/dist/decode/de-rule.d.ts +74 -0
- package/dist/decode/de-rule.d.ts.map +1 -0
- package/dist/decode/de-rule.js +199 -0
- package/dist/decode/de-rule.js.map +1 -0
- package/dist/decode/decode.d.ts +12 -25
- package/dist/decode/decode.d.ts.map +1 -1
- package/dist/decode/decode.js +10 -47
- package/dist/decode/decode.js.map +1 -1
- package/dist/decode/decoders.d.ts +9 -4
- package/dist/decode/decoders.d.ts.map +1 -1
- package/dist/decode/decoders.js +7 -7
- package/dist/decode/decoders.js.map +1 -1
- package/dist/decode/edge-context.d.ts +19 -0
- package/dist/decode/edge-context.d.ts.map +1 -1
- package/dist/decode/edge-context.js +41 -0
- package/dist/decode/edge-context.js.map +1 -1
- package/dist/decode/hint-lattice.d.ts.map +1 -1
- package/dist/decode/hint-lattice.js +17 -3
- package/dist/decode/hint-lattice.js.map +1 -1
- package/dist/decode/jiao-rule.d.ts +9 -3
- package/dist/decode/jiao-rule.d.ts.map +1 -1
- package/dist/decode/jiao-rule.js +44 -5
- package/dist/decode/jiao-rule.js.map +1 -1
- package/dist/decode/lattice-decode.d.ts +28 -0
- package/dist/decode/lattice-decode.d.ts.map +1 -0
- package/dist/decode/lattice-decode.js +48 -0
- package/dist/decode/lattice-decode.js.map +1 -0
- package/dist/decode/lattice-slice.d.ts +22 -6
- package/dist/decode/lattice-slice.d.ts.map +1 -1
- package/dist/decode/lattice-slice.js +24 -18
- package/dist/decode/lattice-slice.js.map +1 -1
- package/dist/decode/lattice-types.d.ts +27 -8
- package/dist/decode/lattice-types.d.ts.map +1 -1
- package/dist/decode/lattice-types.js +27 -8
- package/dist/decode/lattice-types.js.map +1 -1
- package/dist/decode/numbers.d.ts +0 -8
- package/dist/decode/numbers.d.ts.map +1 -1
- package/dist/decode/numbers.js +0 -10
- package/dist/decode/numbers.js.map +1 -1
- package/dist/decode/polyphone-rules.d.ts +7 -27
- package/dist/decode/polyphone-rules.d.ts.map +1 -1
- package/dist/decode/polyphone-rules.js +7 -155
- package/dist/decode/polyphone-rules.js.map +1 -1
- package/dist/decode/reading-rules.d.ts +1 -29
- package/dist/decode/reading-rules.d.ts.map +1 -1
- package/dist/decode/reading-rules.js +5 -69
- package/dist/decode/reading-rules.js.map +1 -1
- package/dist/decode/rules.d.ts +1 -1
- package/dist/decode/rules.d.ts.map +1 -1
- package/dist/decode/rules.js +1 -1
- package/dist/decode/rules.js.map +1 -1
- package/dist/decode/run-context.d.ts +33 -0
- package/dist/decode/run-context.d.ts.map +1 -0
- package/dist/decode/run-context.js +47 -0
- package/dist/decode/run-context.js.map +1 -0
- package/dist/decode/run-lattice.d.ts +13 -10
- package/dist/decode/run-lattice.d.ts.map +1 -1
- package/dist/decode/run-lattice.js +15 -12
- package/dist/decode/run-lattice.js.map +1 -1
- package/dist/decode/run-words.d.ts +17 -0
- package/dist/decode/run-words.d.ts.map +1 -0
- package/dist/decode/run-words.js +29 -0
- package/dist/decode/run-words.js.map +1 -0
- package/dist/decode/sandhi-input.d.ts +30 -0
- package/dist/decode/sandhi-input.d.ts.map +1 -0
- package/dist/decode/sandhi-input.js +35 -0
- package/dist/decode/sandhi-input.js.map +1 -0
- package/dist/decode/sandhi-tones.d.ts +33 -5
- package/dist/decode/sandhi-tones.d.ts.map +1 -1
- package/dist/decode/sandhi-tones.js +59 -8
- package/dist/decode/sandhi-tones.js.map +1 -1
- package/dist/decode/sandhi.d.ts +9 -6
- package/dist/decode/sandhi.d.ts.map +1 -1
- package/dist/decode/sandhi.js +10 -7
- package/dist/decode/sandhi.js.map +1 -1
- package/dist/decode/script-region.d.ts +15 -0
- package/dist/decode/script-region.d.ts.map +1 -0
- package/dist/decode/script-region.js +61 -0
- package/dist/decode/script-region.js.map +1 -0
- package/dist/decode/script-types.d.ts +11 -2
- package/dist/decode/script-types.d.ts.map +1 -1
- package/dist/decode/script-types.js +2 -1
- package/dist/decode/script-types.js.map +1 -1
- package/dist/decode/script-words.d.ts +7 -5
- package/dist/decode/script-words.d.ts.map +1 -1
- package/dist/decode/script-words.js +18 -25
- package/dist/decode/script-words.js.map +1 -1
- package/dist/decode/script.d.ts.map +1 -1
- package/dist/decode/script.js +2 -1
- package/dist/decode/script.js.map +1 -1
- package/dist/decode/write-run.d.ts +0 -7
- package/dist/decode/write-run.d.ts.map +1 -1
- package/dist/decode/write-run.js +4 -39
- package/dist/decode/write-run.js.map +1 -1
- package/dist/dictionary/cedict-senses.d.ts +7 -0
- package/dist/dictionary/cedict-senses.d.ts.map +1 -1
- package/dist/dictionary/cedict-senses.js +12 -0
- package/dist/dictionary/cedict-senses.js.map +1 -1
- package/dist/dictionary/constituent-repair.d.ts +36 -0
- package/dist/dictionary/constituent-repair.d.ts.map +1 -0
- package/dist/dictionary/constituent-repair.js +117 -0
- package/dist/dictionary/constituent-repair.js.map +1 -0
- package/dist/dictionary/measure-tone.d.ts +36 -0
- package/dist/dictionary/measure-tone.d.ts.map +1 -0
- package/dist/dictionary/measure-tone.js +139 -0
- package/dist/dictionary/measure-tone.js.map +1 -0
- package/dist/dictionary/merge-types.d.ts +13 -2
- package/dist/dictionary/merge-types.d.ts.map +1 -1
- package/dist/dictionary/merge-types.js.map +1 -1
- package/dist/dictionary/merge-walk.d.ts +27 -0
- package/dist/dictionary/merge-walk.d.ts.map +1 -0
- package/dist/dictionary/merge-walk.js +49 -0
- package/dist/dictionary/merge-walk.js.map +1 -0
- package/dist/dictionary/merge.d.ts +3 -3
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +24 -28
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/dictionary/overrides.d.ts +5 -0
- package/dist/dictionary/overrides.d.ts.map +1 -1
- package/dist/dictionary/overrides.js +5 -5
- package/dist/dictionary/overrides.js.map +1 -1
- package/dist/dictionary/script-tables.js +91 -13
- package/dist/dictionary/script-tables.js.map +1 -1
- package/dist/dictionary/word-readings.d.ts.map +1 -1
- package/dist/dictionary/word-readings.js +6 -0
- package/dist/dictionary/word-readings.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/script/glyphs.d.ts +9 -8
- package/dist/script/glyphs.d.ts.map +1 -1
- package/dist/script/glyphs.js +21 -48
- package/dist/script/glyphs.js.map +1 -1
- package/dist/script/reading-splits.d.ts +41 -0
- package/dist/script/reading-splits.d.ts.map +1 -0
- package/dist/script/reading-splits.js +98 -0
- package/dist/script/reading-splits.js.map +1 -0
- package/package.json +2 -2
package/dist/script/glyphs.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { toCharacters } from "./characters.js";
|
|
2
|
+
import { splitFormAt, splitFormsOf } from "./reading-splits.js";
|
|
3
|
+
export { isReadingScoped, isReadingSensitive } from "./reading-splits.js";
|
|
2
4
|
/**
|
|
3
5
|
* The regional 繁體 orthographies this package writes.
|
|
4
6
|
*
|
|
@@ -92,7 +94,7 @@ const CANONICAL_PAIRS = "僞偽衹只啓啟喫吃粧妝嫺嫻嬀媯峯峰捝挩
|
|
|
92
94
|
const HONG_KONG_PAIRS = "兌兑叄叁啟啓囪囱媼媪嫻嫺峰峯么幺悅悦慍愠戶户挩捝" +
|
|
93
95
|
"搵揾敓敚敘敍柺枴梲棁榲榅梁樑簷檐檯枱氳氲汙污洩泄" +
|
|
94
96
|
"涗涚溫温溼濕熅煴床牀痺痹著着睪睾稅税縕緼韁繮群羣" +
|
|
95
|
-
"
|
|
97
|
+
"脫脱膃腽臥卧臺台菸煙蒕蒀蔥葱蘊藴蛻蜕衛衞裡裏" +
|
|
96
98
|
"說説轀輼醞醖鉤鈎銳鋭閱閲鯰鮎鰮鰛麵麪顎齶";
|
|
97
99
|
/**
|
|
98
100
|
* Variant 繁體 forms mapped to the canonical form, as a table.
|
|
@@ -107,47 +109,6 @@ export const CANONICAL_FORMS = readPairs(CANONICAL_PAIRS);
|
|
|
107
109
|
* {@link CANONICAL_FORMS}.
|
|
108
110
|
*/
|
|
109
111
|
export const HONG_KONG_FORMS = readPairs(HONG_KONG_PAIRS);
|
|
110
|
-
/**
|
|
111
|
-
* The one glyph mapping whose answer depends on how the character is read.
|
|
112
|
-
*
|
|
113
|
-
* Taiwan writes 著 for every sense; Hong Kong splits it, writing 着 for the
|
|
114
|
-
* aspect particle and its relatives and keeping 著 for `zhù`. CC-CEDICT records
|
|
115
|
-
* the same split in its 简体 column — `著 着 [zhe5]` against `著 著 [zhu4]` —
|
|
116
|
-
* which is independent confirmation that the divide is real and where it falls.
|
|
117
|
-
*
|
|
118
|
-
* OpenCC resolves this with a phrase table. We resolve it with the reading,
|
|
119
|
-
* which is the point of difference this feature exists for, and which
|
|
120
|
-
* generalises to words no phrase table lists.
|
|
121
|
-
*
|
|
122
|
-
* `zhuó` is deliberately absent, and that is not an oversight: CC-CEDICT writes
|
|
123
|
-
* it both ways — `著 着 [zhuo2]` for wearing or applying, `著 著 [zhuo2]` for
|
|
124
|
-
* 執著 — so the reading genuinely does not settle it. It falls through to the
|
|
125
|
-
* default below and is reported as uncertain rather than guessed at silently.
|
|
126
|
-
*/
|
|
127
|
-
const READING_SPLITS = new Map([["著", new Map([["zhu", "著"]])]]);
|
|
128
|
-
/**
|
|
129
|
-
* A reading key ignoring tone and 儿化, which never bear on a glyph choice.
|
|
130
|
-
*
|
|
131
|
-
* Tone is dropped because the split that needs it — 著 — divides `zhù` from
|
|
132
|
-
* `zhe` and `zháo`, and those differ in their vowels as well, so the initial
|
|
133
|
-
* and final are enough and are what sources agree on most.
|
|
134
|
-
*/
|
|
135
|
-
function readingKey(syllable) {
|
|
136
|
-
if (syllable === undefined) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
return `${syllable.initial}${syllable.final}`;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Whether a character's regional form depends on how it is read.
|
|
143
|
-
*
|
|
144
|
-
* Exposed so that a conversion can report the choice as uncertain when it had
|
|
145
|
-
* no reading to go on, rather than presenting a default as though it were
|
|
146
|
-
* settled.
|
|
147
|
-
*/
|
|
148
|
-
export function isReadingSensitive(character) {
|
|
149
|
-
return READING_SPLITS.has(character);
|
|
150
|
-
}
|
|
151
112
|
/**
|
|
152
113
|
* Normalise one 繁體 character to the canonical form the dictionary stores.
|
|
153
114
|
*
|
|
@@ -208,12 +169,24 @@ export function toRegionalGlyph(character, region, syllable) {
|
|
|
208
169
|
if (region === DEFAULT_REGION) {
|
|
209
170
|
return character;
|
|
210
171
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
172
|
+
return (splitFormAt(character, syllable) ??
|
|
173
|
+
HONG_KONG_FORMS.get(character) ??
|
|
174
|
+
character);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Every form a character can take in a region, likeliest first.
|
|
178
|
+
*
|
|
179
|
+
* The region's own answer followed by whatever a reading would have kept, which
|
|
180
|
+
* is what a conversion made without a reading needs in order to say what it was
|
|
181
|
+
* choosing between.
|
|
182
|
+
*/
|
|
183
|
+
export function regionalGlyphsOf(character, region) {
|
|
184
|
+
return [
|
|
185
|
+
...new Set([
|
|
186
|
+
toRegionalGlyph(character, region),
|
|
187
|
+
...splitFormsOf(character),
|
|
188
|
+
]),
|
|
189
|
+
];
|
|
217
190
|
}
|
|
218
191
|
/**
|
|
219
192
|
* Write a whole canonical text in a region's orthography.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glyphs.js","sourceRoot":"","sources":["../../src/script/glyphs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"glyphs.js","sourceRoot":"","sources":["../../src/script/glyphs.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two 繁體 glyph mappings that a reading decides, and what reads them.
|
|
3
|
+
*
|
|
4
|
+
* Their own module because everything here is about one table of two entries,
|
|
5
|
+
* and `glyphs.ts` is otherwise about the flat pair tables. The split is what
|
|
6
|
+
* those tables cannot carry.
|
|
7
|
+
*/
|
|
8
|
+
import type { Syllable } from "../syllable/syllable.js";
|
|
9
|
+
/**
|
|
10
|
+
* The form a split writes at a reading, or undefined where none applies.
|
|
11
|
+
*
|
|
12
|
+
* A caller with no syllable gets undefined, which is what sends it to the flat
|
|
13
|
+
* table's answer and makes the choice a guess.
|
|
14
|
+
*/
|
|
15
|
+
export declare function splitFormAt(character: string, syllable: Syllable | undefined): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Every form a split writes for a character, in the order the table lists them.
|
|
18
|
+
*/
|
|
19
|
+
export declare function splitFormsOf(character: string): readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether a character's regional form depends on how it is read.
|
|
22
|
+
*
|
|
23
|
+
* Exposed so that a conversion can report the choice as uncertain when it had
|
|
24
|
+
* no reading to go on, rather than presenting a default as though it were
|
|
25
|
+
* settled.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isReadingSensitive(character: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a character's Hong Kong form applies at one reading rather than all.
|
|
30
|
+
*
|
|
31
|
+
* The two shapes {@link READING_SPLITS} holds, told apart by what the split
|
|
32
|
+
* writes. A split naming the character itself is an exception to a mapping that
|
|
33
|
+
* otherwise holds, so the flat table keeps it — 著 is 着 in Hong Kong except at
|
|
34
|
+
* `zhù`. A split naming some other form is the whole of the mapping, so the
|
|
35
|
+
* flat table must not carry it, or every reading would take the regional form.
|
|
36
|
+
*
|
|
37
|
+
* Read by the derivation in `scripts/build-data/glyph-tables.ts`, which would
|
|
38
|
+
* otherwise fail the build for a mapping OpenCC makes and this file declines.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isReadingScoped(character: string): boolean;
|
|
41
|
+
//# sourceMappingURL=reading-splits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reading-splits.d.ts","sourceRoot":"","sources":["../../src/script/reading-splits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAgExD;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,MAAM,GAAG,SAAS,CAEpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE1D"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The glyph mappings whose answer depends on how the character is read.
|
|
3
|
+
*
|
|
4
|
+
* A merge one standard makes and the other does not is a difference between
|
|
5
|
+
* them, and {@link import("./glyphs.js").HONG_KONG_FORMS} is that difference
|
|
6
|
+
* read off OpenCC's tables. The reading is what the tables cannot carry,
|
|
7
|
+
* because a merge is not always total: 蔘 is a variant of 參 in its `shēn`
|
|
8
|
+
* sense alone, so inverting Taiwan's 蔘 → 參 into a blanket 參 → 蔘 rewrites
|
|
9
|
+
* 參加, 參考, 參觀 and 參差 as well.
|
|
10
|
+
*
|
|
11
|
+
* OpenCC resolves this with a phrase table. We resolve it with the reading,
|
|
12
|
+
* which is the point of difference this feature exists for, and which
|
|
13
|
+
* generalises to words no phrase table lists.
|
|
14
|
+
*
|
|
15
|
+
* A reading names the form written at that reading, and the two entries here
|
|
16
|
+
* point opposite ways, which is what {@link isReadingScoped} is for:
|
|
17
|
+
*
|
|
18
|
+
* - **著** is Hong Kong's form by default and canonical at one reading. Taiwan
|
|
19
|
+
* writes 著 for every sense; Hong Kong splits it, writing 着 for the aspect
|
|
20
|
+
* particle and its relatives and keeping 著 for `zhù`. CC-CEDICT records the
|
|
21
|
+
* same split in its 简体 column — `著 着 [zhe5]` against `著 著 [zhu4]` — which
|
|
22
|
+
* is independent confirmation that the divide is real and where it falls. So
|
|
23
|
+
* 著 stays in the Hong Kong table and this names the exception.
|
|
24
|
+
* - **參** is canonical by default and Hong Kong's form at one reading. Of the
|
|
25
|
+
* four readings CC-CEDICT gives it — `cān`, `cēn`, `shēn`, `sān` — only `shēn`
|
|
26
|
+
* is the ginseng that 蔘 writes, and 參加 is far the commonest of the rest. So
|
|
27
|
+
* 參 is **not** in the Hong Kong table and this is the whole of its mapping.
|
|
28
|
+
*
|
|
29
|
+
* 著's `zhuó` is deliberately absent, and that is not an oversight: CC-CEDICT
|
|
30
|
+
* writes it both ways — `著 着 [zhuo2]` for wearing or applying, `著 著 [zhuo2]`
|
|
31
|
+
* for 執著 — so the reading genuinely does not settle it. It falls through to
|
|
32
|
+
* the default and is reported as uncertain rather than guessed at silently.
|
|
33
|
+
*
|
|
34
|
+
* **Two is the whole list**, and that is measured rather than assumed. Of the
|
|
35
|
+
* 58 mappings, 39 are stated by Hong Kong's own table and 19 are Taiwan merges
|
|
36
|
+
* read backwards, which is the only direction a partial merge can arrive from.
|
|
37
|
+
* Of those 19, 著 and 參 are the only two whose Hong Kong form covers fewer
|
|
38
|
+
* CC-CEDICT readings than the canonical: 著 has five against 着's four, 參 has
|
|
39
|
+
* four against 蔘's one, and the other 17 cover the same readings or more.
|
|
40
|
+
*/
|
|
41
|
+
const READING_SPLITS = new Map([
|
|
42
|
+
["著", new Map([["zhu", "著"]])],
|
|
43
|
+
["參", new Map([["shen", "蔘"]])],
|
|
44
|
+
]);
|
|
45
|
+
/**
|
|
46
|
+
* A reading key ignoring tone and 儿化, which never bear on a glyph choice.
|
|
47
|
+
*
|
|
48
|
+
* Tone is dropped because the split that needs it — 著 — divides `zhù` from
|
|
49
|
+
* `zhe` and `zháo`, and those differ in their vowels as well, so the initial
|
|
50
|
+
* and final are enough and are what sources agree on most.
|
|
51
|
+
*/
|
|
52
|
+
function readingKey(syllable) {
|
|
53
|
+
if (syllable === undefined) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return `${syllable.initial}${syllable.final}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The form a split writes at a reading, or undefined where none applies.
|
|
60
|
+
*
|
|
61
|
+
* A caller with no syllable gets undefined, which is what sends it to the flat
|
|
62
|
+
* table's answer and makes the choice a guess.
|
|
63
|
+
*/
|
|
64
|
+
export function splitFormAt(character, syllable) {
|
|
65
|
+
return READING_SPLITS.get(character)?.get(readingKey(syllable) ?? "");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Every form a split writes for a character, in the order the table lists them.
|
|
69
|
+
*/
|
|
70
|
+
export function splitFormsOf(character) {
|
|
71
|
+
return [...(READING_SPLITS.get(character)?.values() ?? [])];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether a character's regional form depends on how it is read.
|
|
75
|
+
*
|
|
76
|
+
* Exposed so that a conversion can report the choice as uncertain when it had
|
|
77
|
+
* no reading to go on, rather than presenting a default as though it were
|
|
78
|
+
* settled.
|
|
79
|
+
*/
|
|
80
|
+
export function isReadingSensitive(character) {
|
|
81
|
+
return READING_SPLITS.has(character);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether a character's Hong Kong form applies at one reading rather than all.
|
|
85
|
+
*
|
|
86
|
+
* The two shapes {@link READING_SPLITS} holds, told apart by what the split
|
|
87
|
+
* writes. A split naming the character itself is an exception to a mapping that
|
|
88
|
+
* otherwise holds, so the flat table keeps it — 著 is 着 in Hong Kong except at
|
|
89
|
+
* `zhù`. A split naming some other form is the whole of the mapping, so the
|
|
90
|
+
* flat table must not carry it, or every reading would take the regional form.
|
|
91
|
+
*
|
|
92
|
+
* Read by the derivation in `scripts/build-data/glyph-tables.ts`, which would
|
|
93
|
+
* otherwise fail the build for a mapping OpenCC makes and this file declines.
|
|
94
|
+
*/
|
|
95
|
+
export function isReadingScoped(character) {
|
|
96
|
+
return splitFormsOf(character).some((form) => form !== character);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=reading-splits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reading-splits.js","sourceRoot":"","sources":["../../src/script/reading-splits.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,cAAc,GAGhB,IAAI,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;CAChC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,QAA8B;IAChD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,SAAiB,EACjB,QAA8B;IAE9B,OAAO,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AACpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kensio/pinyinjs",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "Chinese hanzi to pinyin conversion",
|
|
5
5
|
"repository": "https://github.com/KensioSoftware/pinyinjs",
|
|
6
6
|
"homepage": "https://pinyinjs.dev",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
70
70
|
"fta-cli": "^3.0.0",
|
|
71
71
|
"jiti": "^2.7.0",
|
|
72
|
-
"oxfmt": "^0.
|
|
72
|
+
"oxfmt": "^0.63.0",
|
|
73
73
|
"oxlint": "^1.77.0",
|
|
74
74
|
"oxlint-tsgolint": "^7.0.2001",
|
|
75
75
|
"semantic-release": "25.0.9",
|