ai/src/utils/or.ts

18 lines
478 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(/。$/, '')
.replace(/(です|デス)$/, '');
}