Files
ERP/frontend/src/lib/normalize.ts
T

20 lines
714 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ============================================================
// نرمال‌سازی متن برای جستجو/مقایسه‌ی بخشنده
// ============================================================
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, "ک");
}