ipa-hangul 1.2.2 → 1.2.3
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/dist/index.js +54 -0
- package/dist/index.mjs +54 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -262,6 +262,49 @@ function preprocessIPA(ipa) {
|
|
|
262
262
|
function hasIPAVowel(text) {
|
|
263
263
|
return /[iɪeɛæɑɒɔʌəɜɝʊuoa]/.test(text);
|
|
264
264
|
}
|
|
265
|
+
function getTrailingConsonants(text) {
|
|
266
|
+
let i = text.length;
|
|
267
|
+
while (i > 0) {
|
|
268
|
+
if (i >= 2) {
|
|
269
|
+
const twoChar = text.substring(i - 2, i);
|
|
270
|
+
if (CONSONANT_TO_CHOSEONG[twoChar] || CONSONANT_TO_JAMO[twoChar]) {
|
|
271
|
+
i -= 2;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const oneChar = text[i - 1];
|
|
276
|
+
if (CONSONANT_TO_CHOSEONG[oneChar] || CONSONANT_TO_JAMO[oneChar]) {
|
|
277
|
+
i--;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
const beforeConsonants = text.substring(0, i);
|
|
283
|
+
const allTrailing = text.substring(i);
|
|
284
|
+
if (!allTrailing) {
|
|
285
|
+
return { before: text, trailing: "" };
|
|
286
|
+
}
|
|
287
|
+
let keepUntil = 0;
|
|
288
|
+
if (allTrailing.length >= 2) {
|
|
289
|
+
const twoChar = allTrailing.substring(0, 2);
|
|
290
|
+
if (CONSONANT_TO_JONGSEONG[twoChar] !== void 0) {
|
|
291
|
+
keepUntil = 2;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (keepUntil === 0 && allTrailing.length >= 1) {
|
|
295
|
+
const oneChar = allTrailing[0];
|
|
296
|
+
if (CONSONANT_TO_JONGSEONG[oneChar] !== void 0) {
|
|
297
|
+
keepUntil = 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
before: beforeConsonants + allTrailing.substring(0, keepUntil),
|
|
302
|
+
trailing: allTrailing.substring(keepUntil)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function startsWithVowel(text) {
|
|
306
|
+
return matchVowel(text, 0) !== null;
|
|
307
|
+
}
|
|
265
308
|
function parseSyllables(text) {
|
|
266
309
|
const syllables = [];
|
|
267
310
|
const parts = text.split(".");
|
|
@@ -285,6 +328,17 @@ function parseSyllables(text) {
|
|
|
285
328
|
}
|
|
286
329
|
merged.push(curr);
|
|
287
330
|
}
|
|
331
|
+
for (let i = 0; i < merged.length - 1; i++) {
|
|
332
|
+
const curr = merged[i];
|
|
333
|
+
const next = merged[i + 1];
|
|
334
|
+
if (startsWithVowel(next.text)) {
|
|
335
|
+
const { before, trailing } = getTrailingConsonants(curr.text);
|
|
336
|
+
if (trailing && before) {
|
|
337
|
+
curr.text = before;
|
|
338
|
+
next.text = trailing + next.text;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
288
342
|
return merged;
|
|
289
343
|
}
|
|
290
344
|
function splitByLongVowel(text) {
|
package/dist/index.mjs
CHANGED
|
@@ -238,6 +238,49 @@ function preprocessIPA(ipa) {
|
|
|
238
238
|
function hasIPAVowel(text) {
|
|
239
239
|
return /[iɪeɛæɑɒɔʌəɜɝʊuoa]/.test(text);
|
|
240
240
|
}
|
|
241
|
+
function getTrailingConsonants(text) {
|
|
242
|
+
let i = text.length;
|
|
243
|
+
while (i > 0) {
|
|
244
|
+
if (i >= 2) {
|
|
245
|
+
const twoChar = text.substring(i - 2, i);
|
|
246
|
+
if (CONSONANT_TO_CHOSEONG[twoChar] || CONSONANT_TO_JAMO[twoChar]) {
|
|
247
|
+
i -= 2;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const oneChar = text[i - 1];
|
|
252
|
+
if (CONSONANT_TO_CHOSEONG[oneChar] || CONSONANT_TO_JAMO[oneChar]) {
|
|
253
|
+
i--;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
const beforeConsonants = text.substring(0, i);
|
|
259
|
+
const allTrailing = text.substring(i);
|
|
260
|
+
if (!allTrailing) {
|
|
261
|
+
return { before: text, trailing: "" };
|
|
262
|
+
}
|
|
263
|
+
let keepUntil = 0;
|
|
264
|
+
if (allTrailing.length >= 2) {
|
|
265
|
+
const twoChar = allTrailing.substring(0, 2);
|
|
266
|
+
if (CONSONANT_TO_JONGSEONG[twoChar] !== void 0) {
|
|
267
|
+
keepUntil = 2;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (keepUntil === 0 && allTrailing.length >= 1) {
|
|
271
|
+
const oneChar = allTrailing[0];
|
|
272
|
+
if (CONSONANT_TO_JONGSEONG[oneChar] !== void 0) {
|
|
273
|
+
keepUntil = 1;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
before: beforeConsonants + allTrailing.substring(0, keepUntil),
|
|
278
|
+
trailing: allTrailing.substring(keepUntil)
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function startsWithVowel(text) {
|
|
282
|
+
return matchVowel(text, 0) !== null;
|
|
283
|
+
}
|
|
241
284
|
function parseSyllables(text) {
|
|
242
285
|
const syllables = [];
|
|
243
286
|
const parts = text.split(".");
|
|
@@ -261,6 +304,17 @@ function parseSyllables(text) {
|
|
|
261
304
|
}
|
|
262
305
|
merged.push(curr);
|
|
263
306
|
}
|
|
307
|
+
for (let i = 0; i < merged.length - 1; i++) {
|
|
308
|
+
const curr = merged[i];
|
|
309
|
+
const next = merged[i + 1];
|
|
310
|
+
if (startsWithVowel(next.text)) {
|
|
311
|
+
const { before, trailing } = getTrailingConsonants(curr.text);
|
|
312
|
+
if (trailing && before) {
|
|
313
|
+
curr.text = before;
|
|
314
|
+
next.text = trailing + next.text;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
264
318
|
return merged;
|
|
265
319
|
}
|
|
266
320
|
function splitByLongVowel(text) {
|