From d48cafebb277e4ad4b31e883cbe4f55eef9ea4a4 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 29 May 2021 19:24:41 +0200 Subject: Rewrite in TypeScript --- src/lib/search.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/lib/search.ts (limited to 'src/lib/search.ts') diff --git a/src/lib/search.ts b/src/lib/search.ts new file mode 100644 index 0000000..7b9530e --- /dev/null +++ b/src/lib/search.ts @@ -0,0 +1,11 @@ +export function match(search: string, target: string): boolean { + return search.split(/\s+/).every(s => format(target).includes(format(s))) +} + +export function format(str: string): string { + return unaccent(str.toLowerCase()) +} + +function unaccent(str: string): string { + return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "") +} -- cgit v1.2.3