aboutsummaryrefslogtreecommitdiff
path: root/src/lib/search.ts
diff options
context:
space:
mode:
authorJoris2021-05-29 19:24:41 +0200
committerJoris2021-05-29 19:24:41 +0200
commitd48cafebb277e4ad4b31e883cbe4f55eef9ea4a4 (patch)
tree7f04fb49defa5fbc7984b0eee60bb7ce16a37ae2 /src/lib/search.ts
parent4e3cd92a8063a70dab9ae0ccafd0552c78c6e005 (diff)
Rewrite in TypeScript
Diffstat (limited to 'src/lib/search.ts')
-rw-r--r--src/lib/search.ts11
1 files changed, 11 insertions, 0 deletions
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, "")
+}