Methods
bind(input, optionsopt)
Binds eventListener for 'input' events to an input field to automagically replace values with kana
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
HTMLElement | textarea, input[type="text"] etc |
||
options |
DefaultOptions |
<optional> |
defaultOptions
|
user config overrides |
isHiragana(inputopt) → {Boolean}
- Source:
Test if input
is Hiragana
Example
isHiragana('げーむ')
// => true
isHiragana('A')
// => false
isHiragana('あア')
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
Returns:
true if all Hiragana
- Type
- Boolean
isJapanese(inputopt) → {Boolean}
- Source:
Example
isJapanese('泣き虫')
// => true
isJapanese('あア')
// => true
isJapanese('泣き虫。!〜') // Full-width punctuation
// => true
isJapanese('泣き虫.!~') // Half-width / Latin punctuation
// => false
isJapanese('泣き虫A')
// => false
isJapanese('A')
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
Returns:
- Type
- Boolean
isKana(inputopt) → {Boolean}
Example
isKana('あ')
// => true
isKana('ア')
// => true
isKana('あーア')
// => true
isKana('A')
// => false
isKana('あAア')
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
Returns:
true if all Kana
- Type
- Boolean
isKanji(inputopt) → {Boolean}
- Source:
Tests if input
is Kanji (Japanese CJK ideographs)
Example
isKanji('刀')
// => true
isKanji('切腹')
// => true
isKanji('勢い')
// => false
isKanji('あAア')
// => false
isKanji('🐸')
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
Returns:
true if all Kanji
- Type
- Boolean
isKatakana(inputopt) → {Boolean}
- Source:
Test if input
is Katakana
Example
isKatakana('ゲーム')
// => true
isKatakana('あ')
// => false
isKatakana('A')
// => false
isKatakana('あア')
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
Returns:
true if all Katakana
- Type
- Boolean
isMixed(input, optionsopt) → {Boolean}
- Source:
Example
isMixed('Abあア'))
// => true
isMixed('お腹A'))
// => true
isMixed('お腹A', { passKanji: false }))
// => false
isMixed('ab'))
// => false
isMixed('あア'))
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String | text |
||
options |
Object |
<optional> |
{ passKanji: true }
|
optional config to skip over kanji |
Returns:
true if mixed
- Type
- Boolean
isRomaji(inputopt) → {Boolean}
- Source:
Test if input
is Romaji (allowing Hepburn romanisation)
Example
isRomaji('Tōkyō and Ōsaka')
// => true
isRomaji('a*b&c-d')
// => true
isRomaji('あアA')
// => false
isRomaji('お願い')
// => false
isRomaji('a!b&cーd') // Full-width punctuation fails
// => false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
Returns:
true if Romaji
- Type
- Boolean
stripOkurigana(input, optionsopt) → {String}
- Source:
Example
stripOkurigana('踏み込む')
// => '踏み込'
stripOkurigana('粘り。')
// => '粘。'
stripOkurigana('お祝い')
// => 'お祝'
stripOkurigana('踏み込む', { all: true })
// => '踏込'
stripOkurigana('お祝い', { all: true })
// => '祝'
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String | text |
||
options |
Object |
<optional> |
{ all: false }
|
config object specifying if all kana should be removed, not just trailing okurigana |
Returns:
text with okurigana removed
- Type
- String
toHiragana(inputopt, optionsopt) → {String}
- Source:
Convert input to Hiragana
Example
toHiragana('toukyou, オオサカ')
// => 'とうきょう、 おおさか'
toHiragana('only カナ', { passRomaji: true })
// => 'only かな'
toHiragana('wi')
// => 'うぃ'
toHiragana('wi', { useObsoleteKana: true })
// => 'ゐ'
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
options |
DefaultOptions |
<optional> |
defaultOptions
|
Returns:
converted text
- Type
- String
toKana(inputopt, optionsopt) → {String}
Convert Romaji to Kana, lowercase text will result in Hiragana and uppercase text will result in Katakana.
Example
toKana('onaji BUTTSUUJI')
// => 'おなじ ブッツウジ'
toKana('ONAJI buttsuuji')
// => 'オナジ ぶっつうじ'
toKana('座禅‘zazen’スタイル')
// => '座禅「ざぜん」スタイル'
toKana('batsuge-mu')
// => 'ばつげーむ'
toKana('!?.:/,~-‘’“”[](){}') // Punctuation conversion
// => '!?。:・、〜ー「」『』[](){}'
toKana('we', { useObsoleteKana: true })
// => 'ゑ'
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
options |
DefaultOptions |
<optional> |
defaultOptions
|
Returns:
converted text
- Type
- String
toKatakana(inputopt, optionsopt) → {String}
- Source:
Convert input to Katakana
Example
toKatakana('toukyou, おおさか')
// => 'トウキョウ、 オオサカ'
toKatakana('only かな', { passRomaji: true })
// => 'only カナ'
toKatakana('wi')
// => 'うぃ'
toKatakana('wi', { useObsoleteKana: true })
// => 'ヰ'
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String |
<optional> |
''
|
text |
options |
DefaultOptions |
<optional> |
defaultOptions
|
Returns:
converted text
- Type
- String
toRomaji(kana, optionsopt) → {String}
- Source:
Convert kana to romaji
Example
toRomaji('ひらがな カタカナ')
// => "hiragana katakana"
toRomaji('ひらがな カタカナ', { upcaseKatakana: true })
// => "hiragana KATAKANA"
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
kana |
String | text input |
||
options |
DefaultOptions |
<optional> |
defaultOptions
|
Returns:
converted text
- Type
- String
tokenize(input) → {Array}
- Source:
Splits input into array of Kanji, Hiragana, Katakana, and Romaji tokens.
Does not split into parts of speech!
Example
tokenize('ふふフフ')
// => ['ふふ', 'フフ']
tokenize('感じ')
// => ['感', 'じ']
tokenize('私は悲しい')
// => ['私', 'は', '悲', 'しい']
tokenize('what the...私は「悲しい」。')
// => ['what the...', '私', 'は', '「', '悲', 'しい', '」。']
Parameters:
Name | Type | Description |
---|---|---|
input |
String | text |
Returns:
text split into tokens
- Type
- Array
unbind(input)
Unbinds eventListener from input field
Parameters:
Name | Type | Description |
---|---|---|
input |
HTMLElement | textarea, input[type="text"] etc |
Type Definitions
DefaultOptions
- Source:
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
useObsoleteKana |
Boolean |
<optional> |
false
|
Set to true to use obsolete characters, such as ゐ and ゑ. |
passRomaji |
Boolean |
<optional> |
false
|
Set to true to pass romaji when using mixed syllabaries with toKatakana() or toHiragana() |
upcaseKatakana |
Boolean |
<optional> |
false
|
Set to true to convert katakana to uppercase using toRomaji() |
IMEMode |
Boolean |
<optional> |
false
|
Set to true to handle conversion from a text input as it is being typed |
Type:
- Object
Examples
toHiragana('we', { useObsoleteKana: true })
// => 'ゑ'
toHiragana('only convert the katakana: ヒラガナ', { passRomaji: true })
// => "only convert the katakana: ひらがな"
toRomaji('ひらがな カタカナ', { upcaseKatakana: true })
// => "hiragana KATAKANA"