20 lines
714 B
TypeScript
20 lines
714 B
TypeScript
// ============================================================
|
||
// نرمالسازی متن برای جستجو/مقایسهی بخشنده
|
||
// ============================================================
|
||
|
||
const FA_DIGITS = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
|
||
|
||
function toEn(s: string): string {
|
||
return String(s).replace(/[۰-۹]/g, (d) => String(FA_DIGITS.indexOf(d)));
|
||
}
|
||
|
||
// trim, lowercase, یکسانسازی ی/ک فارسی و عربی، حذف zero-width non-joiner
|
||
export function normalize(s: unknown): string {
|
||
return toEn(String(s == null ? "" : s))
|
||
.replace(/\u200c/g, "")
|
||
.trim()
|
||
.toLowerCase()
|
||
.replace(/ي/g, "ی")
|
||
.replace(/ك/g, "ک");
|
||
}
|