1.0.9 • Published 6 months ago

kana-convert v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

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

1.0.9

6 months ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago