jamomatic
v0.3.0
Published
A library dedicated to working with the Korean alphabet, Hangul.
Maintainers
Readme
Jamomatic
A library dedicated to working with the Korean alphabet, Hangul.
⚠️ This library is still under development and breaking changes may be many until a v1.0.0 version is released. Use with caution.
🥲 Unfortunately, after many attempts, the package name
hangul, despite being squatted on, is not being released by NPM. This project is now namedjamomatic.
Installation
npm install jamomaticUsage
This package comes with many useful functions, and more to come!
- endsWith
- getFinal
- getInitial
- getMedial
- isAspirated
- isCompatibility
- isCompositeConsonant
- isCompositeVowel
- isConsonant
- isConsonantCluster
- isDiphthong
- isDoubleConsonant
- isFinal
- isFortis
- isHangul
- isInitial
- isIotized
- isLenis
- isMedial
- isNonCompatibility
- isSyllable
- isVowel
- join
- split
- startsWith
- toAspirated
- toCompatibility
- toDouble
- toFinal
- toFortis
- toInitial
- toIotized
- toLenis
- toMedial
- toSingle
endsWith 🔝
Checks if the given search string exists at the end of the given operation string.
Signature
function endsWith(
str: string,
options?: {
decouple: boolean
}
): booleanOptions
| Name | Default Value | Description | | -------- | ------------- | ------------------------------------------------------------ | | decouple | true | Decouples the composite letters before performing the search |
Example
endsWith("한글", "글") // true
endsWith("한글", "ㅡㄹ") // true
endsWith("한글", "한") // false
endsWith("늙다", "ㄱ다") // true
endsWith("늙다", "ㄱ다", { decouple: false }) // falsegetFinal 🔝
Extracts the final letter from the given Hangul syllable block.
Signature
function getFinal(
str: string,
options?: {
compatibility: boolean
}
): stringOptions
| Name | Default Value | Description | | ------------- | ------------- | ----------------------------------------------------- | | compatibility | true | Converts the final letter into its compatibility form |
Example
getFinal("한") // "ㄴ"
getFinal("한", { compatibility: false }) // "ᆫ"
getFinal("하") // ""getInitial 🔝
Extracts the initial letter from the given Hangul syllable block.
Signature
function getInitial(
str: string,
options?: {
compatibility: boolean
}
): stringOptions
| Name | Default Value | Description | | ------------- | ------------- | ------------------------------------------------------- | | compatibility | true | Converts the initial letter into its compatibility form |
Example
getInitial("한") // "ㅎ"
getInitial("한", { compatibility: false }) // "ᄒ"getMedial 🔝
Extracts the medial letter from the given Hangul syllable block.
Signature
function getMedial(
str: string,
options?: {
compatibility: boolean
}
): stringOptions
| Name | Default Value | Description | | ------------- | ------------- | ------------------------------------------------------ | | compatibility | true | Converts the medial letter into its compatibility form |
Example
getMedial("한") // "ㅏ"
getMedial("한", { compatibility: false }) // "ᅡ"isAspirated 🔝
Checks if the given value is an aspirated consonant.
Signature
function isAspirated(value: unknown): booleanExample
isAspirated("ㅋ") // true
isAspirated("ㄱ") // falseisCompatibility 🔝
Checks if the given value is a compatibility letter.
Signature
function isCompatibility(value: unknown): booleanExample
isCompatibility("ㄱ") // true
isCompatibility("ᄀ") // falseisCompositeConsonant 🔝
Checks if the given value is a consonant cluster, a cluster of two consonants as one letter.
Signature
function isCompositeConsonant(value: unknown): booleanExample
isCompositeConsonant("ㄳ") // true
isCompositeConsonant("ㄱ") // falseisCompositeVowel 🔝
➡️ isDiphthong
Checks if the given value is a diphthong, a cluster of two vowels as one letter.
Signature
function isCompositeVowel(value: unknown): booleanExample
isCompositeVowel("ㅘ") // true
isCompositeVowel("ㅏ") // falseisConsonant 🔝
Checks if the given value is consonant.
Signature
function isConsonant(value: unknown): booleanExample
isConsonant("ㄱ") // true
isConsonant("ㅏ") // falseisConsonantCluster 🔝
Checks if the given value is a consonant cluster, a cluster of two consonants as one letter.
Signature
function isConsonantCluster(value: unknown): booleanExample
isConsonantCluster("ㄳ") // true
isConsonantCluster("ㄱ") // falseisDiphthong 🔝
Checks if the given value is a diphthong, a cluster of two vowels as one letter.
Signature
function isDiphthong(value: unknown): booleanExample
isDiphthong("ㅘ") // true
isDiphthong("ㅏ") // falseisDoubleConsonant 🔝
Checks if the given value is a double consonant, a cluster of two identical consonants as one letter.
Signature
function isDoubleConsonant(value: unknown): booleanExample
isDoubleConsonant("ㄲ") // true
isDoubleConsonant("ㄳ") // falseisFinal 🔝
Checks if the given value is a non-compatibility, final consonant.
Signature
function isFinal(value: unknown): booleanExample
isFinal("ᆨ") // true
isFinal("ㄱ") // falseisFortis 🔝
Checks if the given value is a fortis (tensed) consonant.
Signature
function isFortis(value: unknown): booleanExample
isFortis("ㄲ") // true
isFortis("ㄱ") // falseisHangul 🔝
Checks if the given value is some sort of Hangul characters, either a loose letter or a syllable block. By default, symbols and numbers are allowed to pass. Use the options.strict boolean to disallow this behavior.
Signature
function isHangul(
value: unknown,
options?: {
strict: boolean
}
): booleanOptions
| Name | Default Value | Description | | ------ | ------------- | --------------------------------------------------------------------------- | | strict | false | Disallows symbols and numbers from being considered valid Hangul characters |
Example
isHangul("안녕하세요!") // true
isHangul("안녕하세요!", { strict: true }) // falseisInitial 🔝
Checks if the given value is a non-compatibility, initial consonant.
Signature
function isInitial(value: unknown): booleanExample
isInitial("ᄀ") // true
isInitial("ㄱ") // falseisIotized 🔝
Checks if the given value is an iotized vowel, one that begins with the /j/ phoneme.
Signature
function isIotized(value: unknown): booleanExample
isIotized("ㅑ") // true
isIotized("ㅏ") // falseisLenis 🔝
Checks if the given value is a lenis (soft) consonant.
Signature
function isLenis(value: unknown): booleanExample
isLenis("ㄱ") // true
isLenis("ㄲ") // falseisMedial 🔝
Checks if the given value is a non-compatibility, medial vowel.
Signature
function isMedial(value: unknown): booleanExample
isMedial("ᅡ") // true
isMedial("ㅏ") // falseisNonCompatibility 🔝
Checks if the given value is a non-compatibility letter.
Signature
function isNonCompatibility(value: unknown): booleanExample
isNonCompatibility("ᅡ") // true
isNonCompatibility("ㅏ") // falseisSyllable 🔝
Checks if the given value is a Hangul syllable block.
Signature
function isSyllable(value: unknown): booleanExample
isSyllable("한") // true
isSyllable("ㅎ") // falseisVowel 🔝
Checks if the given value is a vowel.
Signature
function isVowelExample
isVowel("ㅏ") // true
isVowel("ㄱ") // falsejoin 🔝
Joins the given string in a way that would resemble dubeolsik (두벌식) typing. Converts all non-compatibility letters to compatibility letters during this process.
options.split is an important consideration as it could drastically change the output. When true, this function will deconstruct all valid syllable blocks, then evaluate each individual letter as if they were typed separately. When false, however, each syllable block will be parsed as-is. See the examples for an illustration of what this actually looks like.
Signature
function join(
str: string,
options?: {
split: boolean
}
): stringOptions
| Name | Default Value | Description | | ----- | ------------- | -------------------------------- | | split | true | Splits the string before parsing |
Example
join("ㅎㅏㄴ") // 한
join("ㄱ가") // 까
join("ㄱ가", { split: false }) // ㄱ가split 🔝
Splits the given string, deconstructing all of the hangul syllables into their constituent letters.
Signature
function split(
str: string,
options?: {
group: boolean
decouple: boolean
compatibility: boolean
}
): string[] | string[][]Options
| Name | Default Value | Description | | ------------- | ------------- | ---------------------------------------------------------------------------- | | group | false | Groups each syllable/grapheme into its own array | | decouple | false | Decomposes composite letters into their constituent letters | | compatibility | true | Converts all letters from non-compatibility letters to compatibility letters |
Example
split("하다") // ["ㅎ", "ㅏ", "ㄷ", "ㅏ"]
split("했다") // ["ㅎ", "ㅐ", "ㅆ", "ㄷ", "ㅏ"]
split("했다", { decouple: true, compatibility: false }) // ["ᄒ", "ᅢ", "ᆺ", "ᆺ", "ᄃ", "ᅡ"]startsWith 🔝
Checks if the given search string exists at the beginning of the given operation string.
Signature
function startsWith(
str: string,
options?: {
decouple: boolean
}
): booleanOptions
| Name | Default Value | Description | | -------- | ------------- | ------------------------------------------------------------ | | decouple | true | Decouples the composite letters before performing the search |
Example
startsWith("한글", "한") // true
startsWith("한글", "ㅎㅏ") // true
startsWith("한글", "글") // false
startsWith("늙다", "늘") // true
startsWith("늙다", "늘", { decouple: false }) // falsetoAspirated 🔝
Converts all consonants into their aspirated form.
Signature
function toAspirated(str: string): stringExample
toAspirated("ㄱ") // "ㅋ"
toAspirated("ㄲ") // "ㅋ"
toAspirated("한국") // "한쿸"toCompatibility 🔝
Converts all letters into their compatibility form.
Signature
function toCompatibility(str: string): stringExample
toCompatibility("ᆨ") // "ㄱ"
toCompatibility("ᆩ") // "ㄲ"toDouble 🔝
Converts all consonants into their double consonant form.
Signature
function toDouble(str: string): stringExample
toDouble("ㄱ") // "ㄱ"
toDouble("ㄲ") // "ㄱ"
toDouble("가") // "까"toFinal 🔝
Converts all consonants into their final form.
Signature
function toFinal(str: string): stringExample
toFinal("ㄱ") // "ᆨ"
toFinal("ㄲ") // "ᆩ"toFortis 🔝
Converts all consonants into their fortis (tensed) form.
Signature
function toFortis(str: string): stringExample
toFortis("ㄱ") // "ㄲ"
toFortis("ㄲ") // "ㄲ"
toFortis("한국") // "한꾺"toInitial 🔝
Converts all consonants into their initial form.
Signature
function toInitial(str: string): stringExample
toInitial("ㄱ") // "ᄀ"
toInitial("ㄲ") // "ᄁ"toIotized 🔝
Converts all vowels that can be iotized within the given string.
Signature
function toIotized(str: string): stringExample
toIotized("ㅏ") // "ㅑ"
toIotized("한국") // "햔귝"toLenis 🔝
Converts all consonants into their lenis (soft) form.
Signature
function toLenis(str: string): stringExample
toLenis("ㄱ") // "ㅋ"
toLenis("ㄲ") // "ㅋ"
toLenis("한국") // "한쿸"toMedial 🔝
Converts all vowels into their medial form.
Signature
function toMedial(str: string): stringExample
toMedial("ㅏ") // "ᅡ"
toMedial("ㅔ") // "ᅦ"toSingle 🔝
Converts all consonants into their single consonant form.
Signature
function toSingle(str: string): stringExample
toSingle("ㄱ") // "ㄱ"
toSingle("ㄲ") // "ㄱ"
toSingle("까") // "가"©️ 2024 Jacob Lockett
