ipa-hangul 1.0.1 → 1.0.2
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 +41 -12
- package/dist/index.mjs +41 -12
- package/package.json +8 -5
package/dist/index.js
CHANGED
|
@@ -256,7 +256,7 @@ function matchConsonant(text, pos) {
|
|
|
256
256
|
return null;
|
|
257
257
|
}
|
|
258
258
|
function preprocessIPA(ipa) {
|
|
259
|
-
return ipa.replace(/\([^)]*\)/g, "").replace(/[ˈˌ′'\/\[\]
|
|
259
|
+
return ipa.replace(/\([^)]*\)/g, "").replace(/[ˈˌ′']/g, ".").replace(/[\/\[\]]/g, "").replace(/\.+/g, ".").replace(/^\.|\.$/g, "").trim();
|
|
260
260
|
}
|
|
261
261
|
function splitByLongVowel(text) {
|
|
262
262
|
const segments = [];
|
|
@@ -303,7 +303,31 @@ function convertSegment(tokens) {
|
|
|
303
303
|
const token = tokens[i];
|
|
304
304
|
if (token.type === "consonant" && i + 1 < tokens.length && tokens[i + 1].type === "vowel") {
|
|
305
305
|
const consonant = token.ipa;
|
|
306
|
-
|
|
306
|
+
let vowel = tokens[i + 1].ipa;
|
|
307
|
+
if (consonant === "\u0283") {
|
|
308
|
+
const shVowelMap = {
|
|
309
|
+
"\u0259": "j\u0259",
|
|
310
|
+
// ʃə → 셔 (shə like in -tion)
|
|
311
|
+
"\u025C\u02D0": "j\u025C\u02D0",
|
|
312
|
+
"\u025C": "j\u025C",
|
|
313
|
+
"\u028C": "j\u0259",
|
|
314
|
+
"a": "ja",
|
|
315
|
+
"\u0251\u02D0": "j\u0251\u02D0",
|
|
316
|
+
"\u0251": "j\u0251",
|
|
317
|
+
// ʃa → 샤
|
|
318
|
+
"o": "jo",
|
|
319
|
+
"\u0254\u02D0": "j\u0254\u02D0",
|
|
320
|
+
"\u0254": "j\u0254",
|
|
321
|
+
// ʃo → 쇼
|
|
322
|
+
"u": "ju",
|
|
323
|
+
"u\u02D0": "ju\u02D0",
|
|
324
|
+
"\u028A": "ju"
|
|
325
|
+
// ʃu → 슈
|
|
326
|
+
};
|
|
327
|
+
if (shVowelMap[vowel]) {
|
|
328
|
+
vowel = shVowelMap[vowel];
|
|
329
|
+
}
|
|
330
|
+
}
|
|
307
331
|
const choIdx = CONSONANT_TO_CHOSEONG[consonant];
|
|
308
332
|
const jungIndices = VOWEL_TO_JUNGSEONG[vowel];
|
|
309
333
|
if (choIdx !== void 0 && jungIndices) {
|
|
@@ -368,16 +392,21 @@ function ipaToHangul(ipa) {
|
|
|
368
392
|
if (!ipa) return "";
|
|
369
393
|
const cleaned = preprocessIPA(ipa);
|
|
370
394
|
if (!cleaned) return "";
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
395
|
+
const syllables = cleaned.split(".").filter((s) => s.length > 0);
|
|
396
|
+
const results = [];
|
|
397
|
+
for (const syllable of syllables) {
|
|
398
|
+
const segments = splitByLongVowel(syllable);
|
|
399
|
+
const convertedSegments = segments.map((seg) => {
|
|
400
|
+
const tokens = tokenizeSegment(seg.text);
|
|
401
|
+
const hangul = convertSegment(tokens);
|
|
402
|
+
if (seg.hasLongVowel) {
|
|
403
|
+
return hangul + "-";
|
|
404
|
+
}
|
|
405
|
+
return hangul;
|
|
406
|
+
});
|
|
407
|
+
results.push(convertedSegments.join(""));
|
|
408
|
+
}
|
|
409
|
+
return results.join("");
|
|
381
410
|
}
|
|
382
411
|
// Annotate the CommonJS export names for ESM import in node:
|
|
383
412
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -232,7 +232,7 @@ function matchConsonant(text, pos) {
|
|
|
232
232
|
return null;
|
|
233
233
|
}
|
|
234
234
|
function preprocessIPA(ipa) {
|
|
235
|
-
return ipa.replace(/\([^)]*\)/g, "").replace(/[ˈˌ′'\/\[\]
|
|
235
|
+
return ipa.replace(/\([^)]*\)/g, "").replace(/[ˈˌ′']/g, ".").replace(/[\/\[\]]/g, "").replace(/\.+/g, ".").replace(/^\.|\.$/g, "").trim();
|
|
236
236
|
}
|
|
237
237
|
function splitByLongVowel(text) {
|
|
238
238
|
const segments = [];
|
|
@@ -279,7 +279,31 @@ function convertSegment(tokens) {
|
|
|
279
279
|
const token = tokens[i];
|
|
280
280
|
if (token.type === "consonant" && i + 1 < tokens.length && tokens[i + 1].type === "vowel") {
|
|
281
281
|
const consonant = token.ipa;
|
|
282
|
-
|
|
282
|
+
let vowel = tokens[i + 1].ipa;
|
|
283
|
+
if (consonant === "\u0283") {
|
|
284
|
+
const shVowelMap = {
|
|
285
|
+
"\u0259": "j\u0259",
|
|
286
|
+
// ʃə → 셔 (shə like in -tion)
|
|
287
|
+
"\u025C\u02D0": "j\u025C\u02D0",
|
|
288
|
+
"\u025C": "j\u025C",
|
|
289
|
+
"\u028C": "j\u0259",
|
|
290
|
+
"a": "ja",
|
|
291
|
+
"\u0251\u02D0": "j\u0251\u02D0",
|
|
292
|
+
"\u0251": "j\u0251",
|
|
293
|
+
// ʃa → 샤
|
|
294
|
+
"o": "jo",
|
|
295
|
+
"\u0254\u02D0": "j\u0254\u02D0",
|
|
296
|
+
"\u0254": "j\u0254",
|
|
297
|
+
// ʃo → 쇼
|
|
298
|
+
"u": "ju",
|
|
299
|
+
"u\u02D0": "ju\u02D0",
|
|
300
|
+
"\u028A": "ju"
|
|
301
|
+
// ʃu → 슈
|
|
302
|
+
};
|
|
303
|
+
if (shVowelMap[vowel]) {
|
|
304
|
+
vowel = shVowelMap[vowel];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
283
307
|
const choIdx = CONSONANT_TO_CHOSEONG[consonant];
|
|
284
308
|
const jungIndices = VOWEL_TO_JUNGSEONG[vowel];
|
|
285
309
|
if (choIdx !== void 0 && jungIndices) {
|
|
@@ -344,16 +368,21 @@ function ipaToHangul(ipa) {
|
|
|
344
368
|
if (!ipa) return "";
|
|
345
369
|
const cleaned = preprocessIPA(ipa);
|
|
346
370
|
if (!cleaned) return "";
|
|
347
|
-
const
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
371
|
+
const syllables = cleaned.split(".").filter((s) => s.length > 0);
|
|
372
|
+
const results = [];
|
|
373
|
+
for (const syllable of syllables) {
|
|
374
|
+
const segments = splitByLongVowel(syllable);
|
|
375
|
+
const convertedSegments = segments.map((seg) => {
|
|
376
|
+
const tokens = tokenizeSegment(seg.text);
|
|
377
|
+
const hangul = convertSegment(tokens);
|
|
378
|
+
if (seg.hasLongVowel) {
|
|
379
|
+
return hangul + "-";
|
|
380
|
+
}
|
|
381
|
+
return hangul;
|
|
382
|
+
});
|
|
383
|
+
results.push(convertedSegments.join(""));
|
|
384
|
+
}
|
|
385
|
+
return results.join("");
|
|
357
386
|
}
|
|
358
387
|
export {
|
|
359
388
|
ipaToHangul
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ipa-hangul",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Convert IPA (International Phonetic Alphabet) pronunciation to Korean Hangul",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
20
|
-
"
|
|
20
|
+
"test": "node test.mjs",
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"prepare": "husky"
|
|
21
23
|
},
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/YangSeungWon/ipa-hangul.git"
|
|
26
|
+
"url": "git+https://github.com/YangSeungWon/ipa-hangul.git"
|
|
25
27
|
},
|
|
26
28
|
"homepage": "https://github.com/YangSeungWon/ipa-hangul#readme",
|
|
27
29
|
"bugs": {
|
|
@@ -38,7 +40,8 @@
|
|
|
38
40
|
"author": "YSW",
|
|
39
41
|
"license": "MIT",
|
|
40
42
|
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"tsup": "^8.0.0"
|
|
43
|
+
"husky": "^9.1.7",
|
|
44
|
+
"tsup": "^8.0.0",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
43
46
|
}
|
|
44
47
|
}
|