ipa-hangul 1.2.3 → 1.3.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/dist/index.d.mts CHANGED
@@ -12,6 +12,13 @@
12
12
  */
13
13
  interface IpaToHangulOptions {
14
14
  markStress?: 'markdown' | 'html';
15
+ /**
16
+ * When true, trailing consonants move to next syllable if it starts with a vowel.
17
+ * This produces more natural Korean loan word pronunciation.
18
+ * e.g., "tɪti" → "티티" instead of "팉이"
19
+ * @default true
20
+ */
21
+ preferOnset?: boolean;
15
22
  }
16
23
  /**
17
24
  * Convert IPA notation to Korean Hangul pronunciation
package/dist/index.d.ts CHANGED
@@ -12,6 +12,13 @@
12
12
  */
13
13
  interface IpaToHangulOptions {
14
14
  markStress?: 'markdown' | 'html';
15
+ /**
16
+ * When true, trailing consonants move to next syllable if it starts with a vowel.
17
+ * This produces more natural Korean loan word pronunciation.
18
+ * e.g., "tɪti" → "티티" instead of "팉이"
19
+ * @default true
20
+ */
21
+ preferOnset?: boolean;
15
22
  }
16
23
  /**
17
24
  * Convert IPA notation to Korean Hangul pronunciation
package/dist/index.js CHANGED
@@ -262,7 +262,7 @@ function preprocessIPA(ipa) {
262
262
  function hasIPAVowel(text) {
263
263
  return /[iɪeɛæɑɒɔʌəɜɝʊuoa]/.test(text);
264
264
  }
265
- function getTrailingConsonants(text) {
265
+ function getTrailingConsonants(text, preferOnset = false) {
266
266
  let i = text.length;
267
267
  while (i > 0) {
268
268
  if (i >= 2) {
@@ -284,6 +284,12 @@ function getTrailingConsonants(text) {
284
284
  if (!allTrailing) {
285
285
  return { before: text, trailing: "" };
286
286
  }
287
+ if (preferOnset) {
288
+ return {
289
+ before: beforeConsonants,
290
+ trailing: allTrailing
291
+ };
292
+ }
287
293
  let keepUntil = 0;
288
294
  if (allTrailing.length >= 2) {
289
295
  const twoChar = allTrailing.substring(0, 2);
@@ -305,7 +311,7 @@ function getTrailingConsonants(text) {
305
311
  function startsWithVowel(text) {
306
312
  return matchVowel(text, 0) !== null;
307
313
  }
308
- function parseSyllables(text) {
314
+ function parseSyllables(text, preferOnset = true) {
309
315
  const syllables = [];
310
316
  const parts = text.split(".");
311
317
  for (const part of parts) {
@@ -332,7 +338,7 @@ function parseSyllables(text) {
332
338
  const curr = merged[i];
333
339
  const next = merged[i + 1];
334
340
  if (startsWithVowel(next.text)) {
335
- const { before, trailing } = getTrailingConsonants(curr.text);
341
+ const { before, trailing } = getTrailingConsonants(curr.text, preferOnset);
336
342
  if (trailing && before) {
337
343
  curr.text = before;
338
344
  next.text = trailing + next.text;
@@ -512,9 +518,10 @@ function applyStressMarker(hangul, stress, format) {
512
518
  }
513
519
  function ipaToHangul(ipa, options) {
514
520
  if (!ipa) return "";
521
+ const preferOnset = options?.preferOnset !== false;
515
522
  const cleaned = preprocessIPA(ipa);
516
523
  if (!cleaned) return "";
517
- const syllables = parseSyllables(cleaned);
524
+ const syllables = parseSyllables(cleaned, preferOnset);
518
525
  const results = [];
519
526
  for (const syllable of syllables) {
520
527
  const segments = splitByLongVowel(syllable.text);
package/dist/index.mjs CHANGED
@@ -238,7 +238,7 @@ function preprocessIPA(ipa) {
238
238
  function hasIPAVowel(text) {
239
239
  return /[iɪeɛæɑɒɔʌəɜɝʊuoa]/.test(text);
240
240
  }
241
- function getTrailingConsonants(text) {
241
+ function getTrailingConsonants(text, preferOnset = false) {
242
242
  let i = text.length;
243
243
  while (i > 0) {
244
244
  if (i >= 2) {
@@ -260,6 +260,12 @@ function getTrailingConsonants(text) {
260
260
  if (!allTrailing) {
261
261
  return { before: text, trailing: "" };
262
262
  }
263
+ if (preferOnset) {
264
+ return {
265
+ before: beforeConsonants,
266
+ trailing: allTrailing
267
+ };
268
+ }
263
269
  let keepUntil = 0;
264
270
  if (allTrailing.length >= 2) {
265
271
  const twoChar = allTrailing.substring(0, 2);
@@ -281,7 +287,7 @@ function getTrailingConsonants(text) {
281
287
  function startsWithVowel(text) {
282
288
  return matchVowel(text, 0) !== null;
283
289
  }
284
- function parseSyllables(text) {
290
+ function parseSyllables(text, preferOnset = true) {
285
291
  const syllables = [];
286
292
  const parts = text.split(".");
287
293
  for (const part of parts) {
@@ -308,7 +314,7 @@ function parseSyllables(text) {
308
314
  const curr = merged[i];
309
315
  const next = merged[i + 1];
310
316
  if (startsWithVowel(next.text)) {
311
- const { before, trailing } = getTrailingConsonants(curr.text);
317
+ const { before, trailing } = getTrailingConsonants(curr.text, preferOnset);
312
318
  if (trailing && before) {
313
319
  curr.text = before;
314
320
  next.text = trailing + next.text;
@@ -488,9 +494,10 @@ function applyStressMarker(hangul, stress, format) {
488
494
  }
489
495
  function ipaToHangul(ipa, options) {
490
496
  if (!ipa) return "";
497
+ const preferOnset = options?.preferOnset !== false;
491
498
  const cleaned = preprocessIPA(ipa);
492
499
  if (!cleaned) return "";
493
- const syllables = parseSyllables(cleaned);
500
+ const syllables = parseSyllables(cleaned, preferOnset);
494
501
  const results = [];
495
502
  for (const syllable of syllables) {
496
503
  const segments = splitByLongVowel(syllable.text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ipa-hangul",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "Convert IPA (International Phonetic Alphabet) pronunciation to Korean Hangul",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",