mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 13:17:59 +00:00
Refactor
This commit is contained in:
parent
c9d80e5470
commit
0b6c9323df
|
@ -11,7 +11,7 @@ export default function(text: string, words: (string | RegExp)[]): boolean {
|
||||||
* テキストの余分な部分を取り除く
|
* テキストの余分な部分を取り除く
|
||||||
* 例えば「藍ちゃん好き!」のようなテキストを「好き」にする
|
* 例えば「藍ちゃん好き!」のようなテキストを「好き」にする
|
||||||
*/
|
*/
|
||||||
function cleanup(text: string): string {
|
function denoise(text: string): string {
|
||||||
text = text.trim()
|
text = text.trim()
|
||||||
.replace(/[!!]+$/, '')
|
.replace(/[!!]+$/, '')
|
||||||
.replace(/っ+$/, '')
|
.replace(/っ+$/, '')
|
||||||
|
@ -33,9 +33,9 @@ export default function(text: string, words: (string | RegExp)[]): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof word == 'string') {
|
if (typeof word == 'string') {
|
||||||
return (text == word) || (cleanup(text) == word);
|
return (text == word) || (denoise(text) == word);
|
||||||
} else {
|
} else {
|
||||||
return (word.test(text)) || (word.test(cleanup(text)));
|
return (word.test(text)) || (word.test(denoise(text)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue