30 lines
779 B
JavaScript
30 lines
779 B
JavaScript
// Replicates the PHP search.php title normalization:
|
|
// - replace ligatures and superscripts
|
|
// - strip everything that is not Latin or 0-9
|
|
// - lowercase
|
|
|
|
const TITLE_SEARCHES = ['œ', 'Œ', 'æ', 'Æ', 'é', 'è', '²', '³', '⁴'];
|
|
const TITLE_REPLACES = ['oe', 'Oe', 'ae', 'Ae', 'é', 'è', '2', '3', '4'];
|
|
|
|
const FILTER_RE = /[^\p{Script=Latin}0-9]+/gu;
|
|
|
|
export function translit(s) {
|
|
if (!s) return '';
|
|
let out = s;
|
|
for (let i = 0; i < TITLE_SEARCHES.length; i++) {
|
|
out = out.split(TITLE_SEARCHES[i]).join(TITLE_REPLACES[i]);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function filterTitle(s) {
|
|
if (!s) return '';
|
|
return translit(s).replace(FILTER_RE, '');
|
|
}
|
|
|
|
export function filterAndLower(s) {
|
|
return filterTitle(s).toLocaleLowerCase();
|
|
}
|
|
|
|
export { FILTER_RE };
|