Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.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)];
}
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,
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
}
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")
}
}
}