Portage complet PHP/Bash vers Node.js (Fastify + worker_threads)
This commit is contained in:
29
lib/titleFilter.js
Normal file
29
lib/titleFilter.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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 };
|
||||
Reference in New Issue
Block a user