Skip to content

Instantly share code, notes, and snippets.

@papalardo
Created November 22, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papalardo/4495acfe7fbf0ccaa3022511d0f37863 to your computer and use it in GitHub Desktop.
Save papalardo/4495acfe7fbf0ccaa3022511d0f37863 to your computer and use it in GitHub Desktop.
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