to-hakka 0.1.0 → 0.1.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.
- package/README.md +9 -9
- package/bin/to-hakka.js +8 -10
- package/data/huiyang.json +1 -1
- package/package.json +3 -3
- package/src/converter.js +8 -8
- package/src/index.js +5 -5
- package/src/ipa.js +10 -10
- package/types/index.d.ts +12 -11
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# to-hakka
|
|
2
2
|
|
|
3
3
|
Chinese text to **Standard Huiyang Hakka** romanization in
|
|
4
|
-
|
|
4
|
+
Hakka Pinyin System Extended (H++), with IPA output. Pure ESM, zero runtime dependencies, Unicode
|
|
5
5
|
code-point safe.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
@@ -62,15 +62,15 @@ ToHakkaAPI.getHakka("𠊎係客家人");
|
|
|
62
62
|
|
|
63
63
|
| Function | Returns | Description |
|
|
64
64
|
| --- | --- | --- |
|
|
65
|
-
| `getHakka(text)` | `string` | Space-separated
|
|
66
|
-
| `getHakkaText(text)` | `string` | Input text annotated inline as `字(
|
|
65
|
+
| `getHakka(text)` | `string` | Space-separated H++ syllables for recognized characters. |
|
|
66
|
+
| `getHakkaText(text)` | `string` | Input text annotated inline as `字(hpp)`; unrecognized characters are kept as-is. |
|
|
67
67
|
| `getHakkaList(text)` | `[string, string \| null][]` | Per-character `[char, primary pronunciation]` pairs. |
|
|
68
68
|
| `getHakkaCandidates(text)` | `[string, string[]][]` | Per-character `[char, candidate pronunciations]`; the first candidate is the primary reading. |
|
|
69
69
|
| `getIpa(text, toneStyle?)` | `string` | Space-separated IPA syllables. |
|
|
70
70
|
| `getIpaText(text, toneStyle?)` | `string` | Input text annotated inline as `字[ipa]`. |
|
|
71
71
|
| `getIpaList(text, toneStyle?)` | `[string, string \| null][]` | Per-character `[char, ipa]` pairs. |
|
|
72
72
|
| `customize(entries)` | `ToHakka` | New converter with custom word/character entries. |
|
|
73
|
-
| `
|
|
73
|
+
| `hppToIpa(syllable, toneStyle?)` | `string` | Convert one H++ syllable to IPA. |
|
|
74
74
|
| `HUIYANG_TONE_VALUES` | `Readonly<Record<string, string>>` | Tone class to tone value mapping (`1 -> "44"`, etc.). |
|
|
75
75
|
| `VERSION` | `string` | Package version. |
|
|
76
76
|
| `ToHakka` | `class` | Converter class for custom tables and reusable instances. |
|
|
@@ -84,9 +84,9 @@ characters such as `𠊎` (U+2028E) count as one character.
|
|
|
84
84
|
|
|
85
85
|
| Value | Example | Output |
|
|
86
86
|
| --- | --- | --- |
|
|
87
|
-
| `"class"` (default) | `
|
|
88
|
-
| `"value"` | `
|
|
89
|
-
| `"chao"` | `
|
|
87
|
+
| `"class"` (default) | `hppToIpa("tien1")` | `tʰien1` |
|
|
88
|
+
| `"value"` | `hppToIpa("tien1", "value")` | `tʰien⁴⁴` |
|
|
89
|
+
| `"chao"` | `hppToIpa("tien1", "chao")` | `tʰien˦˦` |
|
|
90
90
|
|
|
91
91
|
An unsupported tone style throws a `RangeError`.
|
|
92
92
|
|
|
@@ -173,12 +173,12 @@ to-hakka "日頭月光" --json
|
|
|
173
173
|
| Option | Description |
|
|
174
174
|
| --- | --- |
|
|
175
175
|
| `--inline` | Annotate characters inline instead of printing a syllable list. |
|
|
176
|
-
| `--format
|
|
176
|
+
| `--format hpp` | H++ output (default). |
|
|
177
177
|
| `--format ipa` | IPA with tone classes. |
|
|
178
178
|
| `--format ipa-value` | IPA with superscript tone values. |
|
|
179
179
|
| `--format ipa-chao` | IPA with Chao tone letters. |
|
|
180
180
|
| `--json` | Emit the per-character token list as JSON. |
|
|
181
|
-
| `--version` | Print `to-hakka 0.1.
|
|
181
|
+
| `--version` | Print `to-hakka 0.1.1`. |
|
|
182
182
|
| `--help` | Print usage information. |
|
|
183
183
|
|
|
184
184
|
## TypeScript
|
package/bin/to-hakka.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
getIpaText,
|
|
22
22
|
} from "../src/index.js";
|
|
23
23
|
|
|
24
|
-
const FORMATS = new Set(["
|
|
24
|
+
const FORMATS = new Set(["hpp", "ipa", "ipa-value", "ipa-chao"]);
|
|
25
25
|
const IPA_STYLES = {
|
|
26
26
|
ipa: "class",
|
|
27
27
|
"ipa-value": "value",
|
|
@@ -29,10 +29,10 @@ const IPA_STYLES = {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
const HELP = `usage: to-hakka [-h] [--version] [--inline]
|
|
32
|
-
[--format {
|
|
32
|
+
[--format {hpp,ipa,ipa-value,ipa-chao}] [--json]
|
|
33
33
|
text
|
|
34
34
|
|
|
35
|
-
Convert Chinese text to Standard Huiyang Hakka (
|
|
35
|
+
Convert Chinese text to Standard Huiyang Hakka (H++ / IPA).
|
|
36
36
|
|
|
37
37
|
positional arguments:
|
|
38
38
|
text Input Chinese text (Traditional or Simplified)
|
|
@@ -41,8 +41,8 @@ options:
|
|
|
41
41
|
-h, --help show this help message and exit
|
|
42
42
|
--version show program's version number and exit
|
|
43
43
|
--inline annotate characters inline
|
|
44
|
-
--format {
|
|
45
|
-
output phonetic format (default:
|
|
44
|
+
--format {hpp,ipa,ipa-value,ipa-chao}
|
|
45
|
+
output phonetic format (default: hpp)
|
|
46
46
|
--json output JSON token list
|
|
47
47
|
`;
|
|
48
48
|
|
|
@@ -54,7 +54,7 @@ function fail(message) {
|
|
|
54
54
|
function parseArguments(argv) {
|
|
55
55
|
let inline = false;
|
|
56
56
|
let json = false;
|
|
57
|
-
let format = "
|
|
57
|
+
let format = "hpp";
|
|
58
58
|
let text = null;
|
|
59
59
|
let endOfOptions = false;
|
|
60
60
|
|
|
@@ -118,7 +118,7 @@ function parseArguments(argv) {
|
|
|
118
118
|
|
|
119
119
|
if (!FORMATS.has(format)) {
|
|
120
120
|
return {
|
|
121
|
-
error: `argument --format: invalid choice: '${format}' (choose from '
|
|
121
|
+
error: `argument --format: invalid choice: '${format}' (choose from 'hpp', 'hpp', 'ipa', 'ipa-value', 'ipa-chao')`,
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -148,9 +148,7 @@ function main(argv) {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
const { inline, json, format, text } = parsed;
|
|
151
|
-
const ipaStyle =
|
|
152
|
-
? IPA_STYLES[format]
|
|
153
|
-
: null;
|
|
151
|
+
const ipaStyle = Object.hasOwn(IPA_STYLES, format) ? IPA_STYLES[format] : null;
|
|
154
152
|
|
|
155
153
|
if (json) {
|
|
156
154
|
const pairs =
|