JSPM

jap-js

1.4.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q17096F

    A collection of useful utility functions for Japanese text

    Package Exports

    • jap-js
    • jap-js/dist/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jap-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    JapJS

    JapJS is a Javascript utility library for Japanese text converting, detecting and more.

    Installation

    npm install jap-js
    yarn add jap-js

    Usage

    import japJS from 'jap-js';
    // or
    import { isHiragana, hasKanji } from 'jap-js';

    API

    toHiragana

    Take a string and return a string converted from katakana to hiragana

    japJS.toHiragana("カ");
    // か
    
    japJS.toHiragana("hello カ 火");
    // hello か 火

    toKatakana

    Take a string and return a string converted from hiragana to katakana

    japJS.toKatakana("か");
    // カ
    
    japJS.toKatakana("hello か 火");
    // hello カ 火

    kanjiDetails

    Takes one or more kanji and returns all the details of it

    japJS.kanjiDetails("火") 
    // { character: '火', freq: '574', grade: 1, jlpt: 5, stroke: 4...}
    
    japJS.kanjiDetails("火", "jlpt") 
    // 5
    
    japJS.kanjiDetails(["火", "家"], { jlpt: true, grade: true })
    // [ { jlpt: 5, grade: 2 }, { jlpt: 4, grade: 2 } ]

    isHiragana

    Takes a string and return true if the string is a hiragana

    japJS.isHiragana("あう"); // true
    japJS.isHiragana("火"); // false

    isKatakana

    Takes a string and return true if the string is a katakana

    japJS.isKatakana("アイウ"); // true
    japJS.isKatakana("あ火"); // false

    isKana

    Takes a string and return true if the string is a kana

    japJS.isKana("アあ"); // true
    japJS.isKana("あア漢字"); // false

    isKanji

    Takes a string and return true if the string is a kanji

    japJS.isKanji("火漢字"); // true
    japJS.isKanji("ア"); // false

    isJapanese

    Takes a string and return true if the string is a japanese

    japJS.isJapanese("あイ漢字"); // true
    japJS.isJapanese("hello"); // false

    isJoyoKanji

    Takes a string and return true if every character of the string is a kanji on a list of 2,136 common characters : wiki

    japJS.isJoyoKanji("漢字"); // true
    japJS.isJoyoKanji("鮭"); // false

    isKanjiNumber

    Takes a string and return true if the string is a kanji number

    japJS.isKanjiNumber("一五七"); // true
    japJS.isKanjiNumber("三あ"); // false
    japJS.isKanjiNumber(123); // false

    hasHiragana

    Takes a string and return true if the string contains a hiragana

    japJS.hasHiragana("あ"); // true
    japJS.hasHiragana("ア"); // false

    hasKatakana

    Takes a string and return true if the string contains a katakana

    japJS.hasKatakana("ア"); // true
    japJS.hasKatakana("あ"); // false

    hasKana

    Takes a string and return true if the string contains a kana

    japJS.hasKana("私はアルノです"); // true
    japJS.hasKana("字"); // false

    hasKanji

    Takes a string and return true if the string contains a kanji

    japJS.hasKanji("私は猫です"); // true
    japJS.hasKanji("アあ"); // false

    hasKanjiNumber

    Takes a string and return true if the string contains a kanji number

    japJS.hasKanjiNumber("あhello五"); // true
    japJS.hasKanjiNumber("あhello"); // false

    hasJapanese

    Takes a string and return true if the string contains japanese

    japJS.hasJapanese("字hello"); // true
    japJS.hasJapanese("hello"); // false

    hasJoyoKanji

    Takes a string and return true if the string contains kanji on a list of 2,136 common characters : wiki

    japJS.hasJoyoKanji("鮭漢字"); // true
    japJS.hasJoyoKanji("鮭"); // false

    toHalfWidth

    Take a string and return a string converted from Full Width to Half Width : wiki

    japJS.toHalfWidth("hello");
    // hello
    
    japJS.toHalfWidth("i am half width string");
    // i am half width string

    toFullWidth

    Take a string and return a string converted from Half Width to Full Width : wiki

    japJS.toFullWidth("hello");
    // hello
    
    japJS.toFullWidth("i am half width string");
    // i am half width string