update numbers utils

This commit is contained in:
Mohamadzadeh 2026-06-21 15:39:42 +03:30
parent 8652f81ade
commit adb6b8b1f6
2 changed files with 13 additions and 6 deletions

11
dist/utils.js vendored
View File

@ -1,6 +1,9 @@
const e = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), i = (r) => String(r).replace(/\d/g, (t) => "۰۱۲۳۴۵۶۷۸۹"[Number(t)]), o = (r) => String(r).replace(/[۰-۹]/g, (n) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(n))); const t = (n) => n == null || n === "" ? "" : new Intl.NumberFormat("fa-IR").format(Number(n)), e = (n) => n == null ? "" : String(n).replace(/\d/g, (r) => "۰۱۲۳۴۵۶۷۸۹"[Number(r)]), i = (n) => n == null ? "" : String(n).replace(
/[۰-۹]/g,
(r) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(r))
);
export { export {
o as toEnDigits, i as toEnDigits,
i as toFaDigits, e as toFaDigits,
e as toFaNumber t as toFaNumber
}; };

View File

@ -1,12 +1,16 @@
export const toFaNumber = (value) => { export const toFaNumber = (value) => {
if (value === null || value === undefined || value === "") return "";
return new Intl.NumberFormat("fa-IR").format(Number(value)); return new Intl.NumberFormat("fa-IR").format(Number(value));
}; };
export const toFaDigits = (value) => { export const toFaDigits = (value) => {
if (value === null || value === undefined) return "";
return String(value).replace(/\d/g, (d) => "۰۱۲۳۴۵۶۷۸۹"[Number(d)]); return String(value).replace(/\d/g, (d) => "۰۱۲۳۴۵۶۷۸۹"[Number(d)]);
}; };
export const toEnDigits = (value) => { export const toEnDigits = (value) => {
const numberString = String(value); if (value === null || value === undefined) return "";
return numberString.replace(/[۰-۹]/g, (d) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(d))); return String(value).replace(/[۰-۹]/g, (d) =>
String("۰۱۲۳۴۵۶۷۸۹".indexOf(d)),
);
}; };