refactor(books): shared search normalisation and debounce helpers + migrate command palette to server-side queries (#2232)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export const SEARCH_DEBOUNCE_MS = 200;
|
||||
|
||||
export function normalizeRemoteSearchTerm(str: string): string {
|
||||
return str
|
||||
.replace(/[!@$%^&*_=|~`<>?/";']/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function normalizeLocalSearchTerm(str: string): string {
|
||||
const folded = str.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/ø/gi, 'o')
|
||||
.replace(/ł/gi, 'l')
|
||||
.replace(/æ/gi, 'ae')
|
||||
.replace(/œ/gi, 'oe')
|
||||
.replace(/ß/g, 'ss');
|
||||
return normalizeRemoteSearchTerm(folded).toLowerCase();
|
||||
}
|
||||
Reference in New Issue
Block a user