ai/src/utils/or.ts

21 lines
545 B
TypeScript
Raw Normal View History

2018-09-02 13:23:10 +00:00
import { hiraganaToKatagana, hankakuToZenkaku } from './japanese';
export default function(text: string, words: string[]): boolean {
if (text == null) return false;
text = cleanup(hankakuToZenkaku(hiraganaToKatagana(text)));
words = words.map(word => hiraganaToKatagana(word));
return words.some(word => text == word);
}
function cleanup(text: string): string {
return text.trim()
.replace(/[!]+$/, '')
.replace(/。$/, '')
2018-09-02 13:56:21 +00:00
.replace(/デス$/, '')
.replace(/^藍/, '')
.replace(/^チャン/, '')
.replace(/、+$/, '');
2018-09-02 13:23:10 +00:00
}