How to use the wanakana.toKatakana function in wanakana

To help you get started, we’ve selected a few wanakana examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kaniwani / kw-frontend / app / common / utils / splitSentenceByMatch.js View on Github external
.sort((a, b) => b.length - a.length)
    );
  } else if (adjType) {
    matchers.push(
      ...inflectAdjective(base, adjType)
        .map(({ form }) => form)
        .sort((a, b) => b.length - a.length)
    );
    // basic stem matching fallback if no verbType or adjType provided
  } else if (reading) {
    // 'づけ' => 'づ' via 漬け
    matchers.push(stripOkurigana(base, { matchKanji: word }));
    // 'おかね' => 'かね' via お金
    matchers.push(stripOkurigana(base, { matchKanji: word, leading: true }));
    // 'つけ' => 'ツケ'
    matchers.push(toKatakana(base));
  } else {
    matchers.push(stripOkurigana(base)); // '飛び込む' => '飛び込'
    matchers.push(stripOkurigana(base, { leading: true })); // 'お金' => '金'
  }

  return [...new Set(matchers)];
}
github Kaniwani / kw-frontend / app / utils / splitSentenceByMatch.js View on Github external
let onlyChars;
  let cleanKana;
  let cleanKata;
  let strippedKana;

  if (hasChars) {
    cleanChars = stripTilde(word); // '〜漬け' => '漬け'
    strippedChars = stripOkurigana(cleanChars); // '飛び込む' => '飛び込'
    onlyChars = stripOkurigana(cleanChars, { all: true }); // '売り上げ' => '売上'
  }

  const charRegex = hasChars ? joinPipe([cleanChars, strippedChars, onlyChars]) : '';

  if (hasKana) {
    cleanKana = stripTilde(reading); // '〜つけ' => 'つけ'
    cleanKata = toKatakana(cleanKana); // '〜つけ' => 'ツケ'
    strippedKana = stripKana(cleanKana); // '〜つけ' => 'つ'
  }

  const kanaRegex = hasKana ? `${joinPipe([cleanKana, cleanKata, strippedKana])}` : '';

  // '売り上げ' => /(.*?)(売り上げ|売り上|売上|うりあげ|ウリアゲ|うりあ)(.*)/
  const regex = new RegExp(`(.*?)(${charRegex}${hasChars && hasKana ? '|' : ''}${kanaRegex})(.*)`);

  const failSafe = ['', sentence, '', ''];

  const [, head, match, tail] = sentence.match(regex) || failSafe;

  return {
    head,
    match,
    tail,
github hexenq / kuroshiro / dist / node / kuroshiro.js View on Github external
switch (options.to){
            case 'katakana':
                if(options.mode === 'okurigana'){
                    for(var n0=0;n0" + options.delimiter_start + "<rt>" + wanakana.toKatakana(notations[n1][2]) + "</rt><rp>" + options.delimiter_end + "</rp>";
                        }
                    }
                }
                return result;
            case 'romaji':
                if(options.mode === 'okurigana')
                    for(var n2=0;n2
github nkjm / bot-express / module / parser / string.js View on Github external
}

        if (policy.max){
            if (value.length > policy.max){
                throw new Error("be_parser__too_long")
            }
        }

        if (policy.sanitize){
            value = sanitize(value);
        }

        if (policy.character){
            if (policy.character === "katakana"){
                if (wanakana.isKana(value.replace(/(\s| )/g, ""))){
                    value = wanakana.toKatakana(value)
                } else {
                    throw new Error("be_parser__should_be_katakana")
                }
            } else if (policy.character === "hiragana"){
                if (wanakana.isKana(value.replace(/(\s| )/g, ""))){
                    value = wanakana.toHiragana(value)
                } else {
                    throw new Error("be_parser__should_be_hiragana")
                }
            } else if (policy.character === "kana"){
                if (!wanakana.isKana(value.replace(/(\s| )/g, ""))){
                    throw new Error("be_parser__should_be_kana")
                }
            }
        }