@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 ADDED
@@ -0,0 +1,29 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HakkaCL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Note on Bundled Linguistic Data:
26
+ Code in this repository is licensed under the MIT License above.
27
+ Bundled lexical and phonological tables compiled from Hakka-Char-Tables,
28
+ Hakka-Word-Tables, HKILANG, and MCPDict remain subject to their respective
29
+ CC BY 4.0 and MIT licenses. See NOTICE.md for full attribution and licensing.
package/README.md CHANGED
@@ -1,3 +1,206 @@
1
- # Temporary Holding Version
1
+ # @hakkacl/hakka
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Hakka phonology for JavaScript and TypeScript: canonical syllable parsing,
4
+ bidirectional romanization conversion, dialect metadata, validation, and tone
5
+ sandhi.
6
+
7
+ - Pure ESM, zero runtime dependencies.
8
+ - Node.js >= 18 and modern browsers/bundlers.
9
+ - 229 bundled Hakka varieties, including 10 curated core dialects and 218
10
+ MCPDict varieties.
11
+ - Hand-written TypeScript declarations.
12
+ - Data is bundled with the package; no network or database access is required.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @hakkacl/hakka
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ ```js
23
+ import {
24
+ parseSyllable,
25
+ parseSyllables,
26
+ formatSyllable,
27
+ convert,
28
+ getDialect,
29
+ listDialects,
30
+ validateSyllable,
31
+ applySandhi,
32
+ } from "@hakkacl/hakka";
33
+
34
+ const syllable = parseSyllable("ziim1", "hps_ext", "meixian");
35
+ syllable.onset; // "z"
36
+ syllable.nucleus; // "ii"
37
+ syllable.coda; // "m"
38
+ syllable.tone; // "1"
39
+ syllable.tone_value; // "44"
40
+ syllable.hps_ext; // "ziim1"
41
+
42
+ convert("ziim1 ngin2", "hps_ext", "ipa", "meixian");
43
+ // "tsəm1 ŋin2"
44
+
45
+ convert("ziim1 ngin2", "hps_ext", "ipa_value", "meixian");
46
+ // "tsəm⁴⁴ ŋin¹¹"
47
+
48
+ formatSyllable(parseSyllable("tien1", "hps_ext", "huiyang"), "ipa", "huiyang");
49
+ // "tʰien1"
50
+ ```
51
+
52
+ Every parsing/formatting function also accepts an options object:
53
+
54
+ ```js
55
+ parseSyllable("ngin2", { scheme: "hps_ext", dialect: "huiyang" });
56
+ convert("ngin2", { src: "hps_ext", dst: "ipa", dialect: "huiyang" });
57
+ validateSyllable("ngin2", { dialect: "meixian" });
58
+ ```
59
+
60
+ ## Dialects
61
+
62
+ The default dialect is standard Huiyang (`"huiyang"`). Lookup accepts a slug,
63
+ an alias, or a traditional/simplified Chinese name.
64
+
65
+ ```js
66
+ getDialect().slug; // "huiyang"
67
+ getDialect("梅縣").slug; // "meixian"
68
+ getDialect("梅县").slug; // "meixian"
69
+ getDialect("hk").slug; // "hongkong-newterritories"
70
+ getDialect("sixian").slug; // "mcp:臺灣四縣腔"
71
+ getDialect("1860新安").slug; // "mcp:1860新安"
72
+
73
+ listDialects().length; // 229
74
+ listDialects({ tier: "core" }).length; // 10
75
+ listDialects({ historicalOnly: true }).length; // 4
76
+ listDialects({ islandsOnly: true }).length; // 96
77
+ ```
78
+
79
+ Each `DialectInfo` record exposes `slug`, `name_trad`, `name_simp`, `tier`,
80
+ `subgroup`, `location`, `lat`, `lon`, `tones`, `aliases`, and related metadata.
81
+ Tone values are available through `toneValueFor(toneClass)` and
82
+ `toneClassForValue(toneValue)`.
83
+
84
+ ## Schemes
85
+
86
+ | Canonical name | Aliases | Description |
87
+ | --- | --- | --- |
88
+ | `hps_ext` | `hps`, `hps-ext`, `hakka_pinyin`, `pinyin` | Canonical HPS-Ext with tone classes 1–8 |
89
+ | `hps_diacritic` | `hps_mark`, `hps-diacritic`, `diacritic` | HPS-Ext with tone diacritics |
90
+ | `ipa` | — | IPA segments with tone class |
91
+ | `ipa_value` | `ipa-value`, `ipa_numeric` | IPA with superscript Chao tone values |
92
+ | `ipa_chao` | `ipa-chao`, `chao` | IPA with Chao tone letters |
93
+ | `gd` | `guangdong`, `gd_pinyin`, `meixian_pinyin` | Guangdong Hakka Pinyin (1–6 tones) |
94
+ | `hkilang` | `hk`, `hk_assoc` | Hong Kong Indigenous Language Association romanization |
95
+
96
+ ```js
97
+ convert("ngit5 teu2 ngiet6 gong1 sia4", "hkilang", "hps_ext", "hk");
98
+ // "ngid7 teu2 ngied8 gong1 sia5"
99
+
100
+ convert("id7 iu1 ia2 ien1 iung5 'iu1", "hps_ext", "hkilang", "hk");
101
+ // "yit5 yiu1 ya2 yen1 yung4 iu1"
102
+
103
+ convert("tʃæn1 kœŋ3", "ipa", "hps_ext", "huiyang");
104
+ // "zhaen1 goeng3"
105
+ ```
106
+
107
+ ## Parsing and formatting
108
+
109
+ `parseSyllable(text, scheme?, dialect?)` returns a canonical `Syllable` with
110
+ `onset`, `medial`, `nucleus`, `coda`, `nasalized`, `tone`, `tone_value`,
111
+ `reading_mark`, and `raw`, plus computed accessors:
112
+
113
+ ```js
114
+ const s = parseSyllable("hiunnh7", "hps_ext", "huiyang");
115
+ s.final; // "iunnh"
116
+ s.base; // "hiunnh"
117
+ s.hps_ext; // "hiunnh7"
118
+ s.is_checked; // true
119
+ s.is_syllabic_consonant; // false
120
+
121
+ s.withTone("8", "5").hps_ext; // "hiunnh8"
122
+ ```
123
+
124
+ `parseSyllables("id7 ha5 siid8 fan5")` parses a whitespace- or hyphen-separated
125
+ sequence.
126
+
127
+ ## Validation
128
+
129
+ ```js
130
+ const result = validateSyllable("ngin2", "hps_ext", "meixian");
131
+ result.valid; // true
132
+ result.errors; // []
133
+ result.warnings; // []
134
+
135
+ validateSyllable("ged3", "hps_ext", "hk").warnings;
136
+ // ["Checked coda -d paired with non-checked tone class 3"]
137
+
138
+ validateSyllable("ngin6", "hps_ext", "meixian").warnings;
139
+ // ["Tone class '6' is not in meixian's tone inventory (['1', '2', '3', '5', '7', '8'])"]
140
+
141
+ validateSyllable("", "hps_ext", "meixian").valid;
142
+ // false
143
+ ```
144
+
145
+ Hard constraint violations produce `errors` and make `valid` false; dialect
146
+ inventory mismatches and checked/open tone inconsistencies produce warnings.
147
+
148
+ ## Tone sandhi
149
+
150
+ ```js
151
+ applySandhi("tian1 tan2", { dialect: "meixian", chars: "天壇" });
152
+ // syllables[0].tone_value === "45"
153
+
154
+ applySandhi("pag8 sied7 sied7 li3", { dialect: "wuhua", chars: "白雪雪哩" }).hps_ext;
155
+ // "pag8 sied7 sied7 di1"
156
+
157
+ applySandhi("hau3 shii3", "changting").hps_ext;
158
+ // "hau2 shii3"
159
+
160
+ applySandhi("san1 go1", "mcp:臺灣四縣腔").hps_ext;
161
+ // "san2 go1"
162
+
163
+ applySandhi("hau3 siid8 fan5", "mcp:臺灣海陸腔").hps_ext;
164
+ // "hau6 siid7 fan5"
165
+ ```
166
+
167
+ Supported profiles:
168
+
169
+ | Dialect | Profiles | Rule summary |
170
+ | --- | --- | --- |
171
+ | `meixian` | `standard`, `traditional` | 陰平 44 → 45 before 陽平/上聲/陰入; traditional 去聲 52 → 55 |
172
+ | `wuhua` | `standard` | Suffix 哩 progressive assimilation and 3 → 1 (55) |
173
+ | `changting` | `standard`, `rao` | 上聲 3 + 3 → 2; optional 饒長溶 profiles |
174
+ | `mcp:臺灣四縣腔` | `standard` | 陰平 1 → 2 before 1/2/7 |
175
+ | `mcp:臺灣南四縣腔` | `standard` | 陰平 1 → 2 before 1/2/7 |
176
+ | `mcp:臺灣海陸腔` | `standard` | 上聲 3 → 6 and 陽入 8 → 7 non-finally |
177
+ | `dabu-baihou` | `standard` | Explicit no-sandhi pass-through |
178
+
179
+ All other dialects, including the default `huiyang`, pass through unchanged.
180
+ `listSandhiDialects()` returns the dialect → profiles mapping.
181
+
182
+ A `SandhiResult` contains `syllables`, `changes` (each with `index`, `char`,
183
+ `before`, `after`, and `rule`), `dialect`, `profile`, and the space-joined
184
+ `hps_ext` transcription.
185
+
186
+ ## API
187
+
188
+ | Export | Description |
189
+ | --- | --- |
190
+ | `DEFAULT_DIALECT` | `"huiyang"` |
191
+ | `DEFAULT_SCHEME` | `"hps_ext"` |
192
+ | `CANONICAL_SCHEMES` | Canonical scheme names |
193
+ | `getDialect(name?)` | Resolve a dialect record |
194
+ | `listDialects(options?)` | List/filter dialect records |
195
+ | `parseSyllable(text, scheme?, dialect?)` | Parse one syllable |
196
+ | `parseSyllables(text, scheme?, dialect?)` | Parse a syllable sequence |
197
+ | `formatSyllable(syllable, scheme?, dialect?)` | Format a syllable |
198
+ | `convert(text, src?, dst?, dialect?, sep?)` | Convert a sequence |
199
+ | `validateSyllable(text, scheme?, dialect?)` | Validate one syllable |
200
+ | `applySandhi(syllables, dialect?, options?)` | Apply sandhi / assimilation |
201
+ | `listSandhiDialects()` | List supported sandhi profiles |
202
+
203
+ ## License
204
+
205
+ MIT. Bundled dialect metadata derives from HakkaCL curated tables (CC BY 4.0)
206
+ and MCPDict (MIT); see the metadata `license` and `reference` fields.