@lunarisapp/hyphen 0.0.3 → 0.0.4
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 +8 -0
- package/eslint.config.js +2 -2
- package/jest.config.js +6 -0
- package/package.json +13 -11
- package/src/dicts.ts +201 -0
- package/src/index.ts +17 -63
- package/src/types.d.ts +4 -0
- package/tests/__mocks__/dic.js +7 -0
- package/tests/hyphen.test.ts +8 -42
- package/tsup.config.ts +12 -0
- package/.turbo/turbo-build.log +0 -23
- package/.turbo/turbo-lint.log +0 -12
- package/.turbo/turbo-test.log +0 -372
- package/dist/dictionaries/hyph_af_ZA.dic +0 -5332
- package/dist/dictionaries/hyph_as_IN.dic +0 -100
- package/dist/dictionaries/hyph_be_BY.dic +0 -3385
- package/dist/dictionaries/hyph_bg_BG.dic +0 -6625
- package/dist/dictionaries/hyph_ca.dic +0 -3234
- package/dist/dictionaries/hyph_cs_CZ.dic +0 -3637
- package/dist/dictionaries/hyph_da_DK.dic +0 -1146
- package/dist/dictionaries/hyph_de_AT.dic +0 -77902
- package/dist/dictionaries/hyph_de_CH.dic +0 -77902
- package/dist/dictionaries/hyph_de_DE.dic +0 -77902
- package/dist/dictionaries/hyph_el_GR.dic +0 -579
- package/dist/dictionaries/hyph_en_GB.dic +0 -14062
- package/dist/dictionaries/hyph_en_US.dic +0 -11130
- package/dist/dictionaries/hyph_eo.dic +0 -3407
- package/dist/dictionaries/hyph_es.dic +0 -862
- package/dist/dictionaries/hyph_et_EE.dic +0 -3692
- package/dist/dictionaries/hyph_fr.dic +0 -2914
- package/dist/dictionaries/hyph_gl.dic +0 -290
- package/dist/dictionaries/hyph_hr_HR.dic +0 -1597
- package/dist/dictionaries/hyph_hu_HU.dic +0 -102260
- package/dist/dictionaries/hyph_id_ID.dic +0 -12033
- package/dist/dictionaries/hyph_is.dic +0 -7695
- package/dist/dictionaries/hyph_it_IT.dic +0 -421
- package/dist/dictionaries/hyph_kn_IN.dic +0 -100
- package/dist/dictionaries/hyph_lt.dic +0 -1547
- package/dist/dictionaries/hyph_lv_LV.dic +0 -11900
- package/dist/dictionaries/hyph_mn_MN.dic +0 -1004
- package/dist/dictionaries/hyph_mr_IN.dic +0 -199
- package/dist/dictionaries/hyph_nb_NO.dic +0 -27142
- package/dist/dictionaries/hyph_nl_NL.dic +0 -16257
- package/dist/dictionaries/hyph_nn_NO.dic +0 -27142
- package/dist/dictionaries/hyph_pa_IN.dic +0 -87
- package/dist/dictionaries/hyph_pl_PL.dic +0 -4824
- package/dist/dictionaries/hyph_pt_BR.dic +0 -1247
- package/dist/dictionaries/hyph_pt_PT.dic +0 -308
- package/dist/dictionaries/hyph_ro_RO.dic +0 -5220
- package/dist/dictionaries/hyph_ru_RU.dic +0 -3875
- package/dist/dictionaries/hyph_sa_IN.dic +0 -116
- package/dist/dictionaries/hyph_sk_SK.dic +0 -2468
- package/dist/dictionaries/hyph_sl_SI.dic +0 -1413
- package/dist/dictionaries/hyph_sq_AL.dic +0 -14020
- package/dist/dictionaries/hyph_sr-Latn.dic +0 -3412
- package/dist/dictionaries/hyph_sr.dic +0 -3365
- package/dist/dictionaries/hyph_sv.dic +0 -14954
- package/dist/dictionaries/hyph_te_IN.dic +0 -99
- package/dist/dictionaries/hyph_th_TH.dic +0 -5245
- package/dist/dictionaries/hyph_uk_UA.dic +0 -1654
- package/dist/dictionaries/hyph_zu_ZA.dic +0 -171
- package/dist/index.d.mts +0 -48
- package/dist/index.d.ts +0 -48
- package/dist/index.js +0 -236
- package/dist/index.mjs +0 -201
- package/tsconfig.pkg.json +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @lunarisapp/hyphen
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`cd64da1`](https://github.com/LunarisApp/text-tools/commit/cd64da18993b790ea543286eafcc870bcf7aa4a3) Thanks [@MrLightful](https://github.com/MrLightful)! - Downgrade target to es2020
|
|
8
|
+
|
|
9
|
+
- [`7e2718f`](https://github.com/LunarisApp/text-tools/commit/7e2718fd9959b66e1fc0912e15b1ad340fde7be3) Thanks [@MrLightful](https://github.com/MrLightful)! - Fix bundling of dictionary assets
|
|
10
|
+
|
|
3
11
|
## 0.0.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/eslint.config.js
CHANGED
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunarisapp/hyphen",
|
|
3
3
|
"description": "A hyphenation library for JavaScript",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Roman Sirokov",
|
|
7
7
|
"url": "https://mrlightful.com",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://lunaris.app",
|
|
11
11
|
"repository": {
|
|
12
|
-
"url": "https://github.com/LunarisApp/text-tools
|
|
12
|
+
"url": "https://github.com/LunarisApp/text-tools"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
@@ -18,31 +18,33 @@
|
|
|
18
18
|
"hyphenation",
|
|
19
19
|
"text",
|
|
20
20
|
"linguistics",
|
|
21
|
-
"language"
|
|
21
|
+
"language",
|
|
22
|
+
"pronunciation",
|
|
23
|
+
"transcription",
|
|
24
|
+
"syllables"
|
|
22
25
|
],
|
|
23
|
-
"
|
|
26
|
+
"license": "Apache-2.0",
|
|
24
27
|
"main": "./dist/index.js",
|
|
25
28
|
"module": "./dist/index.mjs",
|
|
26
29
|
"types": "./dist/index.d.ts",
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@babel/core": "^7.26.
|
|
29
|
-
"@babel/preset-env": "^7.26.
|
|
31
|
+
"@babel/core": "^7.26.9",
|
|
32
|
+
"@babel/preset-env": "^7.26.9",
|
|
30
33
|
"@babel/preset-typescript": "^7.26.0",
|
|
31
34
|
"@eslint/js": "^9.20.0",
|
|
32
35
|
"@jest/globals": "^29.7.0",
|
|
33
|
-
"@types/node": "^22.13.4",
|
|
34
36
|
"babel-jest": "^29.7.0",
|
|
35
|
-
"copyfiles": "^2.4.1",
|
|
36
37
|
"eslint": "^9.20.1",
|
|
37
|
-
"
|
|
38
|
+
"eslint-config-prettier": "^10.0.1",
|
|
39
|
+
"eslint-plugin-only-warn": "^1.1.0",
|
|
40
|
+
"eslint-plugin-turbo": "^2.4.2",
|
|
38
41
|
"jest": "^29.7.0",
|
|
39
42
|
"tsup": "^8.3.6",
|
|
40
|
-
"tsx": "^4.19.2",
|
|
41
43
|
"typescript": "^5.5.3",
|
|
42
44
|
"typescript-eslint": "^8.24.0"
|
|
43
45
|
},
|
|
44
46
|
"scripts": {
|
|
45
|
-
"build": "tsup
|
|
47
|
+
"build": "tsup",
|
|
46
48
|
"lint": "eslint \"{src,tests}/**/*.ts\" --fix",
|
|
47
49
|
"test": "jest"
|
|
48
50
|
}
|
package/src/dicts.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
export type HyphenDict = string;
|
|
2
|
+
|
|
3
|
+
import * as afZaDict from "./dictionaries/hyph_af_ZA.dic";
|
|
4
|
+
export const afZa: HyphenDict = afZaDict.default;
|
|
5
|
+
|
|
6
|
+
import * as asInDict from "./dictionaries/hyph_as_IN.dic";
|
|
7
|
+
export const asIn: HyphenDict = asInDict.default;
|
|
8
|
+
|
|
9
|
+
import * as beByDict from "./dictionaries/hyph_be_BY.dic";
|
|
10
|
+
export const beBy: HyphenDict = beByDict.default;
|
|
11
|
+
|
|
12
|
+
import * as bgBGDict from "./dictionaries/hyph_bg_BG.dic";
|
|
13
|
+
export const bgBG: HyphenDict = bgBGDict.default;
|
|
14
|
+
|
|
15
|
+
import * as caDict from "./dictionaries/hyph_ca.dic";
|
|
16
|
+
export const ca: HyphenDict = caDict.default;
|
|
17
|
+
|
|
18
|
+
// import * as cs_CZDict from "./dictionaries/hyph_cs_CZ.dic";
|
|
19
|
+
// export const cs_CZ: HyphenDict = cs_CZDict.default;
|
|
20
|
+
|
|
21
|
+
import * as daDKDict from "./dictionaries/hyph_da_DK.dic";
|
|
22
|
+
export const daDK: HyphenDict = daDKDict.default;
|
|
23
|
+
|
|
24
|
+
import * as deDTDict from "./dictionaries/hyph_de_AT.dic";
|
|
25
|
+
export const deDT: HyphenDict = deDTDict.default;
|
|
26
|
+
|
|
27
|
+
import * as deCHDict from "./dictionaries/hyph_de_CH.dic";
|
|
28
|
+
export const deCH: HyphenDict = deCHDict.default;
|
|
29
|
+
//
|
|
30
|
+
import * as deDEDict from "./dictionaries/hyph_de_DE.dic";
|
|
31
|
+
export const deDE: HyphenDict = deDEDict.default;
|
|
32
|
+
|
|
33
|
+
// import * as elGRDict from "./dictionaries/hyph_el_GR.dic";
|
|
34
|
+
// export const elGR: HyphenDict = elGRDict.default;
|
|
35
|
+
|
|
36
|
+
import * as enGBDict from "./dictionaries/hyph_en_GB.dic";
|
|
37
|
+
export const enGB: HyphenDict = enGBDict.default;
|
|
38
|
+
//
|
|
39
|
+
import * as enUSDict from "./dictionaries/hyph_en_US.dic";
|
|
40
|
+
export const enUS: HyphenDict = enUSDict.default;
|
|
41
|
+
//
|
|
42
|
+
import * as eoDict from "./dictionaries/hyph_eo.dic";
|
|
43
|
+
export const eo: HyphenDict = eoDict.default;
|
|
44
|
+
|
|
45
|
+
import * as esDict from "./dictionaries/hyph_es.dic";
|
|
46
|
+
export const es: HyphenDict = esDict.default;
|
|
47
|
+
|
|
48
|
+
import * as etEEDict from "./dictionaries/hyph_et_EE.dic";
|
|
49
|
+
export const etEE: HyphenDict = etEEDict.default;
|
|
50
|
+
|
|
51
|
+
import * as frDict from "./dictionaries/hyph_fr.dic";
|
|
52
|
+
export const fr: HyphenDict = frDict.default;
|
|
53
|
+
|
|
54
|
+
import * as glDict from "./dictionaries/hyph_gl.dic";
|
|
55
|
+
export const gl: HyphenDict = glDict.default;
|
|
56
|
+
|
|
57
|
+
import * as hrHRDict from "./dictionaries/hyph_hr_HR.dic";
|
|
58
|
+
export const hrHR: HyphenDict = hrHRDict.default;
|
|
59
|
+
|
|
60
|
+
import * as huHUDict from "./dictionaries/hyph_hu_HU.dic";
|
|
61
|
+
export const huHU: HyphenDict = huHUDict.default;
|
|
62
|
+
|
|
63
|
+
import * as idIDDict from "./dictionaries/hyph_id_ID.dic";
|
|
64
|
+
export const idID: HyphenDict = idIDDict.default;
|
|
65
|
+
|
|
66
|
+
import * as isDict from "./dictionaries/hyph_is.dic";
|
|
67
|
+
export const is: HyphenDict = isDict.default;
|
|
68
|
+
|
|
69
|
+
import * as itITDict from "./dictionaries/hyph_it_IT.dic";
|
|
70
|
+
export const itIT: HyphenDict = itITDict.default;
|
|
71
|
+
|
|
72
|
+
import * as knINDict from "./dictionaries/hyph_kn_IN.dic";
|
|
73
|
+
export const knIN: HyphenDict = knINDict.default;
|
|
74
|
+
|
|
75
|
+
import * as ltDict from "./dictionaries/hyph_lt.dic";
|
|
76
|
+
export const lt: HyphenDict = ltDict.default;
|
|
77
|
+
|
|
78
|
+
import * as lvLVDict from "./dictionaries/hyph_lv_LV.dic";
|
|
79
|
+
export const lvLV: HyphenDict = lvLVDict.default;
|
|
80
|
+
|
|
81
|
+
import * as mnMNDict from "./dictionaries/hyph_mn_MN.dic";
|
|
82
|
+
export const mnMN: HyphenDict = mnMNDict.default;
|
|
83
|
+
|
|
84
|
+
import * as mrINDict from "./dictionaries/hyph_mr_IN.dic";
|
|
85
|
+
export const mrIN: HyphenDict = mrINDict.default;
|
|
86
|
+
|
|
87
|
+
import * as nbNODict from "./dictionaries/hyph_nb_NO.dic";
|
|
88
|
+
export const nbNO: HyphenDict = nbNODict.default;
|
|
89
|
+
|
|
90
|
+
import * as nlNLDict from "./dictionaries/hyph_nl_NL.dic";
|
|
91
|
+
export const nlNL: HyphenDict = nlNLDict.default;
|
|
92
|
+
|
|
93
|
+
import * as nnNODict from "./dictionaries/hyph_nn_NO.dic";
|
|
94
|
+
export const nnNO: HyphenDict = nnNODict.default;
|
|
95
|
+
|
|
96
|
+
import * as paINDict from "./dictionaries/hyph_pa_IN.dic";
|
|
97
|
+
export const paIN: HyphenDict = paINDict.default;
|
|
98
|
+
|
|
99
|
+
import * as plPLDict from "./dictionaries/hyph_pl_PL.dic";
|
|
100
|
+
export const plPL: HyphenDict = plPLDict.default;
|
|
101
|
+
|
|
102
|
+
import * as ptBRDict from "./dictionaries/hyph_pt_BR.dic";
|
|
103
|
+
export const ptBR: HyphenDict = ptBRDict.default;
|
|
104
|
+
|
|
105
|
+
import * as ptPTDict from "./dictionaries/hyph_pt_PT.dic";
|
|
106
|
+
export const ptPT: HyphenDict = ptPTDict.default;
|
|
107
|
+
|
|
108
|
+
import * as roRODict from "./dictionaries/hyph_ro_RO.dic";
|
|
109
|
+
export const roRO: HyphenDict = roRODict.default;
|
|
110
|
+
|
|
111
|
+
import * as ruRUDict from "./dictionaries/hyph_ru_RU.dic";
|
|
112
|
+
export const ruRU: HyphenDict = ruRUDict.default;
|
|
113
|
+
|
|
114
|
+
import * as saINDict from "./dictionaries/hyph_sa_IN.dic";
|
|
115
|
+
export const saIN: HyphenDict = saINDict.default;
|
|
116
|
+
|
|
117
|
+
import * as skSKDict from "./dictionaries/hyph_sk_SK.dic";
|
|
118
|
+
export const skSK: HyphenDict = skSKDict.default;
|
|
119
|
+
|
|
120
|
+
import * as slSIDict from "./dictionaries/hyph_sl_SI.dic";
|
|
121
|
+
export const slSI: HyphenDict = slSIDict.default;
|
|
122
|
+
|
|
123
|
+
import * as sqALDict from "./dictionaries/hyph_sq_AL.dic";
|
|
124
|
+
export const sqAL: HyphenDict = sqALDict.default;
|
|
125
|
+
|
|
126
|
+
import * as srDict from "./dictionaries/hyph_sr.dic";
|
|
127
|
+
export const sr: HyphenDict = srDict.default;
|
|
128
|
+
|
|
129
|
+
import * as srLatnDict from "./dictionaries/hyph_sr-Latn.dic";
|
|
130
|
+
export const srLatn: HyphenDict = srLatnDict.default;
|
|
131
|
+
|
|
132
|
+
import * as svDict from "./dictionaries/hyph_sv.dic";
|
|
133
|
+
export const sv: HyphenDict = svDict.default;
|
|
134
|
+
|
|
135
|
+
import * as teINDict from "./dictionaries/hyph_te_IN.dic";
|
|
136
|
+
export const teIN: HyphenDict = teINDict.default;
|
|
137
|
+
|
|
138
|
+
import * as thTHDict from "./dictionaries/hyph_th_TH.dic";
|
|
139
|
+
export const thTH: HyphenDict = thTHDict.default;
|
|
140
|
+
|
|
141
|
+
import * as ukUADict from "./dictionaries/hyph_uk_UA.dic";
|
|
142
|
+
export const ukUA: HyphenDict = ukUADict.default;
|
|
143
|
+
|
|
144
|
+
import * as zuZADict from "./dictionaries/hyph_zu_ZA.dic";
|
|
145
|
+
export const zuZA: HyphenDict = zuZADict.default;
|
|
146
|
+
|
|
147
|
+
export const dictionaries = {
|
|
148
|
+
af: afZa,
|
|
149
|
+
as: asIn,
|
|
150
|
+
be: beBy,
|
|
151
|
+
bg: bgBG,
|
|
152
|
+
ca,
|
|
153
|
+
// cs: cs_CZ,
|
|
154
|
+
da: daDK,
|
|
155
|
+
de: deDE,
|
|
156
|
+
de_DE: deDE,
|
|
157
|
+
de_CH: deCH,
|
|
158
|
+
de_AT: deDT,
|
|
159
|
+
// el: elGR,
|
|
160
|
+
en: enUS,
|
|
161
|
+
en_US: enUS,
|
|
162
|
+
en_GB: enGB,
|
|
163
|
+
eo,
|
|
164
|
+
es,
|
|
165
|
+
et: etEE,
|
|
166
|
+
fr,
|
|
167
|
+
gl,
|
|
168
|
+
hr: hrHR,
|
|
169
|
+
hu: huHU,
|
|
170
|
+
id: idID,
|
|
171
|
+
is,
|
|
172
|
+
it: itIT,
|
|
173
|
+
kn: knIN,
|
|
174
|
+
lt,
|
|
175
|
+
lv: lvLV,
|
|
176
|
+
mn: mnMN,
|
|
177
|
+
mr: mrIN,
|
|
178
|
+
nb: nbNO,
|
|
179
|
+
nl: nlNL,
|
|
180
|
+
nn: nnNO,
|
|
181
|
+
pa: paIN,
|
|
182
|
+
pl: plPL,
|
|
183
|
+
pt: ptBR,
|
|
184
|
+
ptPT: ptPT,
|
|
185
|
+
pt_BR: ptBR,
|
|
186
|
+
ro: roRO,
|
|
187
|
+
ru: ruRU,
|
|
188
|
+
sa: saIN,
|
|
189
|
+
sk: skSK,
|
|
190
|
+
sl: slSI,
|
|
191
|
+
sq: sqAL,
|
|
192
|
+
sr,
|
|
193
|
+
sr_Latn: srLatn,
|
|
194
|
+
sv,
|
|
195
|
+
te: teIN,
|
|
196
|
+
th: thTH,
|
|
197
|
+
uk: ukUA,
|
|
198
|
+
zu: zuZA,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export type Language = keyof typeof dictionaries;
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { HyphenDict, enUS, dictionaries, Language } from "./dicts";
|
|
2
|
+
|
|
3
|
+
export * from "./dicts";
|
|
4
|
+
|
|
5
|
+
// export function getDictionary(lang: string) {
|
|
6
|
+
// return import(`./dictionaries/hyph_${lang}.dic`);
|
|
7
|
+
// }
|
|
3
8
|
|
|
4
|
-
const DICTIONARY_PATH = join(__dirname, "dictionaries");
|
|
5
9
|
const IGNORED = [
|
|
6
10
|
"%",
|
|
7
11
|
"#",
|
|
@@ -21,17 +25,13 @@ class DataInt {
|
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
class
|
|
28
|
+
class HyphenDictParser {
|
|
25
29
|
patterns: Map<string, [number, number[]]> = new Map();
|
|
26
30
|
cache: Map<string, DataInt[]> = new Map();
|
|
27
31
|
maxLen: number = 0;
|
|
28
32
|
|
|
29
|
-
constructor(
|
|
30
|
-
|
|
31
|
-
throw new Error(`Dictionary file not found: ${filePath}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const lines = fs.readFileSync(filePath, "utf-8").split("\n");
|
|
33
|
+
constructor(content: string) {
|
|
34
|
+
const lines = content.split("\n");
|
|
35
35
|
lines.forEach((line) => {
|
|
36
36
|
line = line.trim();
|
|
37
37
|
if (!line || IGNORED.some((i) => line.startsWith(i))) return;
|
|
@@ -101,61 +101,15 @@ class HyphenDict {
|
|
|
101
101
|
export class TextHyphen {
|
|
102
102
|
private readonly left: number;
|
|
103
103
|
private readonly right: number;
|
|
104
|
-
private hd
|
|
105
|
-
readonly dictionaries: Record<string, string>;
|
|
106
|
-
private readonly lowercaseLangs: Record<string, string>;
|
|
104
|
+
private hd!: HyphenDictParser;
|
|
107
105
|
|
|
108
|
-
constructor(props?: { lang?:
|
|
109
|
-
const { lang = "
|
|
106
|
+
constructor(props?: { lang?: Language; left?: number; right?: number }) {
|
|
107
|
+
const { lang = "en", left = 2, right = 2 } = props || {};
|
|
110
108
|
this.left = left;
|
|
111
109
|
this.right = right;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
acc[lang.toLowerCase()] = lang;
|
|
116
|
-
return acc;
|
|
117
|
-
},
|
|
118
|
-
{} as Record<string, string>,
|
|
119
|
-
);
|
|
120
|
-
const fallback = this.getLanguageFallback(lang);
|
|
121
|
-
if (!fallback) {
|
|
122
|
-
throw new Error(`Language not found: ${lang}`);
|
|
123
|
-
}
|
|
124
|
-
this.hd = new HyphenDict(
|
|
125
|
-
join(DICTIONARY_PATH, this.dictionaries[fallback]!),
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private loadDictionaries() {
|
|
130
|
-
const dictionaries: Record<string, string> = {};
|
|
131
|
-
for (const file of fs.readdirSync(DICTIONARY_PATH).sort()) {
|
|
132
|
-
const [name, ext] = file.split(".");
|
|
133
|
-
const lang = name!.replace("hyph_", "").replace("-", "_"); // File name format: hyph_LANG-COUNTRY.dic
|
|
134
|
-
const shortLang = lang.split("_")[0];
|
|
135
|
-
if (ext === "dic") {
|
|
136
|
-
dictionaries[lang] = file;
|
|
137
|
-
if (!dictionaries[shortLang!]) {
|
|
138
|
-
dictionaries[shortLang!] = file;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return dictionaries;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get the fallback language for a given language.
|
|
147
|
-
* @param language
|
|
148
|
-
*/
|
|
149
|
-
getLanguageFallback(language: string) {
|
|
150
|
-
const parts = language.replace("-", "_").toLowerCase().split("_");
|
|
151
|
-
while (parts.length) {
|
|
152
|
-
const currentLanguage = parts.join("_");
|
|
153
|
-
if (this.lowercaseLangs[currentLanguage]) {
|
|
154
|
-
return this.lowercaseLangs[currentLanguage];
|
|
155
|
-
}
|
|
156
|
-
parts.pop();
|
|
157
|
-
}
|
|
158
|
-
return undefined;
|
|
110
|
+
const dict = dictionaries[lang] || enUS;
|
|
111
|
+
// const dictStr = new TextDecoder().decode(dict);
|
|
112
|
+
this.hd = new HyphenDictParser(dict);
|
|
159
113
|
}
|
|
160
114
|
|
|
161
115
|
/**
|
|
@@ -199,7 +153,7 @@ export class TextHyphen {
|
|
|
199
153
|
* @param word
|
|
200
154
|
*/
|
|
201
155
|
variants(word: string): string[][] {
|
|
202
|
-
return this.iterate(word)
|
|
156
|
+
return Array.from(this.iterate(word));
|
|
203
157
|
}
|
|
204
158
|
|
|
205
159
|
/**
|
package/src/types.d.ts
ADDED
package/tests/hyphen.test.ts
CHANGED
|
@@ -3,19 +3,19 @@ import { TextHyphen } from "../src";
|
|
|
3
3
|
|
|
4
4
|
describe("hyphen tests", () => {
|
|
5
5
|
it("should correctly hyphenate words using inserted method", () => {
|
|
6
|
-
const dic = new TextHyphen({ lang: "
|
|
6
|
+
const dic = new TextHyphen({ lang: "nl" });
|
|
7
7
|
expect(dic.inserted("lettergrepen")).toBe("let-ter-gre-pen");
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it("should correctly wrap words", () => {
|
|
11
|
-
const dic = new TextHyphen({ lang: "
|
|
11
|
+
const dic = new TextHyphen({ lang: "nl" });
|
|
12
12
|
const actual = dic.wrap("autobandventieldopje", 11);
|
|
13
13
|
const expected = ["autoband-", "ventieldopje"];
|
|
14
14
|
expect(actual).toStrictEqual(expected);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
it("should iterate hyphenation positions correctly", () => {
|
|
18
|
-
const dic = new TextHyphen({ lang: "
|
|
18
|
+
const dic = new TextHyphen({ lang: "nl" });
|
|
19
19
|
console.log(dic);
|
|
20
20
|
const actual = dic.variants("Amsterdam");
|
|
21
21
|
const expected = [
|
|
@@ -25,20 +25,6 @@ describe("hyphen tests", () => {
|
|
|
25
25
|
expect(actual).toStrictEqual(expected);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it("should use a fallback dictionary", () => {
|
|
29
|
-
const dic = new TextHyphen({ lang: "nl_NL-variant" });
|
|
30
|
-
const actual = dic.variants("Amsterdam");
|
|
31
|
-
const expected = [
|
|
32
|
-
["Amster", "dam"],
|
|
33
|
-
["Am", "sterdam"],
|
|
34
|
-
];
|
|
35
|
-
expect(actual).toStrictEqual(expected);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should throw an error for a missing dictionary", () => {
|
|
39
|
-
expect(() => new TextHyphen({ lang: "mi_SS" })).toThrowError();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
28
|
// it('should use a custom dictionary', () => {
|
|
43
29
|
// const dic = new Hyphen('fr');
|
|
44
30
|
// expect(dic.inserted('autobandventieldopje')).to.not.equal(
|
|
@@ -53,19 +39,19 @@ describe("hyphen tests", () => {
|
|
|
53
39
|
|
|
54
40
|
describe("should support left and right hyphenation constraints", () => {
|
|
55
41
|
it("default", () => {
|
|
56
|
-
const dic = new TextHyphen({ lang: "
|
|
42
|
+
const dic = new TextHyphen({ lang: "nl" });
|
|
57
43
|
expect(dic.inserted("lettergrepen")).toBe("let-ter-gre-pen");
|
|
58
44
|
});
|
|
59
45
|
it("left", () => {
|
|
60
|
-
const dic = new TextHyphen({ lang: "
|
|
46
|
+
const dic = new TextHyphen({ lang: "nl", left: 4 });
|
|
61
47
|
expect(dic.inserted("lettergrepen")).toBe("letter-gre-pen");
|
|
62
48
|
});
|
|
63
49
|
it("right", () => {
|
|
64
|
-
const dic = new TextHyphen({ lang: "
|
|
50
|
+
const dic = new TextHyphen({ lang: "nl", right: 4 });
|
|
65
51
|
expect(dic.inserted("lettergrepen")).toBe("let-ter-grepen");
|
|
66
52
|
});
|
|
67
53
|
it("both", () => {
|
|
68
|
-
const dic = new TextHyphen({ lang: "
|
|
54
|
+
const dic = new TextHyphen({ lang: "nl", left: 4, right: 4 });
|
|
69
55
|
expect(dic.inserted("lettergrepen")).toBe("letter-grepen");
|
|
70
56
|
});
|
|
71
57
|
});
|
|
@@ -83,7 +69,7 @@ describe("hyphen tests", () => {
|
|
|
83
69
|
// });
|
|
84
70
|
|
|
85
71
|
it("should handle uppercase words correctly", () => {
|
|
86
|
-
const dic = new TextHyphen({ lang: "
|
|
72
|
+
const dic = new TextHyphen({ lang: "nl" });
|
|
87
73
|
expect(dic.inserted("LETTERGREPEN")).toBe("LET-TER-GRE-PEN");
|
|
88
74
|
});
|
|
89
75
|
|
|
@@ -95,24 +81,4 @@ describe("hyphen tests", () => {
|
|
|
95
81
|
// ]);
|
|
96
82
|
// assert.strictEqual(dic.inserted("KULISSZA"), "KU-LISZ-SZA");
|
|
97
83
|
// });
|
|
98
|
-
|
|
99
|
-
it("should be able to load all dictionaries", () => {
|
|
100
|
-
const hyp = new TextHyphen();
|
|
101
|
-
const dictionaries = hyp.dictionaries;
|
|
102
|
-
Object.keys(dictionaries).forEach((dict) => {
|
|
103
|
-
new TextHyphen({ lang: dict });
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should correctly determine language fallbacks", () => {
|
|
108
|
-
const hyp = new TextHyphen();
|
|
109
|
-
expect(hyp.getLanguageFallback("en")).toBe("en");
|
|
110
|
-
expect(hyp.getLanguageFallback("en_US")).toBe("en_US");
|
|
111
|
-
expect(hyp.getLanguageFallback("en_FR")).toBe("en");
|
|
112
|
-
expect(hyp.getLanguageFallback("sr-Latn")).toBe("sr_Latn");
|
|
113
|
-
expect(hyp.getLanguageFallback("SR-LATN")).toBe("sr_Latn");
|
|
114
|
-
expect(hyp.getLanguageFallback("sr-Cyrl")).toBe("sr");
|
|
115
|
-
expect(hyp.getLanguageFallback("fr-Latn-FR")).toBe("fr");
|
|
116
|
-
expect(hyp.getLanguageFallback("en-US_variant1-x")).toBe("en_US");
|
|
117
|
-
});
|
|
118
84
|
});
|
package/tsup.config.ts
ADDED
package/.turbo/turbo-build.log
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @lunarisapp/hyphen@0.0.2 build /Users/rsirokov/Projects/Lunaris/text-tools/packages/hyphen
|
|
4
|
-
> tsup src/index.ts --format cjs,esm --dts && copyfiles -u 1 src/dictionaries/*.dic dist
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
-
[34mCLI[39m Using tsconfig: ../../tsconfig.json
|
|
8
|
-
[34mCLI[39m tsup v8.3.6
|
|
9
|
-
[34mCLI[39m Target: esnext
|
|
10
|
-
[34mCJS[39m Build start
|
|
11
|
-
[34mESM[39m Build start
|
|
12
|
-
[33mCJS[39m [33mYou have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin[39m
|
|
13
|
-
[33mESM[39m [33mYou have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin[39m
|
|
14
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m5.59 KB[39m
|
|
15
|
-
[32mESM[39m ⚡️ Build success in 52ms
|
|
16
|
-
[32mCJS[39m [1mdist/index.js [22m[32m7.26 KB[39m
|
|
17
|
-
[32mCJS[39m ⚡️ Build success in 52ms
|
|
18
|
-
DTS Build start
|
|
19
|
-
error TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["src/**/*.ts"]' and 'exclude' paths were '["node_modules","dist"]'.
|
|
20
|
-
|
|
21
|
-
DTS ⚡️ Build success in 907ms
|
|
22
|
-
DTS dist/index.d.ts 1.27 KB
|
|
23
|
-
DTS dist/index.d.mts 1.27 KB
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @lunaris/hyphen@0.0.1 lint /Users/rsirokov/Projects/Lunaris/text-tools/packages/hyphen
|
|
4
|
-
> eslint "{src,tests}/**/*.ts" --fix
|
|
5
|
-
|
|
6
|
-
(node:65030) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/rsirokov/Projects/Lunaris/text-tools/packages/hyphen/eslint.config.js?mtime=1739479673334 is not specified and it doesn't parse as CommonJS.
|
|
7
|
-
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
|
|
8
|
-
To eliminate this warning, add "type": "module" to /Users/rsirokov/Projects/Lunaris/text-tools/packages/hyphen/package.json.
|
|
9
|
-
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
10
|
-
(node:65030) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/rsirokov/Projects/Lunaris/text-tools/eslint.config.js is not specified and it doesn't parse as CommonJS.
|
|
11
|
-
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
|
|
12
|
-
To eliminate this warning, add "type": "module" to /Users/rsirokov/Projects/Lunaris/text-tools/package.json.
|