diff --git a/src/utils/or.ts b/src/utils/or.ts index 3efa464..e03f87b 100644 --- a/src/utils/or.ts +++ b/src/utils/or.ts @@ -12,24 +12,36 @@ export default function(text: string, words: (string | RegExp)[]): boolean { * 例えば「藍ちゃん好き!」のようなテキストを「好き」にする */ function denoise(text: string): string { - text = text.trim() - .replace(/[!!]+$/, '') - .replace(/っ+$/, '') + text = text.trim(); + + function fn() { + text = text.replace(/[!!]+$/, ''); + text = text.replace(/っ+$/, ''); + // 末尾の ー を除去 // 例えば「おはよー」を「おはよ」にする // ただそのままだと「セーラー」などの本来「ー」が含まれているワードも「ー」が除去され // 「セーラ」になり、「セーラー」を期待している場合はマッチしなくなり期待する動作にならなくなるので、 // 期待するワードの末尾にもともと「ー」が含まれている場合は(対象のテキストの「ー」をすべて除去した後に)「ー」を付けてあげる - .replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : ''); + text = text.replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : ''); - text = text - .replace(/。$/, '') - .replace(/です$/, '') - .replace(/(\.|…)+$/, '') - .replace(/[♪♥]+$/, '') - .replace(/^藍/, '') - .replace(/^ちゃん/, '') - .replace(/、+$/, ''); + text = text.replace(/。$/, ''); + text = text.replace(/です$/, ''); + text = text.replace(/(\.|…)+$/, ''); + text = text.replace(/[♪♥]+$/, ''); + text = text.replace(/^藍/, ''); + text = text.replace(/^ちゃん/, ''); + text = text.replace(/、+$/, ''); + } + + let textBefore = text; + let textAfter = null; + + while (textBefore != textAfter) { + textBefore = text; + fn(); + textAfter = text; + } return text; }