Created
November 22, 2019 17:13
-
-
Save papalardo/4495acfe7fbf0ccaa3022511d0f37863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const normalize = str => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); | |
let text = "Lorem Ipsum íís simply dummy tééxt of the printing and typesetting industry."; | |
let termSearch = 'lorem iss'; | |
text = normalize(text).toLowerCase(); | |
termSearch = normalize(termSearch).toLowerCase(); | |
multiSearchAnd: | |
(text, searchWords) => | |
searchWords.every(word => text.match(new RegExp(word,"i"))); | |
multiSearchOr: | |
(text, searchWords) => | |
(new RegExp(searchWords.join("|"),"gi")).test(text); | |
multiSearchAnd(text, termSearch.split(' ')); | |
multiSearchOr(text, termSearch.split(' ')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment