From adb6b8b1f6896188f2905f7f2e62754f8e27b54f Mon Sep 17 00:00:00 2001 From: Mohamadzadeh <7796733@gmail.com> Date: Sun, 21 Jun 2026 15:39:42 +0330 Subject: [PATCH] update numbers utils --- dist/utils.js | 11 +++++++---- src/utils/numbers.js | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/dist/utils.js b/dist/utils.js index 949ffb8..2f56e18 100644 --- a/dist/utils.js +++ b/dist/utils.js @@ -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 { - o as toEnDigits, - i as toFaDigits, - e as toFaNumber + i as toEnDigits, + e as toFaDigits, + t as toFaNumber }; diff --git a/src/utils/numbers.js b/src/utils/numbers.js index 2b08aed..bbb1ceb 100644 --- a/src/utils/numbers.js +++ b/src/utils/numbers.js @@ -1,12 +1,16 @@ export const toFaNumber = (value) => { + if (value === null || value === undefined || value === "") return ""; return new Intl.NumberFormat("fa-IR").format(Number(value)); }; export const toFaDigits = (value) => { + if (value === null || value === undefined) return ""; return String(value).replace(/\d/g, (d) => "۰۱۲۳۴۵۶۷۸۹"[Number(d)]); }; export const toEnDigits = (value) => { - const numberString = String(value); - return numberString.replace(/[۰-۹]/g, (d) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(d))); + if (value === null || value === undefined) return ""; + return String(value).replace(/[۰-۹]/g, (d) => + String("۰۱۲۳۴۵۶۷۸۹".indexOf(d)), + ); };