@kensio/pinyinjs 0.1.0-beta.0 → 1.0.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/CHANGELOG.md +87 -0
- package/NOTICE +7 -0
- package/README.md +144 -19
- package/data/full.entries +13400 -13400
- package/data/manifest.json +4 -4
- package/data/standard.entries +2492 -2492
- package/dist/cli/arguments.d.ts +67 -0
- package/dist/cli/arguments.d.ts.map +1 -1
- package/dist/cli/arguments.js +79 -0
- package/dist/cli/arguments.js.map +1 -1
- package/dist/cli/colour.d.ts +77 -0
- package/dist/cli/colour.d.ts.map +1 -0
- package/dist/cli/colour.js +117 -0
- package/dist/cli/colour.js.map +1 -0
- package/dist/cli/commands.d.ts +49 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +404 -42
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/environment.d.ts.map +1 -1
- package/dist/cli/environment.js +20 -0
- package/dist/cli/environment.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +43 -16
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/run.d.ts +11 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +4 -2
- package/dist/cli/run.js.map +1 -1
- package/dist/decode/convert.d.ts +20 -0
- package/dist/decode/convert.d.ts.map +1 -1
- package/dist/decode/convert.js +170 -12
- package/dist/decode/convert.js.map +1 -1
- package/dist/decode/decode.d.ts +3 -2
- package/dist/decode/decode.d.ts.map +1 -1
- package/dist/decode/decode.js +17 -4
- package/dist/decode/decode.js.map +1 -1
- package/dist/decode/reading-rules.d.ts +56 -0
- package/dist/decode/reading-rules.d.ts.map +1 -0
- package/dist/decode/reading-rules.js +107 -0
- package/dist/decode/reading-rules.js.map +1 -0
- package/dist/decode/rules.d.ts +66 -0
- package/dist/decode/rules.d.ts.map +1 -0
- package/dist/decode/rules.js +138 -0
- package/dist/decode/rules.js.map +1 -0
- package/dist/decode/sandhi.d.ts +1 -1
- package/dist/decode/sandhi.d.ts.map +1 -1
- package/dist/decode/sandhi.js +60 -1
- package/dist/decode/sandhi.js.map +1 -1
- package/dist/decode/word.d.ts +18 -0
- package/dist/decode/word.d.ts.map +1 -1
- package/dist/dictionary/artifact.d.ts.map +1 -1
- package/dist/dictionary/artifact.js +28 -1
- package/dist/dictionary/artifact.js.map +1 -1
- package/dist/dictionary/dictionary.d.ts +9 -0
- package/dist/dictionary/dictionary.d.ts.map +1 -1
- package/dist/dictionary/dictionary.js +7 -0
- package/dist/dictionary/dictionary.js.map +1 -1
- package/dist/dictionary/entry.d.ts +12 -0
- package/dist/dictionary/entry.d.ts.map +1 -1
- package/dist/dictionary/entry.js.map +1 -1
- package/dist/dictionary/merge.d.ts +3 -1
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +19 -1
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/format/transcription.d.ts +52 -0
- package/dist/format/transcription.d.ts.map +1 -0
- package/dist/format/transcription.js +88 -0
- package/dist/format/transcription.js.map +1 -0
- package/dist/index.d.ts +24 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/numerals/cardinal.d.ts +39 -0
- package/dist/numerals/cardinal.d.ts.map +1 -0
- package/dist/numerals/cardinal.js +111 -0
- package/dist/numerals/cardinal.js.map +1 -0
- package/dist/numerals/characters.d.ts +31 -0
- package/dist/numerals/characters.d.ts.map +1 -0
- package/dist/numerals/characters.js +80 -0
- package/dist/numerals/characters.js.map +1 -0
- package/dist/numerals/numerals.d.ts +76 -0
- package/dist/numerals/numerals.d.ts.map +1 -0
- package/dist/numerals/numerals.js +119 -0
- package/dist/numerals/numerals.js.map +1 -0
- package/dist/numerals/text.d.ts +52 -0
- package/dist/numerals/text.d.ts.map +1 -0
- package/dist/numerals/text.js +248 -0
- package/dist/numerals/text.js.map +1 -0
- package/dist/orthography/grouping.d.ts +56 -11
- package/dist/orthography/grouping.d.ts.map +1 -1
- package/dist/orthography/grouping.js +109 -35
- package/dist/orthography/grouping.js.map +1 -1
- package/dist/orthography/idiom-list.d.ts +56 -0
- package/dist/orthography/idiom-list.d.ts.map +1 -0
- package/dist/orthography/idiom-list.js +296 -0
- package/dist/orthography/idiom-list.js.map +1 -0
- package/dist/orthography/idioms.d.ts +18 -0
- package/dist/orthography/idioms.d.ts.map +1 -0
- package/dist/orthography/idioms.js +22 -0
- package/dist/orthography/idioms.js.map +1 -0
- package/dist/orthography/reduplication.d.ts +52 -0
- package/dist/orthography/reduplication.d.ts.map +1 -0
- package/dist/orthography/reduplication.js +99 -0
- package/dist/orthography/reduplication.js.map +1 -0
- package/dist/orthography/rule.d.ts +50 -0
- package/dist/orthography/rule.d.ts.map +1 -0
- package/dist/orthography/rule.js +101 -0
- package/dist/orthography/rule.js.map +1 -0
- package/dist/sources/cedict.d.ts +23 -0
- package/dist/sources/cedict.d.ts.map +1 -1
- package/dist/sources/cedict.js +28 -0
- package/dist/sources/cedict.js.map +1 -1
- package/dist/syllable/syllable.d.ts +1 -1
- package/dist/syllable/syllable.d.ts.map +1 -1
- package/dist/syllable/syllable.js +2 -37
- package/dist/syllable/syllable.js.map +1 -1
- package/dist/tone/tone-mark.d.ts +23 -0
- package/dist/tone/tone-mark.d.ts.map +1 -1
- package/dist/tone/tone-mark.js +49 -0
- package/dist/tone/tone-mark.js.map +1 -1
- package/dist/transcription/bopomofo.d.ts +46 -0
- package/dist/transcription/bopomofo.d.ts.map +1 -0
- package/dist/transcription/bopomofo.js +371 -0
- package/dist/transcription/bopomofo.js.map +1 -0
- package/dist/transcription/gwoyeu.d.ts +32 -0
- package/dist/transcription/gwoyeu.d.ts.map +1 -0
- package/dist/transcription/gwoyeu.js +491 -0
- package/dist/transcription/gwoyeu.js.map +1 -0
- package/dist/transcription/ipa.d.ts +40 -0
- package/dist/transcription/ipa.d.ts.map +1 -0
- package/dist/transcription/ipa.js +221 -0
- package/dist/transcription/ipa.js.map +1 -0
- package/dist/transcription/spelling-index.d.ts +23 -0
- package/dist/transcription/spelling-index.d.ts.map +1 -0
- package/dist/transcription/spelling-index.js +61 -0
- package/dist/transcription/spelling-index.js.map +1 -0
- package/dist/transcription/wade-giles.d.ts +108 -0
- package/dist/transcription/wade-giles.d.ts.map +1 -0
- package/dist/transcription/wade-giles.js +656 -0
- package/dist/transcription/wade-giles.js.map +1 -0
- package/dist/transcription/yale.d.ts +43 -0
- package/dist/transcription/yale.d.ts.map +1 -0
- package/dist/transcription/yale.js +242 -0
- package/dist/transcription/yale.js.map +1 -0
- package/package.json +9 -5
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Syllable } from "../syllable/syllable.js";
|
|
2
|
+
/**
|
|
3
|
+
* Spell a syllable in Yale without its tone: 西 xī is `syi`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function writeYaleSpelling(syllable: Syllable): string;
|
|
6
|
+
/**
|
|
7
|
+
* How a Yale syllable writes its tone.
|
|
8
|
+
*
|
|
9
|
+
* Diacritics are the system's own notation and the same four pinyin uses, which
|
|
10
|
+
* is where pinyin took them from; `numbers` writes a digit on the line instead,
|
|
11
|
+
* and is the only one of the three that can say "neutral" rather than leaving
|
|
12
|
+
* it to be inferred.
|
|
13
|
+
*/
|
|
14
|
+
export interface YaleOptions {
|
|
15
|
+
readonly tones?: "marks" | "numbers" | "none";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Write a syllable in Yale: 就 jiù becomes `jyòu`.
|
|
19
|
+
*
|
|
20
|
+
* The mark goes on the base rather than on the 儿化 suffix, so 花儿 huār is
|
|
21
|
+
* `hwār`. An unwritten tone stays unwritten, as everywhere else in this
|
|
22
|
+
* package; the neutral tone is written unmarked, which is Yale's own convention
|
|
23
|
+
* and pinyin's, and means the two are told apart only by `numbers`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function writeYale(syllable: Syllable, options?: YaleOptions): string;
|
|
26
|
+
/**
|
|
27
|
+
* Write a word in Yale, one syllable after another.
|
|
28
|
+
*
|
|
29
|
+
* Solid, as Yale's own textbooks write a word — 中國 is `Jūnggwó` — rather than
|
|
30
|
+
* hyphenated as Wade-Giles has it. That leaves the syllable boundary unmarked
|
|
31
|
+
* and so unrecoverable, which is the same gap pinyin fills with the 隔音符号 and
|
|
32
|
+
* which this module does not attempt: reading takes a syllable at a time.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeYaleWord(syllables: readonly Syllable[], options?: YaleOptions): string;
|
|
35
|
+
/**
|
|
36
|
+
* Read a Yale syllable: `jyòu` becomes 就 jiù.
|
|
37
|
+
*
|
|
38
|
+
* Returns every syllable the spelling stands for, which is one for all but the
|
|
39
|
+
* handful `docs/romanization/` counts. Empty for anything that is not Yale at
|
|
40
|
+
* all.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readYale(text: string): readonly Syllable[];
|
|
43
|
+
//# sourceMappingURL=yale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yale.d.ts","sourceRoot":"","sources":["../../src/transcription/yale.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AA8KxD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAE5D;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;CAC/C;AAkBD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,WAAgB,GACxB,MAAM,CAWR;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,OAAO,GAAE,WAAgB,GACxB,MAAM,CAER;AAwBD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE,CAK1D"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { applyToneMark, normaliseSuperscript, stripToneMarks, toneDiacritic, toneFromMarks, } from "../tone/tone-mark.js";
|
|
2
|
+
import { toneFromNotation } from "../tone/tone.js";
|
|
3
|
+
import { indexInventory, readIndexed } from "./spelling-index.js";
|
|
4
|
+
/**
|
|
5
|
+
* How each initial is spelled.
|
|
6
|
+
*
|
|
7
|
+
* The aspiration pairs read as English does — pinyin b is `b` and pinyin p is
|
|
8
|
+
* `p` — which is the whole point of the system and the one respect in which it
|
|
9
|
+
* is easier than Wade-Giles. The palatals borrow the retroflex letters, since
|
|
10
|
+
* the two series never contrast, except for x: `sy` keeps 西 `syi` from being
|
|
11
|
+
* read as 詩 `shr`.
|
|
12
|
+
*/
|
|
13
|
+
const INITIAL_SPELLINGS = new Map([
|
|
14
|
+
["b", "b"],
|
|
15
|
+
["p", "p"],
|
|
16
|
+
["m", "m"],
|
|
17
|
+
["f", "f"],
|
|
18
|
+
["d", "d"],
|
|
19
|
+
["t", "t"],
|
|
20
|
+
["n", "n"],
|
|
21
|
+
["l", "l"],
|
|
22
|
+
["g", "g"],
|
|
23
|
+
["k", "k"],
|
|
24
|
+
["h", "h"],
|
|
25
|
+
["j", "j"],
|
|
26
|
+
["q", "ch"],
|
|
27
|
+
["x", "sy"],
|
|
28
|
+
["zh", "j"],
|
|
29
|
+
["ch", "ch"],
|
|
30
|
+
["sh", "sh"],
|
|
31
|
+
["r", "r"],
|
|
32
|
+
["z", "dz"],
|
|
33
|
+
["c", "ts"],
|
|
34
|
+
["s", "s"],
|
|
35
|
+
]);
|
|
36
|
+
/**
|
|
37
|
+
* How each final is spelled after an initial.
|
|
38
|
+
*
|
|
39
|
+
* The i and ü groups are written with y and the u group with w, which is why
|
|
40
|
+
* so few of them need a second form with no initial in front: 家 jiā is `jya`
|
|
41
|
+
* and 呀 ya is `ya`, the same final spelled the same way.
|
|
42
|
+
*/
|
|
43
|
+
const FINAL_SPELLINGS = {
|
|
44
|
+
a: "a",
|
|
45
|
+
o: "o",
|
|
46
|
+
e: "e",
|
|
47
|
+
ê: "e",
|
|
48
|
+
er: "er",
|
|
49
|
+
ai: "ai",
|
|
50
|
+
ei: "ei",
|
|
51
|
+
ao: "au",
|
|
52
|
+
ou: "ou",
|
|
53
|
+
an: "an",
|
|
54
|
+
en: "en",
|
|
55
|
+
ang: "ang",
|
|
56
|
+
eng: "eng",
|
|
57
|
+
ong: "ung",
|
|
58
|
+
i: "i",
|
|
59
|
+
ia: "ya",
|
|
60
|
+
io: "yo",
|
|
61
|
+
ie: "ye",
|
|
62
|
+
iao: "yau",
|
|
63
|
+
iou: "you",
|
|
64
|
+
ian: "yan",
|
|
65
|
+
in: "in",
|
|
66
|
+
iang: "yang",
|
|
67
|
+
ing: "ing",
|
|
68
|
+
iong: "yung",
|
|
69
|
+
u: "u",
|
|
70
|
+
ua: "wa",
|
|
71
|
+
uo: "wo",
|
|
72
|
+
uai: "wai",
|
|
73
|
+
uei: "wei",
|
|
74
|
+
uan: "wan",
|
|
75
|
+
uen: "wun",
|
|
76
|
+
uang: "wang",
|
|
77
|
+
ueng: "weng",
|
|
78
|
+
ü: "yu",
|
|
79
|
+
üe: "ywe",
|
|
80
|
+
üan: "ywan",
|
|
81
|
+
ün: "yun",
|
|
82
|
+
m: "m",
|
|
83
|
+
n: "n",
|
|
84
|
+
ng: "ng",
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The five finals that are spelled differently with no initial in front of
|
|
88
|
+
* them.
|
|
89
|
+
*
|
|
90
|
+
* Everything else in the i, u and ü groups already carries its y or w, so this
|
|
91
|
+
* is a much shorter list than Wade-Giles needs. 文 wen is the odd one: after an
|
|
92
|
+
* initial the same final is `wun` (敦 dwun), because there the w is the medial
|
|
93
|
+
* rather than the onset.
|
|
94
|
+
*/
|
|
95
|
+
const ZERO_INITIAL_SPELLINGS = new Map([
|
|
96
|
+
["i", "yi"],
|
|
97
|
+
["in", "yin"],
|
|
98
|
+
["ing", "ying"],
|
|
99
|
+
["u", "wu"],
|
|
100
|
+
["uen", "wen"],
|
|
101
|
+
]);
|
|
102
|
+
/**
|
|
103
|
+
* The initials after which pinyin's -o final is really -uo, and Yale writes it
|
|
104
|
+
* so: 波 bō is `bwo`, against 咯 lo which is `lo`.
|
|
105
|
+
*/
|
|
106
|
+
const LABIAL_INITIALS = new Set(["b", "p", "m", "f"]);
|
|
107
|
+
/**
|
|
108
|
+
* The letter the empty rhyme is written with after each series.
|
|
109
|
+
*
|
|
110
|
+
* 知 is `jr` and 資 is `dz`: the i of zhi and zi is the syllabic continuation
|
|
111
|
+
* of the initial rather than a vowel, and Yale writes that continuation as a
|
|
112
|
+
* letter. Where the initial already ends in it — `r` and `dz` — it is not
|
|
113
|
+
* written twice, which is why 日 rì is `r` and 字 zì is `dz`.
|
|
114
|
+
*/
|
|
115
|
+
const EMPTY_RHYME_LETTERS = new Map([
|
|
116
|
+
["zh", "r"],
|
|
117
|
+
["ch", "r"],
|
|
118
|
+
["sh", "r"],
|
|
119
|
+
["r", "r"],
|
|
120
|
+
["z", "z"],
|
|
121
|
+
["c", "z"],
|
|
122
|
+
["s", "z"],
|
|
123
|
+
]);
|
|
124
|
+
/**
|
|
125
|
+
* The 儿化 suffix, which Yale writes as pinyin does.
|
|
126
|
+
*/
|
|
127
|
+
const ERHUA_SUFFIX = "r";
|
|
128
|
+
/**
|
|
129
|
+
* How a final is spelled after a given initial.
|
|
130
|
+
*/
|
|
131
|
+
function finalSpelling(initial, final) {
|
|
132
|
+
if (initial === "") {
|
|
133
|
+
return ZERO_INITIAL_SPELLINGS.get(final) ?? FINAL_SPELLINGS[final];
|
|
134
|
+
}
|
|
135
|
+
if (final === "i" && EMPTY_RHYME_LETTERS.has(initial)) {
|
|
136
|
+
return EMPTY_RHYME_LETTERS.get(initial) ?? "";
|
|
137
|
+
}
|
|
138
|
+
if (final === "o" && LABIAL_INITIALS.has(initial)) {
|
|
139
|
+
return "wo";
|
|
140
|
+
}
|
|
141
|
+
return FINAL_SPELLINGS[final];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Spell a syllable in Yale, without its tone or its 儿化 suffix.
|
|
145
|
+
*
|
|
146
|
+
* The two collapses live here rather than in the tables, because both are the
|
|
147
|
+
* same rule — Yale does not write a letter twice — and both are visible only
|
|
148
|
+
* once the initial and the final are side by side.
|
|
149
|
+
*/
|
|
150
|
+
function baseSpelling(syllable) {
|
|
151
|
+
const { initial, final } = syllable;
|
|
152
|
+
const written = finalSpelling(initial, final);
|
|
153
|
+
const spelt = INITIAL_SPELLINGS.get(initial) ?? "";
|
|
154
|
+
// sy + ya is sya, and dz + z is dz.
|
|
155
|
+
return spelt.endsWith(written.slice(0, 1))
|
|
156
|
+
? `${spelt}${written.slice(1)}`
|
|
157
|
+
: `${spelt}${written}`;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Spell a syllable in Yale without its tone: 西 xī is `syi`.
|
|
161
|
+
*/
|
|
162
|
+
export function writeYaleSpelling(syllable) {
|
|
163
|
+
return `${baseSpelling(syllable)}${syllable.erhua === true ? ERHUA_SUFFIX : ""}`;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Put the tone mark on, including on the syllables with no vowel to take it.
|
|
167
|
+
*
|
|
168
|
+
* `applyToneMark` follows the standard's a-then-o-or-e-then-last-vowel rule and
|
|
169
|
+
* gives back what it was handed when nothing can carry a mark, which is exactly
|
|
170
|
+
* the seven empty-rhyme syllables: `jr`, `chr`, `shr`, `r`, `dz`, `tsz` and
|
|
171
|
+
* `sz`. Those take the mark on their last letter, since a syllable with no
|
|
172
|
+
* vowel still has a tone.
|
|
173
|
+
*/
|
|
174
|
+
function markTone(spelling, tone) {
|
|
175
|
+
const marked = applyToneMark(spelling, tone);
|
|
176
|
+
return marked === spelling
|
|
177
|
+
? `${spelling}${toneDiacritic(tone)}`.normalize("NFC")
|
|
178
|
+
: marked;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Write a syllable in Yale: 就 jiù becomes `jyòu`.
|
|
182
|
+
*
|
|
183
|
+
* The mark goes on the base rather than on the 儿化 suffix, so 花儿 huār is
|
|
184
|
+
* `hwār`. An unwritten tone stays unwritten, as everywhere else in this
|
|
185
|
+
* package; the neutral tone is written unmarked, which is Yale's own convention
|
|
186
|
+
* and pinyin's, and means the two are told apart only by `numbers`.
|
|
187
|
+
*/
|
|
188
|
+
export function writeYale(syllable, options = {}) {
|
|
189
|
+
const { tones = "marks" } = options;
|
|
190
|
+
const base = baseSpelling(syllable);
|
|
191
|
+
const suffix = syllable.erhua === true ? ERHUA_SUFFIX : "";
|
|
192
|
+
const { tone } = syllable;
|
|
193
|
+
if (tone === undefined || tones === "none") {
|
|
194
|
+
return `${base}${suffix}`;
|
|
195
|
+
}
|
|
196
|
+
return tones === "numbers"
|
|
197
|
+
? `${base}${suffix}${String(tone)}`
|
|
198
|
+
: `${markTone(base, tone)}${suffix}`;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Write a word in Yale, one syllable after another.
|
|
202
|
+
*
|
|
203
|
+
* Solid, as Yale's own textbooks write a word — 中國 is `Jūnggwó` — rather than
|
|
204
|
+
* hyphenated as Wade-Giles has it. That leaves the syllable boundary unmarked
|
|
205
|
+
* and so unrecoverable, which is the same gap pinyin fills with the 隔音符号 and
|
|
206
|
+
* which this module does not attempt: reading takes a syllable at a time.
|
|
207
|
+
*/
|
|
208
|
+
export function writeYaleWord(syllables, options = {}) {
|
|
209
|
+
return syllables.map((syllable) => writeYale(syllable, options)).join("");
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Every syllable each Yale spelling stands for.
|
|
213
|
+
*/
|
|
214
|
+
const INDEX = indexInventory((syllable) => baseSpelling(syllable));
|
|
215
|
+
/**
|
|
216
|
+
* Take the tone off, however it was written.
|
|
217
|
+
*
|
|
218
|
+
* A trailing digit first, since `jyou4` is unambiguous and cheap to spot; then
|
|
219
|
+
* the diacritics, which is what Yale actually writes. An unmarked syllable has
|
|
220
|
+
* no tone rather than the neutral one, for the reason `readSyllable` gives:
|
|
221
|
+
* nothing was written either way.
|
|
222
|
+
*/
|
|
223
|
+
function splitTone(text) {
|
|
224
|
+
const found = /^(.*?)([0-5])$/u.exec(normaliseSuperscript(text));
|
|
225
|
+
const digit = found?.[2];
|
|
226
|
+
if (found !== null && digit !== undefined) {
|
|
227
|
+
return [stripToneMarks(found[1] ?? ""), toneFromNotation(Number(digit))];
|
|
228
|
+
}
|
|
229
|
+
return [stripToneMarks(text), toneFromMarks(text)];
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Read a Yale syllable: `jyòu` becomes 就 jiù.
|
|
233
|
+
*
|
|
234
|
+
* Returns every syllable the spelling stands for, which is one for all but the
|
|
235
|
+
* handful `docs/romanization/` counts. Empty for anything that is not Yale at
|
|
236
|
+
* all.
|
|
237
|
+
*/
|
|
238
|
+
export function readYale(text) {
|
|
239
|
+
const [spelling, tone] = splitTone(text.trim().normalize("NFC").toLowerCase());
|
|
240
|
+
return readIndexed(INDEX, spelling, tone, ERHUA_SUFFIX);
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=yale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yale.js","sourceRoot":"","sources":["../../src/transcription/yale.ts"],"names":[],"mappings":"AA8BA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAa,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAkB;IACjD,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,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;AAED;;GAEG;AACH,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEnE;;;;;;;GAOG;AACH,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,SAAS,CAChC,IAAI,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAC3C,CAAC;IACF,OAAO,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AAC1D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kensio/pinyinjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Chinese hanzi to pinyin conversion",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dist",
|
|
30
30
|
"data",
|
|
31
31
|
"README.md",
|
|
32
|
+
"CHANGELOG.md",
|
|
32
33
|
"LICENSE",
|
|
33
34
|
"NOTICE"
|
|
34
35
|
],
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"#test/*": "./test/*"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
43
|
+
"node": ">=22.0.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@eslint/js": "^10.0.1",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"eslint-plugin-jsdoc": "^63.0.13",
|
|
56
57
|
"eslint-plugin-no-secrets": "^2.3.3",
|
|
57
58
|
"eslint-plugin-security": "^4.0.1",
|
|
58
|
-
"eslint-plugin-unicorn": "^
|
|
59
|
+
"eslint-plugin-unicorn": "^71.0.0",
|
|
59
60
|
"fta-cli": "^3.0.0",
|
|
60
61
|
"globals": "^17.7.0",
|
|
61
62
|
"jiti": "^2.7.0",
|
|
@@ -77,18 +78,21 @@
|
|
|
77
78
|
"license": "Apache-2.0 AND CC-BY-SA-4.0",
|
|
78
79
|
"type": "module",
|
|
79
80
|
"scripts": {
|
|
80
|
-
"build": "tsc -p tsconfig.build.json",
|
|
81
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
81
82
|
"cli": "node --import jiti/register src/cli/main.ts",
|
|
82
83
|
"build:check": "tsc -p tsconfig.json --noEmit",
|
|
83
84
|
"fmt": "eslint --fix . && prettier --write .",
|
|
84
85
|
"lint": "eslint . && prettier --check .",
|
|
85
86
|
"fta": "./scripts/sh/fta.sh",
|
|
87
|
+
"pack:check": "./scripts/sh/pack-check.sh",
|
|
86
88
|
"build:data": "node --import jiti/register scripts/build-data/build.ts",
|
|
87
89
|
"fetch:data": "node --import jiti/register scripts/build-data/fetch.ts",
|
|
88
90
|
"test": "vitest run",
|
|
89
91
|
"test:coverage": "vitest run --coverage",
|
|
90
92
|
"check": "pnpm fmt && pnpm fta && pnpm build && pnpm build:check && pnpm test:coverage",
|
|
91
93
|
"accuracy": "node --import jiti/register scripts/build-data/accuracy.ts",
|
|
92
|
-
"polyphones": "node --import jiti/register scripts/build-data/polyphones.ts"
|
|
94
|
+
"polyphones": "node --import jiti/register scripts/build-data/polyphones.ts",
|
|
95
|
+
"numerals": "node --import jiti/register scripts/build-data/numerals.ts",
|
|
96
|
+
"transcription": "node --import jiti/register scripts/build-data/transcription.ts"
|
|
93
97
|
}
|
|
94
98
|
}
|