kana-convert
v1.0.9
Published
A utility library for converting from [Kana](https://en.wikipedia.org/wiki/Kana) to [Rōmaji](https://en.wikipedia.org/wiki/Romanization_of_Japanese)
Downloads
3
Readme
kana-convert
A utility library for converting from Kana to Rōmaji
Punctuation are allowed and any Japanese punctuation will be converted to their Roman alphabet equivalent.
Examples
const { romanize } = require('../src/romanize');
romanize('かきくけこ')
// {
// status: 'SUCCESS',
// result: 'kakikukeko',
// }
romanize('hello')
// {
// status: 'ERROR',
// result: 'Error at h',
// }
Romanization config options
By default non-kana characters are not allowed, but nonKanaAllowed: true
turns this off:
romanize('a) か b) き c) く', { nonKanaAllowed: false })
// {
// status: 'ERROR',
// result: 'Error at a',
// }
romanize('a) か b) き c) く', { nonKanaAllowed: true })
// {
// status: 'SUCCESS',
// result: 'a) ka b) ki c) ku',
// }
By default long vowels will be romanized by doubling vowels up corresponding
exactly to the original kana, this can be turned off with mergeLongVowels:
true
. However, it is not always possible to distinguish between a long vowel
and two separate short vowels in kana, so this will not always be perfect. For
example, the kana "おう" could be rendered either as "ou" (as in 王) or as "ō"
(as in 追う). Determining the correct romanization in such cases therefore
requires more information than is actually encoded by the kana. If this option
is turned on, all such sequences will be interpreted as long vowels.
romanize('がっこう', { mergeLongVowels: false })
// {
// status: 'SUCCESS',
// result: 'gakkou',
// }
romanize('がっこう', { mergeLongVowels: true })
// {
// status: 'SUCCESS',
// result: 'gakkō',
// }
By default, s + i/y, t + i/y and h + u are romanized as 'si', 'ti', 'sya',
'tya', 'hu', etc.
This is more accurate to the phonology of Japanese. Some romanization systems
anglicize these sounds to 'shi', 'chi', 'sha', 'cha', 'fu', etc., aligning them
more closely with English phonology. This can be turned on with anglphone: true
.
romanize('かいしゃ', { anglophone: false })
// {
// status: 'SUCCESS',
// result: 'kaisya',
// }
romanize('かいしゃ', { anglophone: true })
// {
// status: 'SUCCESS',
// result: 'kaisha',
// }
Multiple config options can be enabled at once, for example:
romanize('A: しょうがっこう', {
mergeLongVowels: true,
anglophone: true,
nonKanaAllowed: true,
})
// {
// status: 'SUCCESS',
// result: 'A: shōgakkō',
// }
Installation
yarn
or npm install
(requires node
and npm
or yarn
)
Tests
yarn test
or npm run test
Linting
yarn lint
or npm run lint