(query: string, dataset: string[])
| 207 | * but tags are the standards. |
| 208 | */ |
| 209 | export function fuzzySearch(query: string, dataset: string[]): string[] | null { |
| 210 | const q = query ? query.trim().toLowerCase() : ''; |
| 211 | |
| 212 | const result: string[] = []; |
| 213 | if (!q.length) { |
| 214 | return null; |
| 215 | } |
| 216 | |
| 217 | dataset.forEach((item) => { |
| 218 | const s = item.trim().toLowerCase(); |
| 219 | let n = -1; |
| 220 | for (const char of q) { |
| 221 | n = s.indexOf(char, n + 1); |
| 222 | if (!~n) { |
| 223 | return; |
| 224 | } |
| 225 | } |
| 226 | result.push(item); |
| 227 | }); |
| 228 | |
| 229 | return result.length ? result : null; |
| 230 | } |
no test coverage detected