mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-02 18:24:17 +00:00
24 lines
593 B
TypeScript
24 lines
593 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))
|
|
}
|