uikit/src/utils/numbers.js
2026-06-21 15:41:45 +03:30

17 lines
611 B
JavaScript
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.

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