es-hangul

repository·main·Indexed 23 days ago

https://github.com/toss/es-hangul

A modern TypeScript JavaScript library for Hangul (Korean) manipulation. It provides high-performance utilities for character composition and decomposition, including functions to extract initial consonants (getChoseong), attach grammatically correct particles (josa), and disassemble/assemble characters into their constituent Jamo components.

Tokens
18.7K
Snippets
69
Records
112
Agent score
80%

What's inside es-hangul

  1. Introduction to es-hangul

    main

    es-hangul is a high-performance library designed for handling Hangul (Korean alphabet) in JavaScript applications. It provides interfaces for common business requirements such as initial consonant (Choseong) search, automatic particle (Josa) attachment, and decomposing/assembling Hangul characters into their constituent parts (Choseong, Jungseong, Jongseong).

    Key features include:

    • Tree-shakable: Built with ECMAScript Modules, allowing you to include only the functions you use.
    • TypeScript Support: Provides strong typing for better developer experience.
    • High Performance: Optimized for complex Hangul assembly and disassembly tasks.
  2. Overview of es-hangul

    main
    es-hangul is a modern JavaScript library designed to make handling Hangul (Korean script) easy. It provides a convenient API and uses ECMAScript Modules (ESM), allowing developers to minimize the amount of code sent to the browser.
  3. Performance advantages of es-hangul

    main
    The es-hangul library is optimized for high-performance Hangul processing, specifically for complex tasks such as Hangul composition (combining characters) and decomposition (splitting characters into Jamo). Benchmark tests indicate that es-hangul provides significantly faster performance compared to alternative libraries for these operations.
  4. Understand exception cases in pronunciation standardization

    main

    Standardizing pronunciation relies on linguistic rules (like the 'Addition of Sounds' rule in Korean Orthography). However, determining if a word is a compound or derivative word is difficult using only code without external linguistic data.

    Because of this, es-hangul manages certain linguistic exceptions (where a rule might suggest one pronunciation, but the actual standard is different) using a separate constant list.

    Example of an exception:

    • According to the 'Addition of Sounds' rule, 전역 (jeon-yeok) might be expected to be pronounced as 전녁 (jeon-nyeok).
    • However, since 전역 is not a compound or derivative, it is exceptionally pronounced as 저녁 (jeo-nyeok).

    If you encounter words that require exception handling, the project encourages community contributions.

  5. Benefit from TypeScript type support in es-hangul

    main

    Unlike many existing Hangul processing libraries, es-hangul is written in TypeScript. This provides several advantages for developers:

    • Type Safety: Enhances code safety and maintainability by preventing errors during development.
    • Improved Readability: Function input and output types are clearly defined.
    • Developer Efficiency: Full support for IDE auto-completion features, making it easier to discover and use available functions.
  6. Benefit from strong TypeScript support in es-hangul

    main

    Unlike many legacy Hangul processing libraries, es-hangul is written entirely in TypeScript. This provides several advantages for developers:

    • Type Safety: Prevents common errors during development by ensuring inputs and outputs match expected types.
    • Improved Maintainability: Clearer code structure through explicitly defined function signatures.
    • Enhanced Developer Experience: Full IDE autocomplete support for all functions and parameters, making it easier to discover and use the API without constant documentation lookups.
    • Predictable Outputs: Explicitly defined return types ensure you know exactly what kind of Hangul transformation result to expect.
  7. Replace removed `curriedCombineHangulCharacter` in v2

    main

    The curriedCombineHangulCharacter function was removed as it was not intended for direct user use. If you require this pattern, you can implement it manually using combineCharacter:

    export const curriedCombineHangulCharacter=
      (firstCharacter: string) =>
      (middleCharacter: string) =>
      (lastCharacter = '') =>
        combineCharacter(firstCharacter, middleCharacter, lastCharacter);
  8. Replace removed `choseongIncludes` and `chosungIncludes` in v2

    main

    The choseongIncludes and chosungIncludes functions have been removed. To check if a string contains specific initial consonants (choseong), use getChoseong to extract them and then use the standard JavaScript .includes() method.

    // ASIS
    chosungIncludes('바나나', 'ㅂㄴㄴ');
    choseongIncludes('바나나', 'ㅂㄴㄴ');
    
    // TOBE
    const choseonged = getChoseong('바나나');
    choseonged.includes('ㅂㄴㄴ');
  9. Migrate from `chosungIncludes` and `choseongIncludes`

    main

    The functions choseongIncludes and chosungIncludes have been removed. To check if a string contains specific initial consonants (choseong), use getChoseong to transform the string first, then use the standard JavaScript .includes() method.

    // Replacement pattern
    const choseonged = getChoseong('바나나');
    choseonged.includes('ㅂㄴㄴ');
  10. Migrate renamed Hangul functions in v2

    main

    As part of a naming convention update in v2, the Hangul suffix has been removed from several function names. Use the following mappings to update your code:

    Old Name (v1)New Name (v2)
    assembleHangulassemble
    combineHangulCharactercombineCharacter
    convertQwertyToHangulAlphabetconvertQwertyToAlphabet
    disassembleHanguldisassemble
    disassembleHangulToGroupsdisassembleToGroups
    disassembleCompleteHangulCharacterdisassembleCompleteCharacter
    removeLastHangulCharacterremoveLastCharacter
    // ASIS
    assembleHangul('ㄱ', 'ㅏ', 'ㅁ')
    // TOBE
    assemble('ㄱ', 'ㅏ', 'ㅁ')
    
    // ASIS
    combineHangulCharacter('ㄱ', 'ㅏ', 'ㅁ')
    // TOBE
    combineCharacter('ㄱ', 'ㅏ', 'ㅁ')
    
    // ASIS
    convertQwertyToHangulAlphabet('r')
    // TOBE
    convertQwertyToAlphabet('r')
    
    // ASIS
    disassembleHangul('감');
    // TOBE
    disassemble('감');
    
    // ASIS
    removeLastHangulCharacter('감');
    // TOBE
    removeLastCharacter('감');