mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-29 15:24:54 +00:00
19 lines
581 B
TypeScript
19 lines
581 B
TypeScript
import { normalizeSync } from 'normalize-diacritics'
|
|
|
|
export type SearchTextValue =
|
|
string | number | boolean | bigint | null | undefined
|
|
|
|
export function normalizeSearchText(value: SearchTextValue): string {
|
|
return normalizeSync(String(value ?? '')).toLocaleLowerCase()
|
|
}
|
|
|
|
export function matchesSearchText(
|
|
value: SearchTextValue,
|
|
searchText: SearchTextValue
|
|
): boolean {
|
|
const normalizedValue = normalizeSearchText(value)
|
|
const searchTerms = normalizeSearchText(searchText).trim().split(/\s+/)
|
|
|
|
return searchTerms.every((term) => normalizedValue.includes(term))
|
|
}
|