TelegramPWA/src/util/searchWords.ts
Alexander Zinchuk 3afcde3217 Initial commit
2021-04-09 14:11:51 +03:00

15 lines
431 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const RE_NOT_LETTER = /[^\wа-яё]+/;
export default function searchWords(haystack: string, needle: string) {
if (!haystack || !needle) {
return false;
}
const haystackWords = haystack.toLowerCase().split(RE_NOT_LETTER);
const needleWords = needle.toLowerCase().split(RE_NOT_LETTER);
return needleWords.every((needleWord) => (
haystackWords.some((haystackWord) => haystackWord.startsWith(needleWord))
));
}