@hakkacl/hakka 0.0.0-stage → 0.1.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/LICENSE +29 -0
- package/README.md +205 -2
- package/data/dialects.json +1 -0
- package/package.json +48 -4
- package/src/dialects.js +207 -0
- package/src/index.js +12 -0
- package/src/phon/converter.js +365 -0
- package/src/phon/parser.js +991 -0
- package/src/phon/schemes.js +360 -0
- package/src/phon/syllable.js +258 -0
- package/src/phon/validate.js +118 -0
- package/src/sandhi.js +402 -0
- package/types/index.d.ts +378 -0
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for `@hakkacl/hakka`.
|
|
3
|
+
*
|
|
4
|
+
* The package provides canonical Hakka syllable parsing, multi-scheme
|
|
5
|
+
* romanization conversion, dialect metadata, validation, and tone sandhi.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Canonical transcription scheme names. */
|
|
9
|
+
export type CanonicalScheme =
|
|
10
|
+
| "hps_ext"
|
|
11
|
+
| "hps_diacritic"
|
|
12
|
+
| "ipa"
|
|
13
|
+
| "ipa_value"
|
|
14
|
+
| "ipa_chao"
|
|
15
|
+
| "gd"
|
|
16
|
+
| "hkilang";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A scheme name or one of the accepted aliases (`hps`, `pinyin`, `sixian`-style
|
|
20
|
+
* dialect names are not schemes; see {@link SchemeAlias}).
|
|
21
|
+
*/
|
|
22
|
+
export type SchemeAlias =
|
|
23
|
+
| "hps-ext"
|
|
24
|
+
| "hps"
|
|
25
|
+
| "hakka_pinyin"
|
|
26
|
+
| "pinyin"
|
|
27
|
+
| "hps-diacritic"
|
|
28
|
+
| "hps_mark"
|
|
29
|
+
| "diacritic"
|
|
30
|
+
| "ipa-value"
|
|
31
|
+
| "ipa_numeric"
|
|
32
|
+
| "ipa-chao"
|
|
33
|
+
| "chao"
|
|
34
|
+
| "guangdong"
|
|
35
|
+
| "gd_pinyin"
|
|
36
|
+
| "gd-pinyin"
|
|
37
|
+
| "meixian_pinyin"
|
|
38
|
+
| "hk"
|
|
39
|
+
| "hk_assoc";
|
|
40
|
+
|
|
41
|
+
/** Any accepted scheme spelling. Unknown strings are rejected at runtime. */
|
|
42
|
+
export type SchemeName = CanonicalScheme | SchemeAlias | (string & {});
|
|
43
|
+
|
|
44
|
+
/** Canonical eight-tone classes plus neutral tone and unspecified. */
|
|
45
|
+
export type CanonicalToneClass =
|
|
46
|
+
| "0"
|
|
47
|
+
| "1"
|
|
48
|
+
| "2"
|
|
49
|
+
| "3"
|
|
50
|
+
| "4"
|
|
51
|
+
| "5"
|
|
52
|
+
| "6"
|
|
53
|
+
| "7"
|
|
54
|
+
| "8"
|
|
55
|
+
| "";
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A tone class. The curated registry uses 1–8 (plus 0), while some MCPDict
|
|
59
|
+
* varieties use extended labels such as `"6a"`, `"7b"`, `"1c"`, or `"10"`.
|
|
60
|
+
*/
|
|
61
|
+
export type ToneClass = CanonicalToneClass | (string & {});
|
|
62
|
+
|
|
63
|
+
/** One tone class in a dialect's tone inventory. */
|
|
64
|
+
export interface ToneSpec {
|
|
65
|
+
/** Canonical tone class key (`"1"`–`"8"`, or `"0"`). */
|
|
66
|
+
readonly tone_class: string;
|
|
67
|
+
/** Camel-case alias of {@link ToneSpec.tone_class}. */
|
|
68
|
+
readonly toneClass: string;
|
|
69
|
+
/** Tone name, e.g. `"陰平"`. */
|
|
70
|
+
readonly name: string;
|
|
71
|
+
/** Five-level Chao tone value, e.g. `"44"`; empty when unknown. */
|
|
72
|
+
readonly value: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Metadata record for a curated core dialect or an MCPDict variety. */
|
|
76
|
+
export interface DialectInfo {
|
|
77
|
+
/** Stable numeric registry id (1-based). */
|
|
78
|
+
readonly id: number;
|
|
79
|
+
/** Canonical dialect slug. */
|
|
80
|
+
readonly slug: string;
|
|
81
|
+
/** Traditional-Chinese name. */
|
|
82
|
+
readonly name_trad: string;
|
|
83
|
+
/** Simplified-Chinese name. */
|
|
84
|
+
readonly name_simp: string;
|
|
85
|
+
readonly nameTrad: string;
|
|
86
|
+
readonly nameSimp: string;
|
|
87
|
+
/** Registry tier: `"standard"`, `"core"`, or `"mcpdict"`. */
|
|
88
|
+
readonly tier: string;
|
|
89
|
+
/** Dialect-group path, or `null`. */
|
|
90
|
+
readonly subgroup: string | null;
|
|
91
|
+
/** Geographic location description, or `null`. */
|
|
92
|
+
readonly location: string | null;
|
|
93
|
+
readonly lat: number | null;
|
|
94
|
+
readonly lon: number | null;
|
|
95
|
+
readonly is_island: boolean;
|
|
96
|
+
readonly isIsland: boolean;
|
|
97
|
+
readonly is_historical: boolean;
|
|
98
|
+
readonly isHistorical: boolean;
|
|
99
|
+
/** Tone inventory keyed by canonical tone class. */
|
|
100
|
+
readonly tones: Readonly<Record<string, ToneSpec>>;
|
|
101
|
+
/** Whether tone values are requested by default when bare digits are parsed. */
|
|
102
|
+
readonly use_tone_value: boolean;
|
|
103
|
+
readonly useToneValue: boolean;
|
|
104
|
+
readonly has_words: boolean;
|
|
105
|
+
readonly hasWords: boolean;
|
|
106
|
+
readonly char_count: number;
|
|
107
|
+
readonly charCount: number;
|
|
108
|
+
readonly word_count: number;
|
|
109
|
+
readonly wordCount: number;
|
|
110
|
+
/** Source data license. */
|
|
111
|
+
readonly source_license: string;
|
|
112
|
+
readonly sourceLicense: string;
|
|
113
|
+
/** Alias of {@link DialectInfo.source_license}. */
|
|
114
|
+
readonly license: string;
|
|
115
|
+
readonly reference: string | null;
|
|
116
|
+
/** Accepted registry aliases (slugs, abbreviations, Chinese names). */
|
|
117
|
+
readonly aliases: readonly string[];
|
|
118
|
+
|
|
119
|
+
/** Look up the five-level tone value for a tone class. */
|
|
120
|
+
toneValueFor(toneClass: ToneClass | string): string;
|
|
121
|
+
/** Snake-case alias of {@link DialectInfo.toneValueFor}. */
|
|
122
|
+
tone_value_for(toneClass: ToneClass | string): string;
|
|
123
|
+
/** Reverse lookup from a tone value to its first matching tone class. */
|
|
124
|
+
toneClassForValue(toneValue: string): string;
|
|
125
|
+
/** Snake-case alias of {@link DialectInfo.toneClassForValue}. */
|
|
126
|
+
tone_class_for_value(toneValue: string): string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Canonical phonological representation of one Hakka syllable.
|
|
131
|
+
*
|
|
132
|
+
* Fields use HPS-Ext ASCII segments. Computed accessors (`final`, `base`,
|
|
133
|
+
* `hps_ext`, …) and immutable update methods are non-enumerable.
|
|
134
|
+
*/
|
|
135
|
+
export interface Syllable {
|
|
136
|
+
/** Initial consonant; empty for zero onset, `"'"` for explicit glottal onset. */
|
|
137
|
+
readonly onset: string;
|
|
138
|
+
/** Glide: `""`, `"i"`, `"u"`, or `"y"`. */
|
|
139
|
+
readonly medial: string;
|
|
140
|
+
/** Main vowel or syllabic consonant (`m`, `n`, `ng`, `v`). */
|
|
141
|
+
readonly nucleus: string;
|
|
142
|
+
/** Coda: empty, `i`, `u`, `m`, `n`, `ng`, `b`, `d`, `g`, or `h`. */
|
|
143
|
+
readonly coda: string;
|
|
144
|
+
/** Whether the rime carries `-nn` nasalization. */
|
|
145
|
+
readonly nasalized: boolean;
|
|
146
|
+
/** Canonical tone class. */
|
|
147
|
+
readonly tone: ToneClass;
|
|
148
|
+
/** Five-level Chao tone value, e.g. `"44"`; empty when unknown. */
|
|
149
|
+
readonly tone_value: string;
|
|
150
|
+
readonly toneValue: string;
|
|
151
|
+
/** Optional reading mark (`-`, `=`, `+`, `*`, `@`, `?`). */
|
|
152
|
+
readonly reading_mark: string;
|
|
153
|
+
readonly readingMark: string;
|
|
154
|
+
/** Original input token. */
|
|
155
|
+
readonly raw: string;
|
|
156
|
+
|
|
157
|
+
/** Full rime (medial + nucleus + coda + nasalization). */
|
|
158
|
+
readonly final: string;
|
|
159
|
+
/** Segmental spelling without tone. */
|
|
160
|
+
readonly base: string;
|
|
161
|
+
/** Canonical HPS-Ext spelling including tone class. */
|
|
162
|
+
readonly hps_ext: string;
|
|
163
|
+
/** Camel-case alias of {@link Syllable.hps_ext}. */
|
|
164
|
+
readonly hpsExt: string;
|
|
165
|
+
/** True for stop-coda syllables (`-b/-d/-g/-h`). */
|
|
166
|
+
readonly is_checked: boolean;
|
|
167
|
+
readonly isChecked: boolean;
|
|
168
|
+
/** True for nasal-coda syllables (`-m/-n/-ng`). */
|
|
169
|
+
readonly is_nasal_coda: boolean;
|
|
170
|
+
readonly isNasalCoda: boolean;
|
|
171
|
+
/** True for standalone syllabic consonants. */
|
|
172
|
+
readonly is_syllabic_consonant: boolean;
|
|
173
|
+
readonly isSyllabicConsonant: boolean;
|
|
174
|
+
|
|
175
|
+
/** Return a copy with a new tone class and optional tone value. */
|
|
176
|
+
withTone(tone: ToneClass | string, toneValue?: string): Syllable;
|
|
177
|
+
/** Snake-case alias of {@link Syllable.withTone}. */
|
|
178
|
+
with_tone(tone: ToneClass | string, toneValue?: string): Syllable;
|
|
179
|
+
/** Return a copy with a new tone value and optional tone class. */
|
|
180
|
+
withToneValue(toneValue: string, tone?: ToneClass | string): Syllable;
|
|
181
|
+
/** Snake-case alias of {@link Syllable.withToneValue}. */
|
|
182
|
+
with_tone_value(toneValue: string, tone?: ToneClass | string): Syllable;
|
|
183
|
+
/** Return a copy with a new onset. */
|
|
184
|
+
withOnset(onset: string): Syllable;
|
|
185
|
+
/** Snake-case alias of {@link Syllable.withOnset}. */
|
|
186
|
+
with_onset(onset: string): Syllable;
|
|
187
|
+
toString(): string;
|
|
188
|
+
toJSON(): SyllableJSON;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** JSON shape returned by {@link Syllable.toJSON}. */
|
|
192
|
+
export interface SyllableJSON {
|
|
193
|
+
onset: string;
|
|
194
|
+
medial: string;
|
|
195
|
+
nucleus: string;
|
|
196
|
+
coda: string;
|
|
197
|
+
nasalized: boolean;
|
|
198
|
+
tone: ToneClass;
|
|
199
|
+
tone_value: string;
|
|
200
|
+
reading_mark: string;
|
|
201
|
+
raw: string;
|
|
202
|
+
hps_ext: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Options for parsing a syllable or syllable sequence. */
|
|
206
|
+
export interface ParseOptions {
|
|
207
|
+
scheme?: SchemeName;
|
|
208
|
+
dialect?: string | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Options for formatting a syllable. */
|
|
212
|
+
export interface FormatOptions {
|
|
213
|
+
scheme?: SchemeName;
|
|
214
|
+
dialect?: string | null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Options for validating a syllable. */
|
|
218
|
+
export interface ValidateOptions {
|
|
219
|
+
scheme?: SchemeName;
|
|
220
|
+
dialect?: string | null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Options for converting a sequence. */
|
|
224
|
+
export interface ConvertOptions {
|
|
225
|
+
src?: SchemeName;
|
|
226
|
+
dst?: SchemeName;
|
|
227
|
+
/** Alias of {@link ConvertOptions.src}. */
|
|
228
|
+
from?: SchemeName;
|
|
229
|
+
/** Alias of {@link ConvertOptions.dst}. */
|
|
230
|
+
to?: SchemeName;
|
|
231
|
+
dialect?: string | null;
|
|
232
|
+
/** Output separator; defaults to a single space. */
|
|
233
|
+
sep?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Filters accepted by {@link listDialects}. */
|
|
237
|
+
export interface ListDialectsOptions {
|
|
238
|
+
/** Exact tier: `"standard"`, `"core"`, or `"mcpdict"`. */
|
|
239
|
+
tier?: string;
|
|
240
|
+
/** Case-insensitive substring match against the dialect subgroup. */
|
|
241
|
+
subgroup?: string;
|
|
242
|
+
/** Require (true) or exclude (false) dialects with word data. */
|
|
243
|
+
hasWords?: boolean;
|
|
244
|
+
/** Snake-case alias of {@link ListDialectsOptions.hasWords}. */
|
|
245
|
+
has_words?: boolean;
|
|
246
|
+
/** Only historical attestations. */
|
|
247
|
+
historicalOnly?: boolean;
|
|
248
|
+
/** Only island / diaspora varieties. */
|
|
249
|
+
islandsOnly?: boolean;
|
|
250
|
+
/** Snake-case alias of {@link ListDialectsOptions.historicalOnly}. */
|
|
251
|
+
historical_only?: boolean;
|
|
252
|
+
/** Snake-case alias of {@link ListDialectsOptions.islandsOnly}. */
|
|
253
|
+
islands_only?: boolean;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Result of {@link validateSyllable}. */
|
|
257
|
+
export interface ValidationResult {
|
|
258
|
+
readonly valid: boolean;
|
|
259
|
+
readonly syllable: Syllable | null;
|
|
260
|
+
readonly errors: readonly string[];
|
|
261
|
+
readonly warnings: readonly string[];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Audit record of one sandhi or assimilation mutation. */
|
|
265
|
+
export interface SandhiChange {
|
|
266
|
+
/** Syllable index in the sequence. */
|
|
267
|
+
readonly index: number;
|
|
268
|
+
/** Aligned Chinese character, or empty when unavailable. */
|
|
269
|
+
readonly char: string;
|
|
270
|
+
/** HPS-Ext spelling before the change. */
|
|
271
|
+
readonly before: string;
|
|
272
|
+
/** HPS-Ext spelling after the change. */
|
|
273
|
+
readonly after: string;
|
|
274
|
+
/** Rule identifier (multiple joined with `+`). */
|
|
275
|
+
readonly rule: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Result of {@link applySandhi}. */
|
|
279
|
+
export interface SandhiResult {
|
|
280
|
+
readonly syllables: Syllable[];
|
|
281
|
+
readonly changes: SandhiChange[];
|
|
282
|
+
/** Canonical dialect slug actually used. */
|
|
283
|
+
readonly dialect: string;
|
|
284
|
+
/** Sandhi profile name actually used. */
|
|
285
|
+
readonly profile: string;
|
|
286
|
+
/** Space-joined HPS-Ext transcription of the result. */
|
|
287
|
+
readonly hps_ext: string;
|
|
288
|
+
/** Camel-case alias of {@link SandhiResult.hps_ext}. */
|
|
289
|
+
readonly hpsExt: string;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Options for {@link applySandhi}. */
|
|
293
|
+
export interface SandhiOptions {
|
|
294
|
+
dialect?: string | null;
|
|
295
|
+
/** Aligned Chinese characters for morpheme-specific rules. */
|
|
296
|
+
chars?: string | readonly string[] | null;
|
|
297
|
+
/** Rule profile (e.g. `"standard"`, `"traditional"`, `"rao"`). */
|
|
298
|
+
profile?: string;
|
|
299
|
+
/** Input scheme when the syllable argument is a string. */
|
|
300
|
+
scheme?: SchemeName;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Input accepted by {@link applySandhi}. */
|
|
304
|
+
export type SandhiInput = string | readonly Syllable[];
|
|
305
|
+
|
|
306
|
+
/** Default dialect slug (`"huiyang"`). */
|
|
307
|
+
export const DEFAULT_DIALECT: "huiyang";
|
|
308
|
+
|
|
309
|
+
/** Default scheme name (`"hps_ext"`). */
|
|
310
|
+
export const DEFAULT_SCHEME: "hps_ext";
|
|
311
|
+
|
|
312
|
+
/** Canonical scheme names in registry order. */
|
|
313
|
+
export const CANONICAL_SCHEMES: readonly CanonicalScheme[];
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Resolve a dialect slug, Chinese name (traditional or simplified), or alias.
|
|
317
|
+
* Throws if the dialect is unknown.
|
|
318
|
+
*/
|
|
319
|
+
export function getDialect(name?: string | null): DialectInfo;
|
|
320
|
+
|
|
321
|
+
/** List available Hakka varieties with optional filtering. */
|
|
322
|
+
export function listDialects(options?: ListDialectsOptions): DialectInfo[];
|
|
323
|
+
|
|
324
|
+
/** Parse one syllable into canonical IR. */
|
|
325
|
+
export function parseSyllable(
|
|
326
|
+
text: string,
|
|
327
|
+
scheme?: SchemeName,
|
|
328
|
+
dialect?: string | null,
|
|
329
|
+
): Syllable;
|
|
330
|
+
export function parseSyllable(text: string, options?: ParseOptions): Syllable;
|
|
331
|
+
|
|
332
|
+
/** Parse a whitespace- or hyphen-separated syllable sequence. */
|
|
333
|
+
export function parseSyllables(
|
|
334
|
+
text: string,
|
|
335
|
+
scheme?: SchemeName,
|
|
336
|
+
dialect?: string | null,
|
|
337
|
+
): Syllable[];
|
|
338
|
+
export function parseSyllables(text: string, options?: ParseOptions): Syllable[];
|
|
339
|
+
|
|
340
|
+
/** Format a syllable into the requested scheme. */
|
|
341
|
+
export function formatSyllable(
|
|
342
|
+
syllable: Syllable,
|
|
343
|
+
scheme?: SchemeName,
|
|
344
|
+
dialect?: string | null,
|
|
345
|
+
): string;
|
|
346
|
+
export function formatSyllable(
|
|
347
|
+
syllable: Syllable,
|
|
348
|
+
options?: FormatOptions,
|
|
349
|
+
): string;
|
|
350
|
+
|
|
351
|
+
/** Convert a whitespace-separated transcription between schemes. */
|
|
352
|
+
export function convert(
|
|
353
|
+
text: string,
|
|
354
|
+
src?: SchemeName,
|
|
355
|
+
dst?: SchemeName,
|
|
356
|
+
dialect?: string | null,
|
|
357
|
+
sep?: string,
|
|
358
|
+
): string;
|
|
359
|
+
export function convert(text: string, options?: ConvertOptions): string;
|
|
360
|
+
|
|
361
|
+
/** Validate a syllable and report errors and warnings. */
|
|
362
|
+
export function validateSyllable(
|
|
363
|
+
text: string,
|
|
364
|
+
scheme?: SchemeName,
|
|
365
|
+
dialect?: string | null,
|
|
366
|
+
): ValidationResult;
|
|
367
|
+
export function validateSyllable(text: string, options?: ValidateOptions): ValidationResult;
|
|
368
|
+
|
|
369
|
+
/** Apply dialect-specific tone sandhi and progressive assimilation. */
|
|
370
|
+
export function applySandhi(
|
|
371
|
+
syllables: SandhiInput,
|
|
372
|
+
dialect?: string,
|
|
373
|
+
options?: SandhiOptions,
|
|
374
|
+
): SandhiResult;
|
|
375
|
+
export function applySandhi(syllables: SandhiInput, options?: SandhiOptions): SandhiResult;
|
|
376
|
+
|
|
377
|
+
/** Return the mapping of dialect slug -> supported sandhi profile names. */
|
|
378
|
+
export function listSandhiDialects(): Record<string, string[]>;
|