@rzl-zone/utils-js 3.13.1 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/.references/index.d.cts +2 -1
- package/dist/.references/index.d.ts +2 -1
- package/dist/AbortError-CgE6QNOR.js +20 -0
- package/dist/AbortError-CgE6QNOR.js.map +1 -0
- package/dist/AbortError-D54txsmn.cjs +26 -0
- package/dist/AbortError-D54txsmn.cjs.map +1 -0
- package/dist/{assertIsArray-HgzPQIAM.js → assertIsArray-DmlqnTiq.js} +3 -3
- package/dist/assertIsArray-DmlqnTiq.js.map +1 -0
- package/dist/{assertIsArray-CeXL4xv5.cjs → assertIsArray-Xx-zlo6O.cjs} +5 -5
- package/dist/assertIsArray-Xx-zlo6O.cjs.map +1 -0
- package/dist/assertIsPlainObject-CIzDchLs.js +20 -0
- package/dist/assertIsPlainObject-CIzDchLs.js.map +1 -0
- package/dist/assertIsPlainObject-DYoxHcW5.cjs +26 -0
- package/dist/assertIsPlainObject-DYoxHcW5.cjs.map +1 -0
- package/dist/{assertIsString-DUrVt82d.cjs → assertIsString-CuPbh3FB.cjs} +6 -6
- package/dist/assertIsString-CuPbh3FB.cjs.map +1 -0
- package/dist/{assertIsString-CY_WkCLr.js → assertIsString-sgY3ml5f.js} +4 -4
- package/dist/assertIsString-sgY3ml5f.js.map +1 -0
- package/dist/assertions/index.cjs +14 -12
- package/dist/assertions/index.cjs.map +1 -1
- package/dist/assertions/index.d.cts +2 -2
- package/dist/assertions/index.d.ts +2 -2
- package/dist/assertions/index.js +10 -8
- package/dist/assertions/index.js.map +1 -1
- package/dist/conversions/index.cjs +6 -6
- package/dist/conversions/index.d.cts +2 -2
- package/dist/conversions/index.d.ts +2 -2
- package/dist/conversions/index.js +6 -6
- package/dist/{conversions-1s7xMBe_.js → conversions-BkxqYXxy.js} +43 -40
- package/dist/conversions-BkxqYXxy.js.map +1 -0
- package/dist/conversions-UdMB90xR.cjs +449 -0
- package/dist/conversions-UdMB90xR.cjs.map +1 -0
- package/dist/errors/index.cjs +13 -0
- package/dist/errors/index.d.cts +180 -0
- package/dist/errors/index.d.ts +180 -0
- package/dist/errors/index.js +11 -0
- package/dist/events/index.cjs +10 -9
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.cts +185 -100
- package/dist/events/index.d.ts +185 -100
- package/dist/events/index.js +9 -8
- package/dist/events/index.js.map +1 -1
- package/dist/formatter-BFgV1HhV-BtIJs2H2.js +55 -0
- package/dist/formatter-BFgV1HhV-BtIJs2H2.js.map +1 -0
- package/dist/formatter-BFgV1HhV-DyybWSuj.cjs +67 -0
- package/dist/formatter-BFgV1HhV-DyybWSuj.cjs.map +1 -0
- package/dist/formatters/index.cjs +2 -2
- package/dist/formatters/index.d.cts +2 -2
- package/dist/formatters/index.d.ts +2 -2
- package/dist/formatters/index.js +2 -2
- package/dist/formatters-Cjng28nY.cjs +436 -0
- package/dist/formatters-Cjng28nY.cjs.map +1 -0
- package/dist/{formatters-C6cVZBbG.js → formatters-Dqccnt-p.js} +78 -71
- package/dist/formatters-Dqccnt-p.js.map +1 -0
- package/dist/generators/index.cjs +37 -31
- package/dist/generators/index.cjs.map +1 -1
- package/dist/generators/index.d.cts +2 -2
- package/dist/generators/index.d.ts +2 -2
- package/dist/generators/index.js +29 -23
- package/dist/generators/index.js.map +1 -1
- package/dist/hasOwnProp-DTWYqy7S.cjs +53 -0
- package/dist/hasOwnProp-DTWYqy7S.cjs.map +1 -0
- package/dist/hasOwnProp-yVVsxPin.js +47 -0
- package/dist/hasOwnProp-yVVsxPin.js.map +1 -0
- package/dist/{index-BG8wdusZ.d.cts → index-9Ql1W3gt.d.cts} +229 -200
- package/dist/{index-RNQBTK8A.d.cts → index-BD0J8wkE.d.cts} +1374 -936
- package/dist/index-BcoUy2oV.d.ts +2424 -0
- package/dist/{index-B5EBAgmC.d.cts → index-Bpk3YwGW.d.ts} +1592 -790
- package/dist/index-CTMG8cZV.d.ts +1041 -0
- package/dist/index-DUBCXPy4.d.cts +1041 -0
- package/dist/{index-CRz9rSZL.d.ts → index-DhUTzQ_o.d.ts} +1374 -936
- package/dist/{index-B1VQ6USF.d.ts → index-DqYMKSmd.d.ts} +229 -200
- package/dist/index-JfwSupYB.d.ts +1103 -0
- package/dist/{index-ORbo-7zA.d.cts → index-O2q2f-pu.d.cts} +242 -133
- package/dist/{index-DPJ-e2JZ.d.ts → index-VgNZ6ndx.d.cts} +1592 -790
- package/dist/{index-ORbo-7zA.d.ts → index-k_rjVRjU.d.ts} +242 -133
- package/dist/index-or0oP9i2.d.cts +2179 -0
- package/dist/index-or0oP9i2.d.ts +2179 -0
- package/dist/index-u4-Euidh.d.cts +1103 -0
- package/dist/index-zAqCZxGr.d.cts +2424 -0
- package/dist/{isBigInt-y7s3rsKc.js → isBigInt-DdFRCpeE.js} +2 -2
- package/dist/isBigInt-DdFRCpeE.js.map +1 -0
- package/dist/{isBigInt-BVj0M5pq.cjs → isBigInt-LkCpVJ3E.cjs} +2 -2
- package/dist/isBigInt-LkCpVJ3E.cjs.map +1 -0
- package/dist/{isEmptyString-BYMz_wt9.js → isEmptyString-B6ubItgT.js} +4 -4
- package/dist/isEmptyString-B6ubItgT.js.map +1 -0
- package/dist/{isEmptyString-C8PYNPgw.cjs → isEmptyString-Csc5Sf_W.cjs} +5 -5
- package/dist/isEmptyString-Csc5Sf_W.cjs.map +1 -0
- package/dist/isEmptyValue-h97JT4pD.js +36 -0
- package/dist/isEmptyValue-h97JT4pD.js.map +1 -0
- package/dist/isEmptyValue-qNOhUBFE.cjs +54 -0
- package/dist/isEmptyValue-qNOhUBFE.cjs.map +1 -0
- package/dist/{isFinite-DeDaBDr2.cjs → isFinite-CKeuVXbD.cjs} +6 -6
- package/dist/isFinite-CKeuVXbD.cjs.map +1 -0
- package/dist/{isFinite-BEJFOv6B.js → isFinite-CzYYv-mQ.js} +5 -5
- package/dist/isFinite-CzYYv-mQ.js.map +1 -0
- package/dist/{isInteger-DEDbBGez.js → isInteger-BtA3flbk.js} +4 -4
- package/dist/isInteger-BtA3flbk.js.map +1 -0
- package/dist/{isInteger-CQLThJOR.cjs → isInteger-iTok9NaH.cjs} +4 -4
- package/dist/isInteger-iTok9NaH.cjs.map +1 -0
- package/dist/isNumber-C1mOuBuA.js +20 -0
- package/dist/isNumber-C1mOuBuA.js.map +1 -0
- package/dist/isNumber-CM1vdNcW.cjs +26 -0
- package/dist/isNumber-CM1vdNcW.cjs.map +1 -0
- package/dist/isPlainObject-DQoM4DGQ.d.ts +331 -0
- package/dist/isPlainObject-Y__iykWN.d.cts +331 -0
- package/dist/{isServer-DmycqWsF.cjs → isServer-CWlp2R2N.cjs} +2 -2
- package/dist/isServer-CWlp2R2N.cjs.map +1 -0
- package/dist/{isServer-q3o6cSwD.js → isServer-Drgyboev.js} +2 -2
- package/dist/isServer-Drgyboev.js.map +1 -0
- package/dist/{isEqual-DM4S_kWh.js → isTypedArray-BY8CIj3k.js} +29 -9
- package/dist/isTypedArray-BY8CIj3k.js.map +1 -0
- package/dist/{isEqual-DaPDxMyw.cjs → isTypedArray-DspIjxdk.cjs} +45 -13
- package/dist/isTypedArray-DspIjxdk.cjs.map +1 -0
- package/dist/{isValidDomain-B8Nukgw0.js → isValidDomain-BPfJEkFk.js} +13 -54
- package/dist/isValidDomain-BPfJEkFk.js.map +1 -0
- package/dist/{isValidDomain-ZbyeGOO9.cjs → isValidDomain-DUUCoKtD.cjs} +16 -69
- package/dist/isValidDomain-DUUCoKtD.cjs.map +1 -0
- package/dist/{assertIsBoolean-D41HrTB_.cjs → logger-BXg2xufj.cjs} +658 -612
- package/dist/logger-BXg2xufj.cjs.map +1 -0
- package/dist/{assertIsBoolean-CWUs-I5l.js → logger-Wxl_Krg6.js} +657 -587
- package/dist/logger-Wxl_Krg6.js.map +1 -0
- package/dist/{noop-BY43WaoU.cjs → noop-ByxeOveJ.cjs} +2 -2
- package/dist/noop-ByxeOveJ.cjs.map +1 -0
- package/dist/{noop-CjY8xVHv.js → noop-D8aGbjbP.js} +2 -2
- package/dist/noop-D8aGbjbP.js.map +1 -0
- package/dist/{normalizeSpaces-BhZp0U_6.cjs → normalizeSpaces-CQ7tZLNG.cjs} +6 -9
- package/dist/normalizeSpaces-CQ7tZLNG.cjs.map +1 -0
- package/dist/{normalizeSpaces-BoUDtq5P.js → normalizeSpaces-DNUOxp_8.js} +4 -7
- package/dist/normalizeSpaces-DNUOxp_8.js.map +1 -0
- package/dist/operations/index.cjs +152 -22
- package/dist/operations/index.cjs.map +1 -1
- package/dist/operations/index.d.cts +257 -35
- package/dist/operations/index.d.ts +257 -35
- package/dist/operations/index.js +142 -13
- package/dist/operations/index.js.map +1 -1
- package/dist/parsers/index.cjs +2 -2
- package/dist/parsers/index.d.cts +238 -180
- package/dist/parsers/index.d.ts +238 -180
- package/dist/parsers/index.js +2 -2
- package/dist/{parsers-B_FPX35n.cjs → parsers-CJ5tHtqF.cjs} +10 -9
- package/dist/parsers-CJ5tHtqF.cjs.map +1 -0
- package/dist/{parsers-B8KYXIjE.js → parsers-DMlqliPw.js} +9 -8
- package/dist/parsers-DMlqliPw.js.map +1 -0
- package/dist/{parsing-BCZGco7n.cjs → parsing-DB_S0WFz.cjs} +4 -4
- package/dist/parsing-DB_S0WFz.cjs.map +1 -0
- package/dist/{parsing-Bfaw85Hd.js → parsing-DhIQhWpX.js} +3 -3
- package/dist/parsing-DhIQhWpX.js.map +1 -0
- package/dist/predicates/index.cjs +43 -43
- package/dist/predicates/index.d.cts +3 -3
- package/dist/predicates/index.d.ts +3 -3
- package/dist/predicates/index.js +14 -14
- package/dist/{predicates-KlyOvBSC.js → predicates-BzYMbNrZ.js} +45 -40
- package/dist/predicates-BzYMbNrZ.js.map +1 -0
- package/dist/{predicates-8y28VrbT.cjs → predicates-DDW3etqF.cjs} +89 -84
- package/dist/predicates-DDW3etqF.cjs.map +1 -0
- package/dist/promises/index.cjs +27 -26
- package/dist/promises/index.cjs.map +1 -1
- package/dist/promises/index.d.cts +227 -75
- package/dist/promises/index.d.ts +227 -75
- package/dist/promises/index.js +27 -26
- package/dist/promises/index.js.map +1 -1
- package/dist/{punyCode-DnKi0qjS.cjs → punyCode-B_VPjG0d.cjs} +12 -12
- package/dist/punyCode-B_VPjG0d.cjs.map +1 -0
- package/dist/{punyCode-Dwto1RpA.js → punyCode-DsuJbWCl.js} +12 -12
- package/dist/punyCode-DsuJbWCl.js.map +1 -0
- package/dist/{removeSpaces--8NW-HSx.js → removeSpaces-BF-T_1Yt.js} +4 -4
- package/dist/removeSpaces-BF-T_1Yt.js.map +1 -0
- package/dist/{removeSpaces-CmrrkeXz.cjs → removeSpaces-BJu-gKps.cjs} +7 -7
- package/dist/removeSpaces-BJu-gKps.cjs.map +1 -0
- package/dist/rzl-utils.global.js +13 -13
- package/dist/safeJsonParse-B5F8XtrZ.cjs +209 -0
- package/dist/safeJsonParse-B5F8XtrZ.cjs.map +1 -0
- package/dist/{safeJsonParse-OnUwG2El.js → safeJsonParse-DYSkUnhM.js} +29 -28
- package/dist/safeJsonParse-DYSkUnhM.js.map +1 -0
- package/dist/{safeStableStringify-B2KTTS3r.js → safeStableStringify-CDSYnLUz.js} +20 -13
- package/dist/safeStableStringify-CDSYnLUz.js.map +1 -0
- package/dist/safeStableStringify-MuBiT-4B.cjs +125 -0
- package/dist/safeStableStringify-MuBiT-4B.cjs.map +1 -0
- package/dist/strings/index.cjs +26 -30
- package/dist/strings/index.cjs.map +1 -1
- package/dist/strings/index.d.cts +2 -2
- package/dist/strings/index.d.ts +2 -2
- package/dist/strings/index.js +13 -17
- package/dist/strings/index.js.map +1 -1
- package/dist/tailwind/index.cjs +3 -3
- package/dist/tailwind/index.d.cts +3 -3
- package/dist/tailwind/index.d.ts +3 -3
- package/dist/tailwind/index.js +3 -3
- package/dist/{tailwind-CUdmv-oO.js → tailwind-BhHULklj.js} +38 -32
- package/dist/tailwind-BhHULklj.js.map +1 -0
- package/dist/{tailwind-DUuboq52.cjs → tailwind-hx6TIFIL.cjs} +59 -53
- package/dist/tailwind-hx6TIFIL.cjs.map +1 -0
- package/dist/{toStringArrayUnRecursive-OOHGazks.js → toStringArrayUnRecursive-U-nkEIDs.js} +9 -9
- package/dist/toStringArrayUnRecursive-U-nkEIDs.js.map +1 -0
- package/dist/toStringArrayUnRecursive-_lJEmBlf.cjs +51 -0
- package/dist/toStringArrayUnRecursive-_lJEmBlf.cjs.map +1 -0
- package/dist/urls/index.cjs +3 -3
- package/dist/urls/index.d.cts +635 -443
- package/dist/urls/index.d.ts +635 -443
- package/dist/urls/index.js +3 -3
- package/dist/{urls-BXT4Krsq.js → urls-BcGIFgfR.js} +50 -41
- package/dist/urls-BcGIFgfR.js.map +1 -0
- package/dist/urls-DGvZsMSN.cjs +308 -0
- package/dist/urls-DGvZsMSN.cjs.map +1 -0
- package/package.json +6 -6
- package/dist/assertIsArray-CeXL4xv5.cjs.map +0 -1
- package/dist/assertIsArray-HgzPQIAM.js.map +0 -1
- package/dist/assertIsBoolean-CWUs-I5l.js.map +0 -1
- package/dist/assertIsBoolean-D41HrTB_.cjs.map +0 -1
- package/dist/assertIsString-CY_WkCLr.js.map +0 -1
- package/dist/assertIsString-DUrVt82d.cjs.map +0 -1
- package/dist/conversions-1s7xMBe_.js.map +0 -1
- package/dist/conversions-B3Rf8uId.cjs +0 -446
- package/dist/conversions-B3Rf8uId.cjs.map +0 -1
- package/dist/formatters-C6cVZBbG.js.map +0 -1
- package/dist/formatters-aEAAuzjx.cjs +0 -429
- package/dist/formatters-aEAAuzjx.cjs.map +0 -1
- package/dist/index-CPCt6_Wq.d.cts +0 -765
- package/dist/index-CPCt6_Wq.d.ts +0 -765
- package/dist/index-DBwNa1iO.d.ts +0 -947
- package/dist/index-DPTYOQkn.d.cts +0 -947
- package/dist/index-Dig1fIhZ.d.cts +0 -1716
- package/dist/index-Dig1fIhZ.d.ts +0 -1716
- package/dist/isBigInt-BVj0M5pq.cjs.map +0 -1
- package/dist/isBigInt-y7s3rsKc.js.map +0 -1
- package/dist/isEmptyObject-BsHngDz4.cjs +0 -37
- package/dist/isEmptyObject-BsHngDz4.cjs.map +0 -1
- package/dist/isEmptyObject-DPGR9iPj.js +0 -25
- package/dist/isEmptyObject-DPGR9iPj.js.map +0 -1
- package/dist/isEmptyString-BYMz_wt9.js.map +0 -1
- package/dist/isEmptyString-C8PYNPgw.cjs.map +0 -1
- package/dist/isEmptyValue-BXf7f1jz.cjs +0 -30
- package/dist/isEmptyValue-BXf7f1jz.cjs.map +0 -1
- package/dist/isEmptyValue-D4OHTB3u.js +0 -24
- package/dist/isEmptyValue-D4OHTB3u.js.map +0 -1
- package/dist/isEqual-DM4S_kWh.js.map +0 -1
- package/dist/isEqual-DaPDxMyw.cjs.map +0 -1
- package/dist/isFinite-BEJFOv6B.js.map +0 -1
- package/dist/isFinite-DeDaBDr2.cjs.map +0 -1
- package/dist/isInteger-CQLThJOR.cjs.map +0 -1
- package/dist/isInteger-DEDbBGez.js.map +0 -1
- package/dist/isPlainObject-BwTkj3G0.d.cts +0 -339
- package/dist/isPlainObject-BwTkj3G0.d.ts +0 -339
- package/dist/isServer-DmycqWsF.cjs.map +0 -1
- package/dist/isServer-q3o6cSwD.js.map +0 -1
- package/dist/isTypedArray-BQLbLXsU.cjs +0 -43
- package/dist/isTypedArray-BQLbLXsU.cjs.map +0 -1
- package/dist/isTypedArray-XiBnifLN.js +0 -31
- package/dist/isTypedArray-XiBnifLN.js.map +0 -1
- package/dist/isValidDomain-B8Nukgw0.js.map +0 -1
- package/dist/isValidDomain-ZbyeGOO9.cjs.map +0 -1
- package/dist/noop-BY43WaoU.cjs.map +0 -1
- package/dist/noop-CjY8xVHv.js.map +0 -1
- package/dist/normalizeSpaces-BhZp0U_6.cjs.map +0 -1
- package/dist/normalizeSpaces-BoUDtq5P.js.map +0 -1
- package/dist/parsers-B8KYXIjE.js.map +0 -1
- package/dist/parsers-B_FPX35n.cjs.map +0 -1
- package/dist/parsing-BCZGco7n.cjs.map +0 -1
- package/dist/parsing-Bfaw85Hd.js.map +0 -1
- package/dist/predicates-8y28VrbT.cjs.map +0 -1
- package/dist/predicates-KlyOvBSC.js.map +0 -1
- package/dist/punyCode-DnKi0qjS.cjs.map +0 -1
- package/dist/punyCode-Dwto1RpA.js.map +0 -1
- package/dist/removeSpaces--8NW-HSx.js.map +0 -1
- package/dist/removeSpaces-CmrrkeXz.cjs.map +0 -1
- package/dist/safeJsonParse-OnUwG2El.js.map +0 -1
- package/dist/safeJsonParse-sFqVXf-e.cjs +0 -208
- package/dist/safeJsonParse-sFqVXf-e.cjs.map +0 -1
- package/dist/safeStableStringify-B2KTTS3r.js.map +0 -1
- package/dist/safeStableStringify-Cmi6GyWj.cjs +0 -106
- package/dist/safeStableStringify-Cmi6GyWj.cjs.map +0 -1
- package/dist/tailwind-CUdmv-oO.js.map +0 -1
- package/dist/tailwind-DUuboq52.cjs.map +0 -1
- package/dist/toStringArrayUnRecursive-OOHGazks.js.map +0 -1
- package/dist/toStringArrayUnRecursive-pfk2oP8C.cjs +0 -51
- package/dist/toStringArrayUnRecursive-pfk2oP8C.cjs.map +0 -1
- package/dist/urls-BL9C_yU3.cjs +0 -299
- package/dist/urls-BL9C_yU3.cjs.map +0 -1
- package/dist/urls-BXT4Krsq.js.map +0 -1
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.14.0`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { A as OverrideTypes, N as Prettify, O as OmitStrict, c as ExtractStrict, i as AnyString } from "./index-or0oP9i2.cjs";
|
|
12
12
|
import { CountryCode, NumberFormat } from "libphonenumber-js";
|
|
13
13
|
import { FormatOptions, Locale } from "date-fns";
|
|
14
14
|
type NegativeFormatOptionCustom = {
|
|
15
15
|
/**
|
|
16
|
-
* Custom formatter function for the final formatted negative string
|
|
17
|
-
* If provided, it ***OVERRIDES*** style & space entirely.
|
|
16
|
+
* * ***Custom formatter function for the final formatted negative string, if provided, it ***OVERRIDES*** style & space entirely.***
|
|
18
17
|
*/
|
|
19
18
|
custom: (formatted: string) => string;
|
|
20
19
|
style?: never;
|
|
@@ -22,394 +21,496 @@ type NegativeFormatOptionCustom = {
|
|
|
22
21
|
};
|
|
23
22
|
type NegativeFormatOptionUnCustom = {
|
|
24
23
|
custom?: never;
|
|
25
|
-
/**
|
|
24
|
+
/** ---------------------------------------------------------------------------
|
|
25
|
+
* * ***Use style & optional spacing for negative numbers.***
|
|
26
|
+
* ----------------------------------------------------------------------------
|
|
26
27
|
*
|
|
27
28
|
* @default "dash"
|
|
28
29
|
*/
|
|
29
30
|
style?: "dash" | "brackets" | "abs";
|
|
30
|
-
/**
|
|
31
|
+
/** ---------------------------------------------------------------------------
|
|
32
|
+
* * ***Whether to include space inside brackets or after dash.***
|
|
33
|
+
* ----------------------------------------------------------------------------
|
|
31
34
|
*
|
|
32
|
-
* Default: false
|
|
33
35
|
* @default false
|
|
34
36
|
*/
|
|
35
37
|
space?: boolean;
|
|
36
38
|
};
|
|
37
|
-
/**
|
|
39
|
+
/** -----------------------------------------------------------------------------
|
|
38
40
|
* * ***Type for negative number formatting options.***
|
|
39
|
-
*
|
|
41
|
+
* ------------------------------------------------------------------------------
|
|
40
42
|
*/
|
|
41
43
|
type NegativeFormatOption = "dash" | "brackets" | "abs" | NegativeFormatOptionCustom | NegativeFormatOptionUnCustom;
|
|
42
|
-
/**
|
|
44
|
+
/** -----------------------------------------------------------------------------
|
|
43
45
|
* * ***Type Options for {@link formatCurrency|`formatCurrency`}.***
|
|
44
|
-
*
|
|
46
|
+
* ------------------------------------------------------------------------------
|
|
45
47
|
*/
|
|
46
48
|
type FormatCurrencyOptions = {
|
|
47
49
|
/** ---------------------------------------------------------------------------
|
|
48
50
|
* * ***Prefix currency string.***
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
+
* ----------------------------------------------------------------------------
|
|
51
52
|
* **Does not auto-keep input symbols.**
|
|
52
|
-
* - ***DefaultValue:** `""`.*
|
|
53
|
-
* - **Example:** `"Rp "` ➔ `Rp 1.000`.
|
|
54
53
|
*
|
|
54
|
+
* ---
|
|
55
|
+
* - DefaultValue: `""`.
|
|
56
|
+
* - Example: `"Rp "` ➔ `Rp 1.000`.
|
|
57
|
+
*
|
|
58
|
+
* ---
|
|
55
59
|
* @default ""
|
|
56
60
|
*/
|
|
57
61
|
suffixCurrency?: string;
|
|
58
62
|
/** ---------------------------------------------------------------------------
|
|
59
63
|
* * ***Thousands separator.***
|
|
60
|
-
*
|
|
64
|
+
* ----------------------------------------------------------------------------
|
|
61
65
|
*
|
|
62
|
-
* -
|
|
63
|
-
* -
|
|
66
|
+
* - DefaultValue: `"."`.
|
|
67
|
+
* - Example: `"."` ➔ `1.000.000`.
|
|
64
68
|
*
|
|
69
|
+
* ---
|
|
65
70
|
* @default "."
|
|
66
71
|
*/
|
|
67
72
|
separator?: string;
|
|
68
73
|
/** ---------------------------------------------------------------------------
|
|
69
74
|
* * ***Prefix currency string.***
|
|
70
|
-
*
|
|
71
|
-
*
|
|
75
|
+
* ----------------------------------------------------------------------------
|
|
72
76
|
* **Whether to show decimals, if `false`, decimals are truncated.**
|
|
73
|
-
* - ***DefaultValue:** `false`.*
|
|
74
77
|
*
|
|
78
|
+
* ---
|
|
79
|
+
* - DefaultValue: `false`.
|
|
80
|
+
*
|
|
81
|
+
* ---
|
|
75
82
|
* @default false
|
|
76
83
|
*/
|
|
77
84
|
decimal?: boolean;
|
|
78
85
|
/** ---------------------------------------------------------------------------
|
|
79
86
|
* * ***Total decimal digits.***
|
|
80
|
-
*
|
|
81
|
-
*
|
|
87
|
+
* ----------------------------------------------------------------------------
|
|
82
88
|
* **If `decimal: true` & `roundedDecimal: false`, simply cuts.**
|
|
83
|
-
* - ***DefaultValue:** `2`.*
|
|
84
89
|
*
|
|
90
|
+
* ---
|
|
91
|
+
* - DefaultValue: `2`.
|
|
92
|
+
*
|
|
93
|
+
* ---
|
|
85
94
|
* @default 2
|
|
86
95
|
*/
|
|
87
96
|
totalDecimal?: number;
|
|
88
97
|
/** ---------------------------------------------------------------------------
|
|
89
98
|
* * ***Actually append `suffixDecimal`.***
|
|
90
|
-
*
|
|
99
|
+
* ----------------------------------------------------------------------------
|
|
91
100
|
*
|
|
92
|
-
* -
|
|
101
|
+
* - DefaultValue: `true`.
|
|
93
102
|
*
|
|
103
|
+
* ---
|
|
94
104
|
* @default true
|
|
95
105
|
*/
|
|
96
106
|
endDecimal?: boolean;
|
|
97
107
|
/** ---------------------------------------------------------------------------
|
|
98
108
|
* * ***Text appended after decimals.***
|
|
99
|
-
*
|
|
109
|
+
* ----------------------------------------------------------------------------
|
|
100
110
|
*
|
|
101
|
-
* -
|
|
102
|
-
* -
|
|
103
|
-
*
|
|
104
|
-
*
|
|
111
|
+
* - DefaultValue: `""`.
|
|
112
|
+
* - Example:
|
|
113
|
+
* - `".-"` ➔ `1.000,00.-`.
|
|
114
|
+
* - `" USD"` ➔ `1.000,00 USD`.
|
|
105
115
|
*
|
|
116
|
+
* ---
|
|
106
117
|
* @default ""
|
|
107
118
|
*/
|
|
108
119
|
suffixDecimal?: string;
|
|
109
120
|
/** ---------------------------------------------------------------------------
|
|
110
121
|
* * ***Rounding mode for decimals.***
|
|
111
|
-
*
|
|
122
|
+
* ----------------------------------------------------------------------------
|
|
112
123
|
*
|
|
113
|
-
* -
|
|
124
|
+
* - Behavior:
|
|
114
125
|
* - `"round"` ➔ nearest.
|
|
115
126
|
* - `"ceil"` ➔ always up.
|
|
116
127
|
* - `"floor"` ➔ always down.
|
|
117
128
|
* - `false` ➔ truncate.
|
|
118
|
-
* -
|
|
129
|
+
* - DefaultValue: `"round"`.
|
|
119
130
|
*
|
|
131
|
+
* ---
|
|
120
132
|
* @default "round"
|
|
121
133
|
*/
|
|
122
134
|
roundedDecimal?: "round" | "ceil" | "floor" | false;
|
|
123
135
|
/** ---------------------------------------------------------------------------
|
|
124
136
|
* * ***Decimal separator.***
|
|
125
|
-
*
|
|
137
|
+
* ----------------------------------------------------------------------------
|
|
126
138
|
*
|
|
127
|
-
* -
|
|
128
|
-
* -
|
|
139
|
+
* - DefaultValue: `","`.
|
|
140
|
+
* - Example: `","` ➔ `1.000,10`.
|
|
129
141
|
*
|
|
142
|
+
* ---
|
|
130
143
|
* @default ","
|
|
131
144
|
*/
|
|
132
145
|
separatorDecimals?: string;
|
|
133
146
|
/** ---------------------------------------------------------------------------
|
|
134
147
|
* * ***Negative formatting option.***
|
|
135
|
-
*
|
|
148
|
+
* ----------------------------------------------------------------------------
|
|
149
|
+
* **Can be string (`"dash"` | `"brackets"` | `"abs"`) or object with custom formatter.**
|
|
136
150
|
*
|
|
137
|
-
*
|
|
138
|
-
* -
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* -
|
|
151
|
+
* ---
|
|
152
|
+
* - Behavior:
|
|
153
|
+
* - `"dash"` ➔ `-15.000`.
|
|
154
|
+
* - `"brackets"` ➔ `(15.000)`.
|
|
155
|
+
* - `"abs"` ➔ `15.000` (always positive).
|
|
156
|
+
* - Or object:
|
|
157
|
+
* `{
|
|
158
|
+
* style: "dash"|"brackets"|"abs",
|
|
159
|
+
* space: true|false,
|
|
160
|
+
* custom: (formatted) => string
|
|
161
|
+
* }`.
|
|
162
|
+
* - DefaultValue: `"dash"`.
|
|
149
163
|
*
|
|
164
|
+
* ---
|
|
150
165
|
* @default "dash"
|
|
151
166
|
*/
|
|
152
167
|
negativeFormat?: NegativeFormatOption;
|
|
153
168
|
/** ---------------------------------------------------------------------------
|
|
154
169
|
* * ***Applies Indian Format.***
|
|
155
|
-
*
|
|
170
|
+
* ----------------------------------------------------------------------------
|
|
156
171
|
*
|
|
157
|
-
* -
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* -
|
|
172
|
+
* - Behavior:
|
|
173
|
+
* - If `true`, formats as Indian: `12,34,567`.
|
|
174
|
+
* - Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
175
|
+
* - DefaultValue: `false`.
|
|
161
176
|
*
|
|
177
|
+
* ---
|
|
162
178
|
* @default false
|
|
163
179
|
*/
|
|
164
180
|
indianFormat?: boolean;
|
|
165
181
|
};
|
|
166
182
|
/** -------------------------------------------------------
|
|
167
183
|
* * ***Utility: `formatCurrency`.***
|
|
168
|
-
*
|
|
184
|
+
* --------------------------------------------------------
|
|
169
185
|
* **Formats a number or messy currency string into a
|
|
170
186
|
* beautifully formatted currency string, with highly
|
|
171
187
|
* customizable separators, decimal control, rounding,
|
|
172
188
|
* currency symbols, and negative styling.**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* - `
|
|
178
|
-
* -
|
|
179
|
-
*
|
|
180
|
-
*
|
|
189
|
+
*
|
|
190
|
+
* ---
|
|
191
|
+
* - **Highlights:**
|
|
192
|
+
* - ***Accepts:***
|
|
193
|
+
* - Pure numbers: `15300.95`.
|
|
194
|
+
* - Messy currency strings from **any locale**:
|
|
195
|
+
* - `"Rp 15.000,21"` ***(Indonesian / Euro)***.
|
|
196
|
+
* - `"$12,345.60"` ***(US)***.
|
|
197
|
+
* - `"CHF 12'345.60"` ***(Swiss)***.
|
|
198
|
+
* - `"1,23,456.78"` ***(Indian)***.
|
|
181
199
|
* - Auto extracts numeric value with smart multi-locale parsing
|
|
182
200
|
* via ***`parseCurrencyString` utility function***.
|
|
183
201
|
* - Strong type checks & clear errors for misconfigured options.
|
|
184
202
|
* - **Handles:**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* -
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* -
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
203
|
+
* - Thousands separators: `.`, `,`, `'`, ` `.
|
|
204
|
+
* - Decimal separators: `,`, `.`.
|
|
205
|
+
* - Decimal suffix (eg. `".-"`, `" USD"`).
|
|
206
|
+
* - Currency prefix (eg. `"Rp "`, `"$ "`).
|
|
207
|
+
* - Rounding: `"round"`, `"ceil"`, `"floor"`, or truncate.
|
|
208
|
+
* - Negative styling: dash `-`, brackets `( )`, absolute, or custom.
|
|
209
|
+
* - **How input is parsed:**
|
|
210
|
+
* - Removes all non-digit except `.`, `,`, `'` and spaces.
|
|
211
|
+
* - Detects bracket negatives: `"(15.000,10)"` ➔ `-15000.10`.
|
|
212
|
+
* - Uses last `,` or `.` as decimal separator (others are thousands).
|
|
213
|
+
* - Ignores currency symbols like `Rp`, `$` (must re-apply with `suffixCurrency`).
|
|
214
|
+
* - **Note:**
|
|
215
|
+
* - Always re-apply symbols via `suffixCurrency`.
|
|
216
|
+
* - `parseCurrencyString` smartly detects last decimal,
|
|
217
|
+
* so `"1.121.234,56"` and `"1,121,234.56"` both parsed correctly.
|
|
218
|
+
*
|
|
219
|
+
* ---
|
|
200
220
|
* @param {string|number} value
|
|
201
221
|
* ***The input value to format, examples:***
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
222
|
+
* - `"Rp 15.000,21"`.
|
|
223
|
+
* - `"$12,345.60"`.
|
|
224
|
+
* - `"CHF 12'345.60"`.
|
|
225
|
+
* - `15300.95`.
|
|
206
226
|
* @param {FormatCurrencyOptions} [options] ***Optional configuration object.***
|
|
207
227
|
* @param {FormatCurrencyOptions["separator"]} [options.separator]
|
|
208
228
|
* ***Thousands separator:***
|
|
209
|
-
*
|
|
210
|
-
*
|
|
229
|
+
* - `{ separator: "." }` ➔ `1.000.000`.
|
|
230
|
+
* - *DefaultValue: `"."`.*
|
|
211
231
|
* @param {FormatCurrencyOptions["separatorDecimals"]} [options.separatorDecimals]
|
|
212
232
|
* ***Decimal separator:***
|
|
213
|
-
*
|
|
214
|
-
*
|
|
233
|
+
* - `{ separatorDecimals: "," }` ➔ `1.000,10`.
|
|
234
|
+
* - *DefaultValue: `","`.*
|
|
215
235
|
* @param {FormatCurrencyOptions["suffixCurrency"]} [options.suffixCurrency]
|
|
216
236
|
* ***Prefix currency string:***
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
237
|
+
* - Does **not auto-keep input symbols**.
|
|
238
|
+
* - Must set manually e.g: `{ suffixCurrency: "Rp " }`.
|
|
239
|
+
* - `{ suffixCurrency: "Rp " }` ➔ `Rp 1.000`.
|
|
240
|
+
* - *DefaultValue: `""`.*
|
|
221
241
|
* @param {FormatCurrencyOptions["decimal"]} [options.decimal]
|
|
222
242
|
* ***Whether to show decimals. If `false`, decimals are truncated:***
|
|
223
|
-
*
|
|
224
|
-
*
|
|
243
|
+
* - If `false`, cut the decimal.
|
|
244
|
+
* - *DefaultValue: `false`.*
|
|
225
245
|
* @param {FormatCurrencyOptions["totalDecimal"]} [options.totalDecimal]
|
|
226
246
|
* ***Total decimal digits:***
|
|
227
|
-
*
|
|
228
|
-
*
|
|
247
|
+
* - If `decimal: true` & `roundedDecimal: false`, simply cuts.
|
|
248
|
+
* - *DefaultValue: `2`.*
|
|
229
249
|
* @param {FormatCurrencyOptions["separatorDecimals"]} [options.suffixDecimal]
|
|
230
250
|
* ***Text appended after decimals:***
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
251
|
+
* - E.g: (`".-"`, `" USD"`).
|
|
252
|
+
* - Example 1: `".-"` ➔ `1.000,00.-`.
|
|
253
|
+
* - Example 2: `" USD"` ➔ `1.000,00 USD`.
|
|
254
|
+
* - *DefaultValue: `""`.*
|
|
235
255
|
* @param {FormatCurrencyOptions["endDecimal"]} [options.endDecimal]
|
|
236
256
|
* ***Actually append `suffixDecimal`:***
|
|
237
|
-
*
|
|
257
|
+
* - *DefaultValue: `true`.*
|
|
238
258
|
* @param {FormatCurrencyOptions["roundedDecimal"]} [options.roundedDecimal]
|
|
239
259
|
* ***Rounding mode:***
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
260
|
+
* - `"round"` ➔ nearest.
|
|
261
|
+
* - `"ceil"` ➔ always up.
|
|
262
|
+
* - `"floor"` ➔ always down.
|
|
263
|
+
* - `false` ➔ truncate.
|
|
264
|
+
* - *DefaultValue: `"round"`.*
|
|
245
265
|
* @param {FormatCurrencyOptions["negativeFormat"]} [options.negativeFormat]
|
|
246
266
|
* ***How to format negatives:***
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
267
|
+
* - `"dash"` ➔ `-15.000`.
|
|
268
|
+
* - `"brackets"` ➔ `(15.000)`.
|
|
269
|
+
* - `"abs"` ➔ `15.000` (always positive).
|
|
270
|
+
* - Or object: `{ style: "dash" | "brackets" | "abs", space: true | false, custom: (formatted) => string }`.
|
|
271
|
+
* - *DefaultValue: `"dash"`.*
|
|
252
272
|
* @param {FormatCurrencyOptions["indianFormat"]} [options.indianFormat]
|
|
253
273
|
* ***Applies Indian Format:***
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* @returns {string}
|
|
257
|
-
* ***Nicely formatted currency string, examples:***
|
|
258
|
-
* - `"15.000,10"`.
|
|
259
|
-
* - `"Rp 15.000,10.-"`.
|
|
260
|
-
* - `"15'000.10 USD"`.
|
|
261
|
-
* - `"12,34,567.89"`.
|
|
262
|
-
* @throws **{@link TypeError | `TypeError`}** ***If:***
|
|
263
|
-
* - The `value` is not string or number.
|
|
264
|
-
* - Cannot parse to valid number.
|
|
265
|
-
* - Options have invalid types.
|
|
266
|
-
* @example
|
|
267
|
-
* // --- Number input (default, decimals off) ---
|
|
268
|
-
* formatCurrency(1234567.89);
|
|
269
|
-
* // ➔ "1.234.567"
|
|
270
|
-
*
|
|
271
|
-
* // --- Decimals enabled ---
|
|
272
|
-
* formatCurrency(1234567.89, { decimal: true });
|
|
273
|
-
* // ➔ "1.234.567,89"
|
|
274
|
-
*
|
|
275
|
-
* // --- Indian format ---
|
|
276
|
-
* formatCurrency(1234567.89, { decimal: true, indianFormat: true });
|
|
277
|
-
* // ➔ "12,34,567.89"
|
|
274
|
+
* - If `true`, formats as Indian: `12,34,567`.
|
|
275
|
+
* - Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
278
276
|
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* // --- String input (US style) ---
|
|
284
|
-
* formatCurrency("$12,345.60", { decimal: true });
|
|
285
|
-
* // ➔ "12.345,60"
|
|
286
|
-
*
|
|
287
|
-
* // --- String input (Swiss style) ---
|
|
288
|
-
* formatCurrency("CHF 12'345.60", { decimal: true });
|
|
289
|
-
* // ➔ "12'345,60"
|
|
290
|
-
*
|
|
291
|
-
* // --- String input (Indian style) ---
|
|
292
|
-
* formatCurrency("1,23,456.78", { decimal: true, indianFormat: true });
|
|
293
|
-
* // ➔ "12,34,567.78"
|
|
294
|
-
*
|
|
295
|
-
* // --- Negative numbers (dash) ---
|
|
296
|
-
* formatCurrency(-1234.56, { decimal: true });
|
|
297
|
-
* // ➔ "-1.234,56"
|
|
298
|
-
*
|
|
299
|
-
* // --- Negative numbers (brackets) ---
|
|
300
|
-
* formatCurrency(-1234.56, {
|
|
301
|
-
* decimal: true,
|
|
302
|
-
* negativeFormat: "brackets"
|
|
303
|
-
* });
|
|
304
|
-
* // ➔ "(1.234,56)"
|
|
305
|
-
*
|
|
306
|
-
* // --- Negative numbers (custom object style) ---
|
|
307
|
-
* formatCurrency(-1234.56, {
|
|
308
|
-
* decimal: true,
|
|
309
|
-
* negativeFormat: { style: "brackets", space: true }
|
|
310
|
-
* });
|
|
311
|
-
* // ➔ "( 1.234,56 )"
|
|
312
|
-
*
|
|
313
|
-
* // --- Negative numbers (custom function) ---
|
|
314
|
-
* formatCurrency(-1234.56, {
|
|
315
|
-
* decimal: true,
|
|
316
|
-
* negativeFormat: { custom: (val) => `NEGATIVE[${val}]` }
|
|
317
|
-
* });
|
|
318
|
-
* // ➔ "NEGATIVE[1.234,56]"
|
|
319
|
-
*
|
|
320
|
-
* // --- With prefix currency ---
|
|
321
|
-
* formatCurrency(1234.56, {
|
|
322
|
-
* decimal: true,
|
|
323
|
-
* suffixCurrency: "Rp "
|
|
324
|
-
* });
|
|
325
|
-
* // ➔ "Rp 1.234,56"
|
|
326
|
-
*
|
|
327
|
-
* // --- With suffix decimal ---
|
|
328
|
-
* formatCurrency(1234.56, {
|
|
329
|
-
* decimal: true,
|
|
330
|
-
* suffixDecimal: ".-"
|
|
331
|
-
* });
|
|
332
|
-
* // ➔ "1.234,56.-"
|
|
333
|
-
*
|
|
334
|
-
* // --- With suffix currency + suffix decimal ---
|
|
335
|
-
* formatCurrency(1234.56, {
|
|
336
|
-
* decimal: true,
|
|
337
|
-
* suffixCurrency: "Rp ",
|
|
338
|
-
* suffixDecimal: ".-"
|
|
339
|
-
* });
|
|
340
|
-
* // ➔ "Rp 1.234,56.-"
|
|
341
|
-
*
|
|
342
|
-
* // --- Custom separators ---
|
|
343
|
-
* formatCurrency(1234567.89, {
|
|
344
|
-
* decimal: true,
|
|
345
|
-
* separator: "'",
|
|
346
|
-
* separatorDecimals: "."
|
|
347
|
-
* });
|
|
348
|
-
* // ➔ "1'234'567.89"
|
|
349
|
-
*
|
|
350
|
-
* // --- Rounding: ceil ---
|
|
351
|
-
* formatCurrency(1234.561, {
|
|
352
|
-
* decimal: true,
|
|
353
|
-
* roundedDecimal: "ceil"
|
|
354
|
-
* });
|
|
355
|
-
* // ➔ "1.234,57"
|
|
356
|
-
*
|
|
357
|
-
* // --- Rounding: floor ---
|
|
358
|
-
* formatCurrency(1234.569, {
|
|
359
|
-
* decimal: true,
|
|
360
|
-
* roundedDecimal: "floor"
|
|
361
|
-
* });
|
|
362
|
-
* // ➔ "1.234,56"
|
|
277
|
+
* ---
|
|
278
|
+
* @throws **{@link TypeError | `TypeError`}** ***If:***
|
|
279
|
+
* - The `value` is not string or number.
|
|
280
|
+
* - Cannot parse to valid number.
|
|
363
281
|
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
282
|
+
* ---
|
|
283
|
+
* @returns {string}
|
|
284
|
+
* ***Nicely formatted currency string, examples:***
|
|
285
|
+
* - `"15.000,10"`.
|
|
286
|
+
* - `"Rp 15.000,10.-"`.
|
|
287
|
+
* - `"15'000.10 USD"`.
|
|
288
|
+
* - `"12,34,567.89"`.
|
|
370
289
|
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* // ➔ "1.235"
|
|
374
|
-
*
|
|
375
|
-
* // --- Edge case: messy input with dots & commas ---
|
|
376
|
-
* formatCurrency("1.121.234,561", {
|
|
377
|
-
* decimal: true,
|
|
378
|
-
* totalDecimal: 2,
|
|
379
|
-
* roundedDecimal: "ceil",
|
|
380
|
-
* suffixCurrency: "Rp ",
|
|
381
|
-
* negativeFormat: { style: "brackets" }
|
|
382
|
-
* });
|
|
383
|
-
* // ➔ "(Rp 1.121.234,57)"
|
|
290
|
+
* ---
|
|
291
|
+
* @example
|
|
384
292
|
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
293
|
+
* 1. #### Number input (default, decimals off):
|
|
294
|
+
* ```ts
|
|
295
|
+
* formatCurrency(1234567.89);
|
|
296
|
+
* // ➔ "1.234.567"
|
|
297
|
+
* ```
|
|
298
|
+
* ---
|
|
299
|
+
* 2. #### Decimals enabled:
|
|
300
|
+
* ```ts
|
|
301
|
+
* formatCurrency(1234567.89, { decimal: true });
|
|
302
|
+
* // ➔ "1.234.567,89"
|
|
303
|
+
* ```
|
|
304
|
+
* ---
|
|
305
|
+
* 3. #### Indian format:
|
|
306
|
+
* ```ts
|
|
307
|
+
* formatCurrency(1234567.89, {
|
|
308
|
+
* decimal: true,
|
|
309
|
+
* indianFormat: true
|
|
310
|
+
* });
|
|
311
|
+
* // ➔ "12,34,567.89"
|
|
312
|
+
* ```
|
|
313
|
+
* ---
|
|
314
|
+
* 4. #### String input (Indonesian style):
|
|
315
|
+
* ```ts
|
|
316
|
+
* formatCurrency("Rp 15.000,21", {
|
|
317
|
+
* decimal: true
|
|
318
|
+
* });
|
|
319
|
+
* // ➔ "15.000,21"
|
|
320
|
+
* ```
|
|
321
|
+
* ---
|
|
322
|
+
* 5. #### String input (US style):
|
|
323
|
+
* ```ts
|
|
324
|
+
* formatCurrency("$12,345.60", {
|
|
325
|
+
* decimal: true
|
|
326
|
+
* });
|
|
327
|
+
* // ➔ "12.345,60"
|
|
328
|
+
* ```
|
|
329
|
+
* ---
|
|
330
|
+
* 6. #### String input (Swiss style):
|
|
331
|
+
* ```ts
|
|
332
|
+
* formatCurrency("CHF 12'345.60", {
|
|
333
|
+
* decimal: true
|
|
334
|
+
* });
|
|
335
|
+
* // ➔ "12'345,60"
|
|
336
|
+
* ```
|
|
337
|
+
* ---
|
|
338
|
+
* 7. #### String input (Indian style):
|
|
339
|
+
* ```ts
|
|
340
|
+
* formatCurrency("1,23,456.78", {
|
|
341
|
+
* decimal: true,
|
|
342
|
+
* indianFormat: true
|
|
343
|
+
* });
|
|
344
|
+
* // ➔ "12,34,567.78"
|
|
345
|
+
* ```
|
|
346
|
+
* ---
|
|
347
|
+
* 8. #### Negative numbers (dash):
|
|
348
|
+
* ```ts
|
|
349
|
+
* formatCurrency(-1234.56, {
|
|
350
|
+
* decimal: true
|
|
351
|
+
* });
|
|
352
|
+
* // ➔ "-1.234,56"
|
|
353
|
+
* ```
|
|
354
|
+
* ---
|
|
355
|
+
* 9. #### Negative numbers (brackets):
|
|
356
|
+
* ```ts
|
|
357
|
+
* formatCurrency(-1234.56, {
|
|
358
|
+
* decimal: true,
|
|
359
|
+
* negativeFormat: "brackets"
|
|
360
|
+
* });
|
|
361
|
+
* // ➔ "(1.234,56)"
|
|
362
|
+
* ```
|
|
363
|
+
* ---
|
|
364
|
+
* 10. #### Negative numbers (custom object style):
|
|
365
|
+
* ```ts
|
|
366
|
+
* formatCurrency(-1234.56, {
|
|
367
|
+
* decimal: true,
|
|
368
|
+
* negativeFormat: {
|
|
369
|
+
* style: "brackets",
|
|
370
|
+
* space: true
|
|
371
|
+
* }
|
|
372
|
+
* });
|
|
373
|
+
* // ➔ "( 1.234,56 )"
|
|
374
|
+
* ```
|
|
375
|
+
* ---
|
|
376
|
+
* 11. #### Negative numbers (custom function):
|
|
377
|
+
* ```ts
|
|
378
|
+
* formatCurrency(-1234.56, {
|
|
379
|
+
* decimal: true,
|
|
380
|
+
* negativeFormat: {
|
|
381
|
+
* custom: (val) => `NEGATIVE[${val}]`
|
|
382
|
+
* }
|
|
383
|
+
* });
|
|
384
|
+
* // ➔ "NEGATIVE[1.234,56]"
|
|
385
|
+
* ```
|
|
386
|
+
* ---
|
|
387
|
+
* 12. #### With prefix currency:
|
|
388
|
+
* ```ts
|
|
389
|
+
* formatCurrency(1234.56, {
|
|
390
|
+
* decimal: true,
|
|
391
|
+
* suffixCurrency: "Rp "
|
|
392
|
+
* });
|
|
393
|
+
* // ➔ "Rp 1.234,56"
|
|
394
|
+
* ```
|
|
395
|
+
* ---
|
|
396
|
+
* 13. #### With suffix decimal:
|
|
397
|
+
* ```ts
|
|
398
|
+
* formatCurrency(1234.56, {
|
|
399
|
+
* decimal: true,
|
|
400
|
+
* suffixDecimal: ".-"
|
|
401
|
+
* });
|
|
402
|
+
* // ➔ "1.234,56.-"
|
|
403
|
+
* ```
|
|
404
|
+
* ---
|
|
405
|
+
* 14. #### With suffix currency + suffix decimal:
|
|
406
|
+
* ```ts
|
|
407
|
+
* formatCurrency(1234.56, {
|
|
408
|
+
* decimal: true,
|
|
409
|
+
* suffixCurrency: "Rp ",
|
|
410
|
+
* suffixDecimal: ".-"
|
|
411
|
+
* });
|
|
412
|
+
* // ➔ "Rp 1.234,56.-"
|
|
413
|
+
* ```
|
|
414
|
+
* ---
|
|
415
|
+
* 15. #### Custom separators:
|
|
416
|
+
* ```ts
|
|
417
|
+
* formatCurrency(1234567.89, {
|
|
418
|
+
* decimal: true,
|
|
419
|
+
* separator: "'",
|
|
420
|
+
* separatorDecimals: "."
|
|
421
|
+
* });
|
|
422
|
+
* // ➔ "1'234'567.89"
|
|
423
|
+
* ```
|
|
424
|
+
* ---
|
|
425
|
+
* 16. #### Rounding: ceil:
|
|
426
|
+
* ```ts
|
|
427
|
+
* formatCurrency(1234.561, {
|
|
428
|
+
* decimal: true,
|
|
429
|
+
* roundedDecimal: "ceil"
|
|
430
|
+
* });
|
|
431
|
+
* // ➔ "1.234,57"
|
|
432
|
+
* ```
|
|
433
|
+
* ---
|
|
434
|
+
* 17. #### Rounding: floor:
|
|
435
|
+
* ```ts
|
|
436
|
+
* formatCurrency(1234.569, {
|
|
437
|
+
* decimal: true,
|
|
438
|
+
* roundedDecimal: "floor"
|
|
439
|
+
* });
|
|
440
|
+
* // ➔ "1.234,56"
|
|
441
|
+
* ```
|
|
442
|
+
* ---
|
|
443
|
+
* 18. #### Rounding: truncate:
|
|
444
|
+
* ```ts
|
|
445
|
+
* formatCurrency(1234.569, {
|
|
446
|
+
* decimal: true,
|
|
447
|
+
* roundedDecimal: false
|
|
448
|
+
* });
|
|
449
|
+
* // ➔ "1.234,56"
|
|
450
|
+
* ```
|
|
451
|
+
* ---
|
|
452
|
+
* 19. #### Force no decimals:
|
|
453
|
+
* ```ts
|
|
454
|
+
* formatCurrency(1234.567, {
|
|
455
|
+
* decimal: false
|
|
456
|
+
* });
|
|
457
|
+
* // ➔ "1.235"
|
|
458
|
+
* ```
|
|
459
|
+
* ---
|
|
460
|
+
* 20. #### Edge case: messy input with dots & commas:
|
|
461
|
+
* ```ts
|
|
462
|
+
* formatCurrency("1.121.234,561", {
|
|
463
|
+
* decimal: true,
|
|
464
|
+
* totalDecimal: 2,
|
|
465
|
+
* roundedDecimal: "ceil",
|
|
466
|
+
* suffixCurrency: "Rp ",
|
|
467
|
+
* negativeFormat: {
|
|
468
|
+
* style: "brackets"
|
|
469
|
+
* }
|
|
470
|
+
* });
|
|
471
|
+
* // ➔ "(Rp 1.121.234,57)"
|
|
472
|
+
* ```
|
|
473
|
+
* ---
|
|
474
|
+
* 21. #### Edge case: integer string input:
|
|
475
|
+
* ```ts
|
|
476
|
+
* formatCurrency("1.121.234", {
|
|
477
|
+
* decimal: true,
|
|
478
|
+
* suffixCurrency: "Rp ",
|
|
479
|
+
* roundedDecimal: "ceil"
|
|
480
|
+
* });
|
|
481
|
+
* // ➔ "Rp 1.121.234,00"
|
|
482
|
+
* ```
|
|
392
483
|
*/
|
|
393
484
|
declare const formatCurrency: (value: string | number, options?: FormatCurrencyOptions) => string;
|
|
394
485
|
/** ----------------------------------------------------------
|
|
395
486
|
* * ***Utility: `formatNumber`.***
|
|
396
|
-
*
|
|
487
|
+
* -----------------------------------------------------------
|
|
397
488
|
* **Formats a number or numeric string by adding a custom separator
|
|
398
489
|
* every three digits (thousands separator), and intelligently flips
|
|
399
490
|
* the decimal separator according to the chosen separator.**
|
|
491
|
+
*
|
|
492
|
+
* ---
|
|
400
493
|
* - **Features:**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
494
|
+
* - Converts a number to string before formatting.
|
|
495
|
+
* - Defaults to using `,` as the thousands separator.
|
|
496
|
+
* - If `.` is used as the separator, the decimal will automatically
|
|
497
|
+
* become `,`, and vice versa.
|
|
498
|
+
* - Handles input with existing formatting (e.g. "1,234,567.89") and normalizes it.
|
|
499
|
+
* - Supports custom separators, including spaces.
|
|
500
|
+
* - Preserves decimals even if more than 2 digits.
|
|
501
|
+
*
|
|
502
|
+
* ---
|
|
408
503
|
* @param {string | number} value - The numeric value or string to format, can be plain numbers, or already formatted strings like `"1,234,567.89"`.
|
|
409
504
|
* @param {string} [separator=","] - The thousands separator to use, examples: `","` ***(default)***, `"."`, `" "`, etc.
|
|
505
|
+
*
|
|
506
|
+
* ---
|
|
507
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not a string or number, or `separator` is not a string.
|
|
508
|
+
*
|
|
509
|
+
* ---
|
|
410
510
|
* @returns {string} The formatted string with thousands separators and
|
|
411
511
|
* appropriate decimal separator.
|
|
412
|
-
*
|
|
512
|
+
*
|
|
513
|
+
* ---
|
|
413
514
|
* @example
|
|
414
515
|
* formatNumber(1000000);
|
|
415
516
|
* // ➔ "1,000,000"
|
|
@@ -440,163 +541,198 @@ declare const formatCurrency: (value: string | number, options?: FormatCurrencyO
|
|
|
440
541
|
*/
|
|
441
542
|
declare const formatNumber: (value: string | number, separator?: string) => string;
|
|
442
543
|
/** -------------------------------------------------------
|
|
443
|
-
* * ***Output format mode for {@link formatPhoneNumber
|
|
444
|
-
*
|
|
445
|
-
* - `'E.164'` ➔ `+6281234567890
|
|
446
|
-
* - `'RFC3966'` ➔ `tel:+62-812-3456-7890
|
|
447
|
-
* - `'NATIONAL'` ➔ `0812 3456 7890
|
|
448
|
-
* - `'INTERNATIONAL'` ➔ `+62 812 3456 7890
|
|
544
|
+
* * ***Output format mode for {@link formatPhoneNumber | `formatPhoneNumber`}.***
|
|
545
|
+
* --------------------------------------------------------
|
|
546
|
+
* - `'E.164'` ➔ `+6281234567890`.
|
|
547
|
+
* - `'RFC3966'` ➔ `tel:+62-812-3456-7890`.
|
|
548
|
+
* - `'NATIONAL'` ➔ `0812 3456 7890`.
|
|
549
|
+
* - `'INTERNATIONAL'` ➔ `+62 812 3456 7890`.
|
|
449
550
|
*/
|
|
450
551
|
type OutputFormat = ExtractStrict<NumberFormat, "INTERNATIONAL" | "NATIONAL" | "RFC3966" | "E.164">;
|
|
451
552
|
/** -------------------------------------------------------
|
|
452
|
-
* * ***Single input value for {@link formatPhoneNumber
|
|
453
|
-
*
|
|
454
|
-
* -
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
553
|
+
* * ***Single input value for {@link formatPhoneNumber | `formatPhoneNumber`}.***
|
|
554
|
+
* --------------------------------------------------------
|
|
555
|
+
* - ***Accepts:***
|
|
556
|
+
* - `string` — e.g. `"0812 3456 7890"`.
|
|
557
|
+
* - `number` — e.g. `81234567890`.
|
|
558
|
+
* - `null` or `undefined` — represents no input.
|
|
559
|
+
*
|
|
560
|
+
* ---
|
|
561
|
+
* - ***Notes***
|
|
562
|
+
* - The function normalizes all **non-digit characters** (spaces, dots, dashes,
|
|
563
|
+
* parentheses, etc.) before validation/formatting.
|
|
564
|
+
* - When you pass a `number`, any **leading zeros are lost by JavaScript**.
|
|
565
|
+
* - Prefer using a `string` if the number may begin with `0`.
|
|
566
|
+
* - E.164 international standard allows **up to 15 digits** (not counting `+`).
|
|
464
567
|
*/
|
|
465
568
|
type ValueFormatPhoneNumber = string | number | null | undefined;
|
|
466
569
|
/** -------------------------------------------------------
|
|
467
|
-
* * ***Base option set for {@link formatPhoneNumber
|
|
468
|
-
*
|
|
570
|
+
* * ***Base option set for {@link formatPhoneNumber | `formatPhoneNumber`}.***
|
|
571
|
+
* --------------------------------------------------------
|
|
469
572
|
* **All properties are optional.**
|
|
573
|
+
*
|
|
574
|
+
* ---
|
|
470
575
|
* @description
|
|
471
576
|
* Defaults apply when a property is omitted or `undefined`.
|
|
472
577
|
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
578
|
+
* ---
|
|
579
|
+
* - ***⚠️ Overload-aware notes:***
|
|
580
|
+
* - If `checkValidOnly` is `true`, **all other properties are ignored**.
|
|
581
|
+
* - If `takeNumberOnly` is `true`, **all formatting properties are ignored**.
|
|
582
|
+
* - The leading `+` is **recommended** but not required;
|
|
583
|
+
* the regex will still validate numbers without `+`
|
|
584
|
+
* as long as the digit count ≤ **15**.
|
|
479
585
|
*/
|
|
480
586
|
type FormatPhoneNumberMain = {
|
|
481
587
|
/** -------------------------------------------------------
|
|
482
588
|
* * ***Separator for formatted output.***
|
|
483
|
-
*
|
|
589
|
+
* --------------------------------------------------------
|
|
484
590
|
* **Defines the string used to separate groups of digits**
|
|
485
591
|
* in the formatted phone number.
|
|
486
|
-
* - **Default:** `" "`.
|
|
487
|
-
* - **Executed only when:**
|
|
488
|
-
* - Parameter options `checkValidOnly` and `takeNumberOnly` are both `false`.
|
|
489
|
-
* - (This option is ignored if either `checkValidOnly` or `takeNumberOnly` is `true`.)
|
|
490
|
-
* - **Behavior:**
|
|
491
|
-
* - The formatter inserts this separator between number blocks
|
|
492
|
-
* according to the selected `outputFormat`.
|
|
493
|
-
* @default " "
|
|
494
|
-
* @example
|
|
495
|
-
* ```ts
|
|
496
|
-
* // Using dash as separator
|
|
497
|
-
* formatPhoneNumber("081234567890", { defaultCountry: "ID", separator: "-" });
|
|
498
|
-
* // ➔ "+62 812-3456-7890"
|
|
499
592
|
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
593
|
+
* ---
|
|
594
|
+
* - ***Executed only when:***
|
|
595
|
+
* - Parameter options `checkValidOnly` and `takeNumberOnly` are both `false`, *(This option is ignored if either `checkValidOnly` or `takeNumberOnly` is `true`)*.
|
|
596
|
+
* - ***DefaultValue:*** `" "`.
|
|
597
|
+
* - ***Behavior:***
|
|
598
|
+
* - The formatter inserts this separator between number blocks
|
|
599
|
+
* according to the selected `outputFormat`.
|
|
600
|
+
*
|
|
601
|
+
* ---
|
|
602
|
+
* @default
|
|
603
|
+
* ```ts
|
|
604
|
+
* " "
|
|
503
605
|
* ```
|
|
606
|
+
*
|
|
607
|
+
* ---
|
|
608
|
+
* @example
|
|
609
|
+
*
|
|
610
|
+
* 1. #### Using dash as separator:
|
|
611
|
+
* ```ts
|
|
612
|
+
* formatPhoneNumber("081234567890", { defaultCountry: "ID", separator: "-" });
|
|
613
|
+
* // ➔ "+62 812-3456-7890"
|
|
614
|
+
* ```
|
|
615
|
+
* ---
|
|
616
|
+
* 2. #### Using space as separator:
|
|
617
|
+
* ```ts
|
|
618
|
+
* formatPhoneNumber("(151) 2345-6789", { defaultCountry: "DE", separator: " " });
|
|
619
|
+
* // ➔ "+49 1512 3456789"
|
|
620
|
+
* ```
|
|
504
621
|
*/
|
|
505
622
|
separator?: string;
|
|
506
623
|
/** -------------------------------------------------------
|
|
507
624
|
* * ***Output format style for the returned phone number.***
|
|
508
|
-
*
|
|
625
|
+
* --------------------------------------------------------
|
|
509
626
|
* **Determines how the formatted phone number string is returned.**
|
|
510
627
|
*
|
|
511
|
-
*
|
|
512
|
-
* -
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
628
|
+
* ---
|
|
629
|
+
* - ***Applicable only when:***
|
|
630
|
+
* - Parameter options `checkValidOnly` and `takeNumberOnly`
|
|
631
|
+
* are both **`false`**, *(Ignored if either of those options is `true`)*.
|
|
632
|
+
* - ***DefaultValue:*** `"INTERNATIONAL"`.
|
|
633
|
+
* - ***Supported values (from {@link NumberFormat | `NumberFormat`}):***
|
|
634
|
+
* - `"NATIONAL"` – Local/national format, e.g. `0812 3456 7890`.
|
|
635
|
+
* - `"INTERNATIONAL"` – International format with leading plus, e.g. `+62 812 3456 7890`.
|
|
636
|
+
* - `"E.164"` – Compact E.164 format, e.g. `+6281234567890`.
|
|
637
|
+
* - `"RFC3966"` – RFC 3966 URI format, e.g. `tel:+62-812-3456-7890`.
|
|
516
638
|
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
* - `"INTERNATIONAL"` – International format with leading plus, e.g. `+62 812 3456 7890`.
|
|
520
|
-
* - `"E.164"` – Compact E.164 format, e.g. `+6281234567890`.
|
|
521
|
-
* - `"RFC3966"` – RFC 3966 URI format, e.g. `tel:+62-812-3456-7890`.
|
|
522
|
-
*
|
|
523
|
-
* @default "INTERNATIONAL"
|
|
524
|
-
* @example
|
|
639
|
+
* ---
|
|
640
|
+
* @default
|
|
525
641
|
* ```ts
|
|
526
|
-
*
|
|
527
|
-
* formatPhoneNumber("+62 81234567890", { outputFormat: "NATIONAL" });
|
|
528
|
-
* // ➔ "0812 3456 7890"
|
|
529
|
-
*
|
|
530
|
-
* // Returns an E.164-format string
|
|
531
|
-
* formatPhoneNumber("+62 81234567890", { outputFormat: "E.164" });
|
|
532
|
-
* // ➔ "+6281234567890"
|
|
642
|
+
* "INTERNATIONAL"
|
|
533
643
|
* ```
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* 1. #### Returns a national-format string:
|
|
647
|
+
* ```ts
|
|
648
|
+
* formatPhoneNumber("+62 81234567890", { outputFormat: "NATIONAL" });
|
|
649
|
+
* // ➔ "0812 3456 7890"
|
|
650
|
+
* ```
|
|
651
|
+
* ---
|
|
652
|
+
* 2. #### Returns an E.164-format string:
|
|
653
|
+
* ```ts
|
|
654
|
+
* formatPhoneNumber("+62 81234567890", { outputFormat: "E.164" });
|
|
655
|
+
* // ➔ "+6281234567890"
|
|
656
|
+
* ```
|
|
534
657
|
*/
|
|
535
658
|
outputFormat?: OutputFormat;
|
|
536
659
|
/** -------------------------------------------------------
|
|
537
660
|
* * ***Prepend a plus sign and country calling code.***
|
|
538
|
-
*
|
|
661
|
+
* --------------------------------------------------------
|
|
539
662
|
* **Forces the returned phone number to start with a leading `+`
|
|
540
663
|
* followed by the detected country calling code (e.g. `+63`, `+1`).**
|
|
541
|
-
* - **Default:** `true`.
|
|
542
|
-
* - **Executed only when:**
|
|
543
|
-
* - Parameter options `outputFormat` is set to `"INTERNATIONAL"`.
|
|
544
|
-
* - (This option is ignored for `"NATIONAL"`, `"E.164"` or `"RFC3966"` formats.).
|
|
545
|
-
* - **Applicable when:**
|
|
546
|
-
* - You want to guarantee that the result
|
|
547
|
-
* always contains a plus sign and country code, regardless of
|
|
548
|
-
* the selected `outputFormat`.
|
|
549
|
-
* - **Behavior:**
|
|
550
|
-
* - When `true`, the formatter ensures the output begins with
|
|
551
|
-
* a `+` and the correct country code.
|
|
552
|
-
* - When `false`, the output follows the chosen `outputFormat`
|
|
553
|
-
* without forcing a `+` prefix.
|
|
554
|
-
* @default true
|
|
555
|
-
* @example
|
|
556
|
-
* ```ts
|
|
557
|
-
* // Automatically adds +63 (default: `true`) even if input is local format
|
|
558
|
-
* formatPhoneNumber("09171234567", {
|
|
559
|
-
* country: "PH",
|
|
560
|
-
* prependPlusCountryCode: true
|
|
561
|
-
* });
|
|
562
|
-
* // ➔ "+63 917 123 4567"
|
|
563
664
|
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
665
|
+
* ---
|
|
666
|
+
* - ***Behavior:***
|
|
667
|
+
* - When `true`, the formatter ensures the output begins with
|
|
668
|
+
* a `+` and the correct country code.
|
|
669
|
+
* - When `false`, the output follows the chosen `outputFormat`
|
|
670
|
+
* without forcing a `+` prefix.
|
|
671
|
+
* - ***DefaultValue:*** `true`.
|
|
672
|
+
* - ***Executed only when:***
|
|
673
|
+
* - Parameter options `outputFormat` is set
|
|
674
|
+
* to `"INTERNATIONAL"`, *(This option is ignored for `"NATIONAL"`, `"E.164"` or `"RFC3966"` formats.)*.
|
|
675
|
+
* - ***Applicable when:***
|
|
676
|
+
* - You want to guarantee that the result
|
|
677
|
+
* always contains a plus sign and country code, regardless of
|
|
678
|
+
* the selected `outputFormat`.
|
|
569
679
|
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
* outputFormat: "NATIONAL"
|
|
575
|
-
* });
|
|
576
|
-
* // ➔ "0917 123 4567"
|
|
680
|
+
* ---
|
|
681
|
+
* @default
|
|
682
|
+
* ```ts
|
|
683
|
+
* true
|
|
577
684
|
* ```
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* 1. #### Automatically adds +63 (default: `true`) even if input is local format:
|
|
688
|
+
* ```ts
|
|
689
|
+
* formatPhoneNumber("09171234567", {
|
|
690
|
+
* country: "PH",
|
|
691
|
+
* prependPlusCountryCode: true
|
|
692
|
+
* });
|
|
693
|
+
* // ➔ "+63 917 123 4567"
|
|
694
|
+
*
|
|
695
|
+
* formatPhoneNumber("09171234567", {
|
|
696
|
+
* country: "PH",
|
|
697
|
+
* prependPlusCountryCode: false
|
|
698
|
+
* });
|
|
699
|
+
* // ➔ "63 917 123 4567"
|
|
700
|
+
* ```
|
|
701
|
+
* ---
|
|
702
|
+
* 2. #### Leaves number in national format (no plus sign):
|
|
703
|
+
* ```ts
|
|
704
|
+
* formatPhoneNumber("+63 9171234567", {
|
|
705
|
+
* country: "PH",
|
|
706
|
+
* prependPlusCountryCode: false,
|
|
707
|
+
* outputFormat: "NATIONAL"
|
|
708
|
+
* });
|
|
709
|
+
* // ➔ "0917 123 4567"
|
|
710
|
+
* ```
|
|
578
711
|
*/
|
|
579
712
|
prependPlusCountryCode?: boolean;
|
|
580
713
|
/** -------------------------------------------------------
|
|
581
714
|
* * ***Characters before the country code (e.g. `"("`).***
|
|
582
|
-
*
|
|
715
|
+
* --------------------------------------------------------
|
|
583
716
|
* **Adds a custom string that appears **immediately before** the
|
|
584
717
|
* international country calling code when formatting.**
|
|
585
|
-
*
|
|
586
|
-
* -
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
* -
|
|
597
|
-
*
|
|
598
|
-
*
|
|
718
|
+
*
|
|
719
|
+
* - ***Behavior:***
|
|
720
|
+
* - **Active only when:**
|
|
721
|
+
* - `checkValidOnly` is **false**,
|
|
722
|
+
* - `takeNumberOnly` is **false**, and
|
|
723
|
+
* - `outputFormat` is `"INTERNATIONAL"`.
|
|
724
|
+
* - **Ignored if:**
|
|
725
|
+
* - The value is an empty string *(after trimming)*,
|
|
726
|
+
* - `checkValidOnly` or `takeNumberOnly` is `true`,
|
|
727
|
+
* - `outputFormat` is not `"INTERNATIONAL"`,
|
|
728
|
+
* - `closingNumberCountry` is `undefined` or an empty string *(after trimming)*.
|
|
729
|
+
* - ***DefaultValue:*** `""` *(empty string)*.
|
|
730
|
+
* - ***Invalid input:***
|
|
731
|
+
* - Returns no effect if the phone number is invalid or not compatible
|
|
732
|
+
* with the selected `defaultCountry`.
|
|
733
|
+
*
|
|
599
734
|
* @default ""
|
|
735
|
+
*
|
|
600
736
|
* @example
|
|
601
737
|
* ```ts
|
|
602
738
|
* formatPhoneNumber("+63 9171234567", {
|
|
@@ -610,24 +746,33 @@ type FormatPhoneNumberMain = {
|
|
|
610
746
|
openingNumberCountry?: string;
|
|
611
747
|
/** -------------------------------------------------------
|
|
612
748
|
* * ***Characters after the country code (e.g. `")"`).***
|
|
613
|
-
*
|
|
749
|
+
* --------------------------------------------------------
|
|
614
750
|
* **Adds a custom string that appears **immediately after** the
|
|
615
751
|
* international country calling code when formatting.**
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
752
|
+
*
|
|
753
|
+
* ---
|
|
754
|
+
* - ***Behavior:***
|
|
755
|
+
* - **Active only when:**
|
|
756
|
+
* - `checkValidOnly` is **false**,
|
|
757
|
+
* - `takeNumberOnly` is **false**, and
|
|
758
|
+
* - `outputFormat` is `"INTERNATIONAL"`.
|
|
759
|
+
* - **Ignored if:**
|
|
760
|
+
* - The value is an empty string *(after trimming)*,
|
|
761
|
+
* - `checkValidOnly` or `takeNumberOnly` is `true`,
|
|
762
|
+
* - `outputFormat` is not `"INTERNATIONAL"`,
|
|
763
|
+
* - `openingNumberCountry` is `undefined` or an empty string *(after trimming)*.
|
|
764
|
+
* - ***DefaultValue:*** `""` *(empty string)*.
|
|
627
765
|
* - **Invalid input:**
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
766
|
+
* Returns no effect if the phone number is invalid or not compatible
|
|
767
|
+
* with the selected `defaultCountry`.
|
|
768
|
+
*
|
|
769
|
+
* ---
|
|
770
|
+
* @default
|
|
771
|
+
* ```ts
|
|
772
|
+
* ""
|
|
773
|
+
* ```
|
|
774
|
+
*
|
|
775
|
+
* ---
|
|
631
776
|
* @example
|
|
632
777
|
* ```ts
|
|
633
778
|
* formatPhoneNumber("+63 9171234567", {
|
|
@@ -641,28 +786,37 @@ type FormatPhoneNumberMain = {
|
|
|
641
786
|
closingNumberCountry?: string;
|
|
642
787
|
/** -------------------------------------------------------
|
|
643
788
|
* * ***Return only a boolean validity flag.***
|
|
644
|
-
*
|
|
789
|
+
* --------------------------------------------------------
|
|
790
|
+
*
|
|
791
|
+
* ---
|
|
645
792
|
* - ***Behavior:***
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* - ***DefaultValue
|
|
658
|
-
*
|
|
793
|
+
* - **Exclusive mode:**
|
|
794
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
795
|
+
* - Conflicts with `takeNumberOnly`:
|
|
796
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
797
|
+
* omitted or are ignored.
|
|
798
|
+
* - But if mistake passing props:
|
|
799
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
800
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
801
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
802
|
+
* - Output:
|
|
803
|
+
* - Boolean ➔ (`true` or `false`).
|
|
804
|
+
* - ***DefaultValue:*** `false`.
|
|
805
|
+
*
|
|
806
|
+
* ---
|
|
807
|
+
* @default
|
|
808
|
+
* ```ts
|
|
809
|
+
* false
|
|
810
|
+
* ```
|
|
811
|
+
*
|
|
812
|
+
* ---
|
|
659
813
|
* @example
|
|
660
814
|
* ```ts
|
|
661
|
-
* // Returns `true` if valid number and number with country code (no need `defaultCountry`)
|
|
815
|
+
* // Returns `true` if valid number and number with country code (no need `defaultCountry`).
|
|
662
816
|
* formatPhoneNumber("+63 912-123-4567", { checkValidOnly: true });
|
|
663
817
|
* // ➔ true
|
|
664
818
|
*
|
|
665
|
-
* // Returns `true` if valid number and number without country code but with `defaultCountry
|
|
819
|
+
* // Returns `true` if valid number and number without country code but with `defaultCountry`.
|
|
666
820
|
* formatPhoneNumber("213-373-4253", { defaultCountry: "US", checkValidOnly: true });
|
|
667
821
|
* // ➔ true
|
|
668
822
|
*
|
|
@@ -678,37 +832,46 @@ type FormatPhoneNumberMain = {
|
|
|
678
832
|
checkValidOnly?: boolean;
|
|
679
833
|
/** -------------------------------------------------------
|
|
680
834
|
* * ***Return only the digits of the phone number (local number only).***
|
|
681
|
-
*
|
|
835
|
+
* --------------------------------------------------------
|
|
682
836
|
* **Returns a string containing only numeric characters** from the **local number**,
|
|
683
837
|
* ignoring any country code, spaces, plus signs, or separators.
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
* `
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
838
|
+
*
|
|
839
|
+
* ---
|
|
840
|
+
* - ***Behavior:***
|
|
841
|
+
* - **Exclusive mode:**
|
|
842
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
843
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
844
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
845
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
846
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
847
|
+
* `checkValidOnly` takes priority and the function
|
|
848
|
+
* returns a `boolean`.
|
|
849
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
850
|
+
* and `takeNumberOnly` is `true`,
|
|
851
|
+
* the function returns a **numeric string of the local number**.
|
|
852
|
+
* - **Invalid input:**
|
|
853
|
+
* - If the input is invalid or cannot be parsed
|
|
854
|
+
* (e.g. not matching the `defaultCountry`),
|
|
855
|
+
* the function returns an **empty string** (`""`).
|
|
856
|
+
* - ***DefaultValue:*** `false`.
|
|
857
|
+
* - ***Output example:***
|
|
858
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
859
|
+
* - Invalid input ➔ `""`.
|
|
860
|
+
*
|
|
861
|
+
* ---
|
|
862
|
+
* @default
|
|
863
|
+
* ```ts
|
|
864
|
+
* false
|
|
865
|
+
* ```
|
|
866
|
+
*
|
|
867
|
+
* ---
|
|
705
868
|
* @example
|
|
706
869
|
* ```ts
|
|
707
|
-
* // Returns only digits of the local number with country code (no need `defaultCountry`)
|
|
870
|
+
* // Returns only digits of the local number with country code (no need `defaultCountry`).
|
|
708
871
|
* formatPhoneNumber("+63 912-123-4567", { takeNumberOnly: true });
|
|
709
872
|
* // ➔ "09121234567"
|
|
710
873
|
*
|
|
711
|
-
* // Returns only digits of the local number without country code but with `defaultCountry
|
|
874
|
+
* // Returns only digits of the local number without country code but with `defaultCountry`.
|
|
712
875
|
* formatPhoneNumber("213-373-4253", { defaultCountry: "US", takeNumberOnly: true });
|
|
713
876
|
* // ➔ "2133734253"
|
|
714
877
|
*
|
|
@@ -724,80 +887,106 @@ type FormatPhoneNumberMain = {
|
|
|
724
887
|
takeNumberOnly?: boolean;
|
|
725
888
|
/** -------------------------------------------------------
|
|
726
889
|
* * ***A "country code" is a two-letter ISO ([`ISO-3166-1 alpha-2`](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)) country code (like `"US"` | `"ID"` | `"DE"`).***
|
|
727
|
-
*
|
|
890
|
+
* --------------------------------------------------------
|
|
728
891
|
* **Used to interpret numbers without an explicit `+<countryCode>`.**
|
|
892
|
+
*
|
|
893
|
+
* ---
|
|
729
894
|
* - ***Behavior:***
|
|
730
|
-
*
|
|
731
|
-
*
|
|
895
|
+
* - Required if the input without country code (`+`).
|
|
896
|
+
* - Ignored if the input already starts with `+`.
|
|
732
897
|
* - ***Examples:***
|
|
733
898
|
* - `"ID"` ➔ Indonesian.
|
|
734
899
|
* - `"US"` ➔ United States.
|
|
735
900
|
* - `"GB"` ➔ United Kingdom.
|
|
736
901
|
* - ***DefaultValue: `undefined`***.
|
|
902
|
+
*
|
|
903
|
+
* ---
|
|
904
|
+
* @default
|
|
905
|
+
* ```ts
|
|
906
|
+
* undefined
|
|
907
|
+
* ```
|
|
908
|
+
*
|
|
909
|
+
* ---
|
|
737
910
|
* @example
|
|
738
911
|
* formatPhoneNumber("081234567890", { defaultCountry: "ID" });
|
|
739
|
-
* @default undefined
|
|
740
912
|
*/
|
|
741
913
|
defaultCountry?: CountryCode;
|
|
742
914
|
};
|
|
743
915
|
/** -------------------------------------------------------
|
|
744
|
-
* * ***Specialized options for the `transformPhoneNumber` variant of {@link formatPhoneNumber
|
|
745
|
-
*
|
|
916
|
+
* * ***Specialized options for the `transformPhoneNumber` variant of {@link formatPhoneNumber | `formatPhoneNumber`}.***
|
|
917
|
+
* --------------------------------------------------------
|
|
746
918
|
* **Ensures that `checkValidOnly` and `takeNumberOnly` are both
|
|
747
919
|
* forced to `false` when transforming/formatting.**
|
|
748
920
|
*
|
|
921
|
+
* ---
|
|
749
922
|
* This type is intended for scenarios where you **must** receive a formatted
|
|
750
923
|
* string as output and never a `boolean` or digit-only result.
|
|
751
924
|
*
|
|
752
|
-
*
|
|
925
|
+
* ---
|
|
926
|
+
* **Example Output:** `+62 812 3456 7890`.
|
|
753
927
|
*/
|
|
754
928
|
type FormatPhoneNumberTransform = OverrideTypes<FormatPhoneNumberMain, {
|
|
755
929
|
/** -------------------------------------------------------
|
|
756
930
|
* * ***Return only a boolean validity flag.***
|
|
757
|
-
*
|
|
931
|
+
* --------------------------------------------------------
|
|
758
932
|
* - ***Behavior:***
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
* - ***DefaultValue
|
|
771
|
-
*
|
|
933
|
+
* - **Exclusive mode:**
|
|
934
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
935
|
+
* - Conflicts with `takeNumberOnly`:
|
|
936
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
937
|
+
* omitted or are ignored.
|
|
938
|
+
* - But if mistake passing props:
|
|
939
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
940
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
941
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
942
|
+
* - Output:
|
|
943
|
+
* - Boolean ➔ (`true` or `false`).
|
|
944
|
+
* - ***DefaultValue:*** `false`.
|
|
945
|
+
*
|
|
946
|
+
* ---
|
|
947
|
+
* @default
|
|
948
|
+
* ```ts
|
|
949
|
+
* false
|
|
950
|
+
*
|
|
951
|
+
* ```
|
|
772
952
|
* @requires `false` or `undefined`
|
|
773
953
|
*/
|
|
774
954
|
checkValidOnly?: never;
|
|
775
955
|
/** -------------------------------------------------------
|
|
776
956
|
* * ***Return only the digits of the phone number (local number only).***
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
* ignoring any country code
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
957
|
+
* --------------------------------------------------------
|
|
958
|
+
* **`Returns a string containing only numeric characters` from the `local number`,
|
|
959
|
+
* ignoring any `country code`, `spaces`, `plus signs`, or `separators`.**
|
|
960
|
+
*
|
|
961
|
+
* ---
|
|
962
|
+
* - ***Behavior:***
|
|
963
|
+
* - **Exclusive mode:**
|
|
964
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
965
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
966
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
967
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
968
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
969
|
+
* `checkValidOnly` takes priority and the function
|
|
970
|
+
* returns a `boolean`.
|
|
971
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
972
|
+
* and `takeNumberOnly` is `true`,
|
|
973
|
+
* the function returns a **numeric string of the local number**.
|
|
974
|
+
* - **Invalid input:**
|
|
975
|
+
* - If the input is invalid or cannot be parsed
|
|
976
|
+
* (e.g. not matching the `defaultCountry`),
|
|
977
|
+
* the function returns an **empty string** (`""`).
|
|
978
|
+
* - ***DefaultValue:*** `false`.
|
|
979
|
+
* - ***Output example:***
|
|
980
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
981
|
+
* - Invalid input ➔ `""`.
|
|
982
|
+
*
|
|
983
|
+
* ---
|
|
984
|
+
* @default
|
|
985
|
+
* ```ts
|
|
986
|
+
* false
|
|
987
|
+
* ```
|
|
988
|
+
*
|
|
989
|
+
* ---
|
|
801
990
|
* @requires `false` or `undefined`
|
|
802
991
|
*/
|
|
803
992
|
takeNumberOnly?: never;
|
|
@@ -805,34 +994,37 @@ type FormatPhoneNumberTransform = OverrideTypes<FormatPhoneNumberMain, {
|
|
|
805
994
|
type NeverForRestFormatPhoneNumberTransform = {
|
|
806
995
|
/** -------------------------------------------------------
|
|
807
996
|
* * ***Not used in this mode **`(Never allowed in this mode)`**.***
|
|
808
|
-
*
|
|
997
|
+
* --------------------------------------------------------
|
|
809
998
|
* - ***Behavior:***
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
999
|
+
* - **Exclusive mode:**
|
|
1000
|
+
* - ⚠️ When `true`, all formatting options must be omitted or are ignored.
|
|
1001
|
+
* - Conflicts with `takeNumberOnly` and `checkValidOnly`:
|
|
1002
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1003
|
+
* `checkValidOnly` takes priority and the function
|
|
1004
|
+
* returns a `boolean`.
|
|
1005
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1006
|
+
* and `takeNumberOnly` is `true`,
|
|
1007
|
+
* the function returns a **numeric string of the local number**.
|
|
1008
|
+
*
|
|
1009
|
+
* ---
|
|
819
1010
|
* @requires `undefined`
|
|
820
1011
|
*/
|
|
821
1012
|
separator?: never;
|
|
822
1013
|
/** -------------------------------------------------------
|
|
823
1014
|
* * ***Not used in this mode **`(Never allowed in this mode)`**.***
|
|
824
|
-
*
|
|
1015
|
+
* --------------------------------------------------------
|
|
825
1016
|
* - ***Behavior:***
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
1017
|
+
* - **Exclusive mode:**
|
|
1018
|
+
* - ⚠️ When `true`, all formatting options must be omitted or are ignored.
|
|
1019
|
+
* - Conflicts with `takeNumberOnly` and `checkValidOnly`:
|
|
1020
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1021
|
+
* `checkValidOnly` takes priority and the function
|
|
1022
|
+
* returns a `boolean`.
|
|
1023
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1024
|
+
* and `takeNumberOnly` is `true`,
|
|
1025
|
+
* the function returns a **numeric string of the local number**.
|
|
835
1026
|
*
|
|
1027
|
+
* ---
|
|
836
1028
|
* @requires `undefined`
|
|
837
1029
|
*/
|
|
838
1030
|
openingNumberCountry?: never;
|
|
@@ -840,368 +1032,428 @@ type NeverForRestFormatPhoneNumberTransform = {
|
|
|
840
1032
|
* * ***Not used in this mode **`(Never allowed in this mode)`**.***
|
|
841
1033
|
* -------------------------------------------------------
|
|
842
1034
|
* - ***Behavior:***
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
1035
|
+
* - **Exclusive mode:**
|
|
1036
|
+
* - ⚠️ When `true`, all formatting options must be omitted or are ignored.
|
|
1037
|
+
* - Conflicts with `takeNumberOnly` and `checkValidOnly`:
|
|
1038
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1039
|
+
* `checkValidOnly` takes priority and the function
|
|
1040
|
+
* returns a `boolean`.
|
|
1041
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1042
|
+
* and `takeNumberOnly` is `true`,
|
|
1043
|
+
* the function returns a **numeric string of the local number**.
|
|
852
1044
|
*
|
|
1045
|
+
* ---
|
|
853
1046
|
* @requires `undefined`
|
|
854
1047
|
*/
|
|
855
1048
|
closingNumberCountry?: never;
|
|
856
1049
|
};
|
|
857
1050
|
/** -------------------------------------------------------
|
|
858
1051
|
* * ***Options subset for **validity-check mode** of
|
|
859
|
-
* {@link formatPhoneNumber
|
|
860
|
-
*
|
|
1052
|
+
* {@link formatPhoneNumber | `formatPhoneNumber`}.***
|
|
1053
|
+
* --------------------------------------------------------
|
|
861
1054
|
* Only `checkValidOnly` is allowed.
|
|
1055
|
+
*
|
|
1056
|
+
* ---
|
|
1057
|
+
* @description
|
|
862
1058
|
* All formatting-related properties are **intentionally disallowed**
|
|
863
1059
|
* to avoid mixing validation with formatting.
|
|
864
1060
|
*
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
*
|
|
868
|
-
*
|
|
1061
|
+
* ---
|
|
1062
|
+
* - **Example Usage:**
|
|
1063
|
+
* ```ts
|
|
1064
|
+
* formatPhoneNumber("+6281234567890", { checkValidOnly: true });
|
|
1065
|
+
* // ➔ boolean
|
|
1066
|
+
* ```
|
|
869
1067
|
*/
|
|
870
1068
|
type FormatPhoneNumberCheckValidOnly = Prettify<OverrideTypes<FormatPhoneNumberMain, {
|
|
871
1069
|
/** -------------------------------------------------------
|
|
872
1070
|
* * ***Return only a boolean validity flag.***
|
|
873
|
-
*
|
|
1071
|
+
* --------------------------------------------------------
|
|
874
1072
|
* - ***Behavior:***
|
|
875
|
-
*
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
* - ***DefaultValue
|
|
1073
|
+
* - **Exclusive mode:**
|
|
1074
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
1075
|
+
* - Conflicts with `takeNumberOnly`:
|
|
1076
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
1077
|
+
* omitted or are ignored.
|
|
1078
|
+
* - But if mistake passing props:
|
|
1079
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
1080
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
1081
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
1082
|
+
* - Output:
|
|
1083
|
+
* - Boolean ➔ (`true` or `false`).
|
|
1084
|
+
* - ***DefaultValue:*** `false`.
|
|
1085
|
+
*
|
|
1086
|
+
* ---
|
|
887
1087
|
* @default false
|
|
888
1088
|
*/
|
|
889
1089
|
checkValidOnly: true;
|
|
890
1090
|
/** -------------------------------------------------------
|
|
891
1091
|
* * ***Return only the digits of the phone number (local number only).***
|
|
892
|
-
*
|
|
1092
|
+
* --------------------------------------------------------
|
|
893
1093
|
* **Returns a string containing only numeric characters** from the **local number**,
|
|
894
1094
|
* ignoring any country code, spaces, plus signs, or separators.
|
|
895
|
-
*
|
|
896
|
-
* -
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
*
|
|
912
|
-
* -
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
1095
|
+
*
|
|
1096
|
+
* - ***Behavior:***
|
|
1097
|
+
* - **Exclusive mode:**
|
|
1098
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
1099
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
1100
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
1101
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
1102
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1103
|
+
* `checkValidOnly` takes priority and the function
|
|
1104
|
+
* returns a `boolean`.
|
|
1105
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1106
|
+
* and `takeNumberOnly` is `true`,
|
|
1107
|
+
* the function returns a **numeric string of the local number**.
|
|
1108
|
+
* - **Invalid input:**
|
|
1109
|
+
* - If the input is invalid or cannot be parsed
|
|
1110
|
+
* (e.g. not matching the `defaultCountry`),
|
|
1111
|
+
* the function returns an **empty string** (`""`).
|
|
1112
|
+
* - ***DefaultValue:*** `false`.
|
|
1113
|
+
* - ***Output example:***
|
|
1114
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
1115
|
+
* - Invalid input ➔ `""`.
|
|
1116
|
+
*
|
|
1117
|
+
* ---
|
|
1118
|
+
* @default ```ts
|
|
1119
|
+
* false
|
|
1120
|
+
* ```
|
|
1121
|
+
* ---
|
|
916
1122
|
* @requires `false` or `undefined`
|
|
917
1123
|
*/
|
|
918
1124
|
takeNumberOnly?: false;
|
|
919
1125
|
} & NeverForRestFormatPhoneNumberTransform>>;
|
|
920
1126
|
/** -------------------------------------------------------
|
|
921
|
-
* * ***Options subset for calling {@link formatPhoneNumber
|
|
1127
|
+
* * ***Options subset for calling {@link formatPhoneNumber | `formatPhoneNumber`} in
|
|
922
1128
|
* **digits-only mode**.***
|
|
923
|
-
*
|
|
1129
|
+
* --------------------------------------------------------
|
|
924
1130
|
* **Only `takeNumberOnly` is allowed; all other formatting options are
|
|
925
1131
|
* intentionally disallowed.**
|
|
926
1132
|
*
|
|
1133
|
+
* ---
|
|
927
1134
|
* Use this when you want a pure numeric string without any separators or country
|
|
928
1135
|
* decorations, but still want the function to normalize the input.
|
|
929
1136
|
*
|
|
930
|
-
*
|
|
1137
|
+
* ---
|
|
1138
|
+
* **Example Output:** `"6281234567890"`.
|
|
931
1139
|
*/
|
|
932
1140
|
type FormatPhoneNumberTakeNumberOnly = Prettify<OverrideTypes<FormatPhoneNumberMain, {
|
|
933
1141
|
/** -------------------------------------------------------
|
|
934
1142
|
* * ***Return only a boolean validity flag.***
|
|
935
|
-
*
|
|
1143
|
+
* --------------------------------------------------------
|
|
1144
|
+
*
|
|
936
1145
|
* - ***Behavior:***
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
* - ***DefaultValue
|
|
949
|
-
*
|
|
1146
|
+
* - **Exclusive mode:**
|
|
1147
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
1148
|
+
* - Conflicts with `takeNumberOnly`:
|
|
1149
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
1150
|
+
* omitted or are ignored.
|
|
1151
|
+
* - But if mistake passing props:
|
|
1152
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
1153
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
1154
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
1155
|
+
* - Output:
|
|
1156
|
+
* - Boolean ➔ (`true` or `false`).
|
|
1157
|
+
* - ***DefaultValue:*** `false`.
|
|
1158
|
+
*
|
|
1159
|
+
* ---
|
|
1160
|
+
* @default
|
|
1161
|
+
* ```ts
|
|
1162
|
+
* false
|
|
1163
|
+
* ```
|
|
1164
|
+
* ---
|
|
950
1165
|
* @requires `false` or `undefined`
|
|
951
1166
|
*/
|
|
952
1167
|
checkValidOnly?: false;
|
|
953
1168
|
/** -------------------------------------------------------
|
|
954
1169
|
* * ***Return only the digits of the phone number (local number only).***
|
|
955
|
-
*
|
|
1170
|
+
* --------------------------------------------------------
|
|
956
1171
|
* **Returns a string containing only numeric characters** from the **local number**,
|
|
957
1172
|
* ignoring any country code, spaces, plus signs, or separators.
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
*
|
|
961
|
-
*
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
* `
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
1173
|
+
*
|
|
1174
|
+
* ---
|
|
1175
|
+
* - ***Behavior:***
|
|
1176
|
+
* - **Exclusive mode:**
|
|
1177
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
1178
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
1179
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
1180
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
1181
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1182
|
+
* `checkValidOnly` takes priority and the function
|
|
1183
|
+
* returns a `boolean`.
|
|
1184
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1185
|
+
* and `takeNumberOnly` is `true`,
|
|
1186
|
+
* the function returns a **numeric string of the local number**.
|
|
1187
|
+
* - **Invalid input:**
|
|
1188
|
+
* - If the input is invalid or cannot be parsed
|
|
1189
|
+
* (e.g. not matching the `defaultCountry`),
|
|
1190
|
+
* the function returns an **empty string** (`""`).
|
|
1191
|
+
* - ***DefaultValue:*** `false`.
|
|
1192
|
+
* - ***Output example:***
|
|
1193
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
1194
|
+
* - Invalid input ➔ `""`.
|
|
1195
|
+
*
|
|
1196
|
+
* ---
|
|
978
1197
|
* @default false
|
|
979
1198
|
*/
|
|
980
1199
|
takeNumberOnly: true;
|
|
981
1200
|
} & NeverForRestFormatPhoneNumberTransform>>;
|
|
982
1201
|
/** -------------------------------------------------------
|
|
983
|
-
* * ***Options subset for calling {@link formatPhoneNumber
|
|
1202
|
+
* * ***Options subset for calling {@link formatPhoneNumber | `formatPhoneNumber`} force to **Validity-check Mode**.***
|
|
984
1203
|
* -------------------------------------------------------
|
|
985
1204
|
*/
|
|
986
1205
|
type FormatPhoneNumberAllPassing = OverrideTypes<FormatPhoneNumberMain, {
|
|
987
1206
|
/** -------------------------------------------------------
|
|
988
1207
|
* * ***Return only a boolean validity flag.***
|
|
989
|
-
*
|
|
1208
|
+
* --------------------------------------------------------
|
|
1209
|
+
*
|
|
990
1210
|
* - ***Behavior:***
|
|
991
|
-
*
|
|
992
|
-
*
|
|
993
|
-
*
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
*
|
|
997
|
-
*
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1002
|
-
* - ***DefaultValue
|
|
1211
|
+
* - **Exclusive mode:**
|
|
1212
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
1213
|
+
* - Conflicts with `takeNumberOnly`:
|
|
1214
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
1215
|
+
* omitted or are ignored.
|
|
1216
|
+
* - But if mistake passing props:
|
|
1217
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
1218
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
1219
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
1220
|
+
* - Output:
|
|
1221
|
+
* - Boolean ➔ (`true` or `false`).
|
|
1222
|
+
* - ***DefaultValue:*** `false`.
|
|
1223
|
+
*
|
|
1224
|
+
* ---
|
|
1003
1225
|
* @default false
|
|
1004
1226
|
*/
|
|
1005
1227
|
checkValidOnly: true;
|
|
1006
1228
|
/** -------------------------------------------------------
|
|
1007
1229
|
* * ***Return only the digits of the phone number (local number only).***
|
|
1008
|
-
*
|
|
1230
|
+
* --------------------------------------------------------
|
|
1009
1231
|
* **Returns a string containing only numeric characters** from the **local number**,
|
|
1010
1232
|
* ignoring any country code, spaces, plus signs, or separators.
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1019
|
-
* `
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
*
|
|
1031
|
-
*
|
|
1233
|
+
*
|
|
1234
|
+
* ---
|
|
1235
|
+
* - ***Behavior:***
|
|
1236
|
+
* - **Exclusive mode:**
|
|
1237
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
1238
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
1239
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
1240
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
1241
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1242
|
+
* `checkValidOnly` takes priority and the function
|
|
1243
|
+
* returns a `boolean`.
|
|
1244
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1245
|
+
* and `takeNumberOnly` is `true`,
|
|
1246
|
+
* the function returns a **numeric string of the local number**.
|
|
1247
|
+
* - **Invalid input:**
|
|
1248
|
+
* - If the input is invalid or cannot be parsed
|
|
1249
|
+
* (e.g. not matching the `defaultCountry`),
|
|
1250
|
+
* the function returns an **empty string** (`""`).
|
|
1251
|
+
* - ***DefaultValue:*** `false`.
|
|
1252
|
+
* - ***Output example:***
|
|
1253
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
1254
|
+
* - Invalid input ➔ `""`.
|
|
1255
|
+
*
|
|
1256
|
+
* ---
|
|
1257
|
+
* @default
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* false
|
|
1260
|
+
* ```
|
|
1261
|
+
*
|
|
1262
|
+
* ---
|
|
1032
1263
|
* @requires `false` or `undefined`
|
|
1033
1264
|
*/
|
|
1034
1265
|
takeNumberOnly: true;
|
|
1035
1266
|
}>;
|
|
1036
1267
|
/** -------------------------------------------------------
|
|
1037
|
-
* * ***Options subset for calling {@link formatPhoneNumber
|
|
1038
|
-
*
|
|
1268
|
+
* * ***Options subset for calling {@link formatPhoneNumber | `formatPhoneNumber`} force to **Validity-check Mode**.***
|
|
1269
|
+
* --------------------------------------------------------
|
|
1039
1270
|
*/
|
|
1040
1271
|
type FormatPhoneNumberAllPassingValidOnly = OverrideTypes<FormatPhoneNumberMain, {
|
|
1041
1272
|
/** -------------------------------------------------------
|
|
1042
1273
|
* * ***Return only a boolean validity flag.***
|
|
1043
|
-
*
|
|
1274
|
+
* --------------------------------------------------------
|
|
1275
|
+
*
|
|
1044
1276
|
* - ***Behavior:***
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1056
|
-
* - ***DefaultValue
|
|
1277
|
+
* - **Exclusive mode:**
|
|
1278
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
1279
|
+
* - Conflicts with `takeNumberOnly`:
|
|
1280
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
1281
|
+
* omitted or are ignored.
|
|
1282
|
+
* - But if mistake passing props:
|
|
1283
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
1284
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
1285
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
1286
|
+
* - Output:
|
|
1287
|
+
* - Boolean ➔ (`true` or `false`).
|
|
1288
|
+
* - ***DefaultValue:*** `false`.
|
|
1289
|
+
*
|
|
1290
|
+
* ---
|
|
1057
1291
|
* @default false
|
|
1058
1292
|
*/
|
|
1059
1293
|
checkValidOnly: true;
|
|
1060
1294
|
/** -------------------------------------------------------
|
|
1061
1295
|
* * ***Return only the digits of the phone number (local number only).***
|
|
1062
|
-
*
|
|
1296
|
+
* --------------------------------------------------------
|
|
1063
1297
|
* **Returns a string containing only numeric characters** from the **local number**,
|
|
1064
1298
|
* ignoring any country code, spaces, plus signs, or separators.
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1073
|
-
* `
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1081
|
-
*
|
|
1082
|
-
*
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1299
|
+
*
|
|
1300
|
+
* ---
|
|
1301
|
+
* - ***Behavior:***
|
|
1302
|
+
* - **Exclusive mode:**
|
|
1303
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
1304
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
1305
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
1306
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
1307
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1308
|
+
* `checkValidOnly` takes priority and the function
|
|
1309
|
+
* returns a `boolean`.
|
|
1310
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1311
|
+
* and `takeNumberOnly` is `true`,
|
|
1312
|
+
* the function returns a **numeric string of the local number**.
|
|
1313
|
+
* - **Invalid input:**
|
|
1314
|
+
* - If the input is invalid or cannot be parsed
|
|
1315
|
+
* (e.g. not matching the `defaultCountry`),
|
|
1316
|
+
* the function returns an **empty string** (`""`).
|
|
1317
|
+
* - ***DefaultValue:*** `false`.
|
|
1318
|
+
* - ***Output example:***
|
|
1319
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
1320
|
+
* - Invalid input ➔ `""`.
|
|
1321
|
+
*
|
|
1322
|
+
* ---
|
|
1323
|
+
* @default
|
|
1324
|
+
* ```ts
|
|
1325
|
+
* false
|
|
1326
|
+
* ```
|
|
1327
|
+
*
|
|
1328
|
+
* ---
|
|
1086
1329
|
* @requires `false` or `undefined`
|
|
1087
1330
|
*/
|
|
1088
1331
|
takeNumberOnly?: false;
|
|
1089
1332
|
}>;
|
|
1090
1333
|
/** -------------------------------------------------------
|
|
1091
|
-
* * ***Options subset for calling {@link formatPhoneNumber
|
|
1092
|
-
*
|
|
1334
|
+
* * ***Options subset for calling {@link formatPhoneNumber | `formatPhoneNumber`} force to **Digits-only Mode**.***
|
|
1335
|
+
* --------------------------------------------------------
|
|
1093
1336
|
*/
|
|
1094
1337
|
type FormatPhoneNumberAllPassingTakeOnly = OverrideTypes<FormatPhoneNumberMain, {
|
|
1095
1338
|
/** -------------------------------------------------------
|
|
1096
1339
|
* * ***Return only a boolean validity flag.***
|
|
1097
|
-
*
|
|
1340
|
+
* --------------------------------------------------------
|
|
1341
|
+
*
|
|
1098
1342
|
* - ***Behavior:***
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
* - ***DefaultValue
|
|
1111
|
-
*
|
|
1343
|
+
* - **Exclusive mode:**
|
|
1344
|
+
* - ⚠️ When `true`, all formatting options and `takeNumberOnly` must be omitted or are ignored.
|
|
1345
|
+
* - Conflicts with `takeNumberOnly`:
|
|
1346
|
+
* - ⚠️ When `checkValidOnly` is `true` and all formatting options and `takeNumberOnly` must be
|
|
1347
|
+
* omitted or are ignored.
|
|
1348
|
+
* - But if mistake passing props:
|
|
1349
|
+
* - ⚠️ When `checkValidOnly` is `true` and other of formatting options was passing:
|
|
1350
|
+
* - If `takeNumberOnly` is `true` or `false`:
|
|
1351
|
+
* - Will return a `boolean` because `checkValidOnly` is prioritize first.
|
|
1352
|
+
* - Output:
|
|
1353
|
+
* - Boolean ➔ (`true` or `false`).
|
|
1354
|
+
* - ***DefaultValue:*** `false`.
|
|
1355
|
+
*
|
|
1356
|
+
* ---
|
|
1357
|
+
* @default
|
|
1358
|
+
* ```ts
|
|
1359
|
+
* false
|
|
1360
|
+
* ```
|
|
1361
|
+
*
|
|
1362
|
+
* ---
|
|
1112
1363
|
* @requires `false` or `undefined`
|
|
1113
1364
|
*/
|
|
1114
1365
|
checkValidOnly?: false;
|
|
1115
1366
|
/** -------------------------------------------------------
|
|
1116
1367
|
* * ***Return only the digits of the phone number (local number only).***
|
|
1117
|
-
*
|
|
1368
|
+
* --------------------------------------------------------
|
|
1118
1369
|
* **Returns a string containing only numeric characters** from the **local number**,
|
|
1119
1370
|
* ignoring any country code, spaces, plus signs, or separators.
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
*
|
|
1126
|
-
*
|
|
1127
|
-
*
|
|
1128
|
-
* `
|
|
1129
|
-
*
|
|
1130
|
-
*
|
|
1131
|
-
*
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1371
|
+
*
|
|
1372
|
+
* ---
|
|
1373
|
+
* - ***Behavior:***
|
|
1374
|
+
* - **Exclusive mode:**
|
|
1375
|
+
* - ⚠️ When set to `true`, all formatting options
|
|
1376
|
+
* (`outputFormat`, `prependPlusCountryCode`, etc.)
|
|
1377
|
+
* and `checkValidOnly` **must be omitted** or will be **ignored**.
|
|
1378
|
+
* - **Conflict handling with `checkValidOnly`:**
|
|
1379
|
+
* - If both `takeNumberOnly` and `checkValidOnly` are `true`,
|
|
1380
|
+
* `checkValidOnly` takes priority and the function
|
|
1381
|
+
* returns a `boolean`.
|
|
1382
|
+
* - If `checkValidOnly` is `false` (or not provided),
|
|
1383
|
+
* and `takeNumberOnly` is `true`,
|
|
1384
|
+
* the function returns a **numeric string of the local number**.
|
|
1385
|
+
* - **Invalid input:**
|
|
1386
|
+
* - If the input is invalid or cannot be parsed
|
|
1387
|
+
* (e.g. not matching the `defaultCountry`),
|
|
1388
|
+
* the function returns an **empty string** (`""`).
|
|
1389
|
+
* - ***DefaultValue:*** `false`.
|
|
1390
|
+
* - ***Output example:***
|
|
1391
|
+
* - Valid input ➔ `"81234567890"` *(country code removed)*.
|
|
1392
|
+
* - Invalid input ➔ `""`.
|
|
1393
|
+
*
|
|
1394
|
+
* ---
|
|
1140
1395
|
* @default false
|
|
1141
1396
|
*/
|
|
1142
1397
|
takeNumberOnly: true;
|
|
1143
1398
|
}>;
|
|
1144
1399
|
/** -------------------------------------------------------
|
|
1145
1400
|
* * ***Utility: `formatPhoneNumber`.***
|
|
1146
|
-
*
|
|
1401
|
+
* --------------------------------------------------------
|
|
1147
1402
|
* **Formats a phone number into a customizable local or international style.**
|
|
1403
|
+
*
|
|
1404
|
+
* ---
|
|
1148
1405
|
* - **Type:** ***`Formatting Number`.***
|
|
1149
1406
|
* - **Can also:**
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1407
|
+
* - Return only digits string when **digits-only mode** (`takeNumberOnly`):
|
|
1408
|
+
* - Return empty-string (""), if invalid number phone.
|
|
1409
|
+
* - Return boolean when **validity-check mode** (`checkValidOnly`):
|
|
1410
|
+
* - ***Return `true` if:***
|
|
1411
|
+
* - A phone number is "valid" when it has valid length, and the actual phone number digits match the
|
|
1412
|
+
* regular expressions for its country (parameter options `defaultCountry`).
|
|
1156
1413
|
* - **E.164 compliance:**
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1160
|
-
*
|
|
1414
|
+
* - Optional leading `+` is recommended but **not required**.
|
|
1415
|
+
* - If Without leading `+`, you must passing `defaultCountry`.
|
|
1416
|
+
*
|
|
1417
|
+
* ---
|
|
1161
1418
|
* @param {ValueFormatPhoneNumber} value
|
|
1162
1419
|
* ***Phone number to format, accepts:***
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1420
|
+
* - `string` (recommended to preserve leading zeros).
|
|
1421
|
+
* - `number` (leading zeros will be lost).
|
|
1422
|
+
* - `null` or `undefined` (returns empty string).
|
|
1166
1423
|
* @param {FormatPhoneNumberMain} [options]
|
|
1167
1424
|
* ***Main options object controlling:***
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1425
|
+
* - `separator` (**string**): Group separator, default `" "`.
|
|
1426
|
+
* - `plusNumberCountry` (**string**): Country code with optional leading `+`.
|
|
1427
|
+
* - `openingNumberCountry` (**string**): Characters before the country code, e.g. `"("`.
|
|
1428
|
+
* - `closingNumberCountry` (**string**): Characters after the country code, e.g. `")"`.
|
|
1429
|
+
* - `checkValidOnly` (**boolean**): Return only validity.
|
|
1430
|
+
* - `takeNumberOnly` (**boolean**): Return digits only.
|
|
1431
|
+
* - `defaultCountry` (**string** - **`<ISO-3166-1 alpha-2>`**): Used to interpret numbers without an explicit `+<countryCode>`.
|
|
1432
|
+
*
|
|
1433
|
+
* ---
|
|
1434
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not string, number, null or undefined.
|
|
1435
|
+
* @throws **{@link TypeError | `TypeError`}** if `options` is not an object or contains wrong types.
|
|
1436
|
+
*
|
|
1437
|
+
* ---
|
|
1175
1438
|
* @returns {string|boolean} Formatted phone number string, digits-only string, or boolean.
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
* @param {FormatPhoneNumberCheckValidOnly} [options] With `checkValidOnly: true`.
|
|
1179
|
-
* Return a **validity-check mode** when `checkValidOnly: true`.
|
|
1180
|
-
* @returns {boolean} A boolean indicating whether the input is a valid phone number.
|
|
1181
|
-
* @overload
|
|
1182
|
-
* @param {ValueFormatPhoneNumber} value The phone number input (string or number).
|
|
1183
|
-
* @param {FormatPhoneNumberTransform} [options] With `takeNumberOnly: true`.
|
|
1184
|
-
* Return **digits-only mode** when `takeNumberOnly: true`.
|
|
1185
|
-
* @returns {string} A string of digits only.
|
|
1186
|
-
* @overload
|
|
1187
|
-
* @param {ValueFormatPhoneNumber} value The phone number input (string or number).
|
|
1188
|
-
* @param {FormatPhoneNumberTakeNumberOnly} [options] Options to customize format output (country code, separator, etc).
|
|
1189
|
-
* Return a **formatted phone number string** with custom formatting and (`checkValidOnly: false`, `takeNumberOnly: false`).
|
|
1190
|
-
* @returns {string} Formatting number. return a string of digits only with formatter.
|
|
1439
|
+
*
|
|
1440
|
+
* ---
|
|
1191
1441
|
* @example
|
|
1192
|
-
*
|
|
1193
|
-
*
|
|
1194
|
-
*
|
|
1195
|
-
*
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1442
|
+
*
|
|
1443
|
+
* 1. #### *Formatting Phone Number String:*
|
|
1444
|
+
* ```ts
|
|
1445
|
+
* formatPhoneNumber("081234567890");
|
|
1446
|
+
* // ➔ "0812 3456 7890"
|
|
1447
|
+
* formatPhoneNumber("081234567890", {
|
|
1448
|
+
* separator: "-",
|
|
1449
|
+
* plusNumberCountry: "+44",
|
|
1450
|
+
* openingNumberCountry: "(",
|
|
1451
|
+
* closingNumberCountry: ")"
|
|
1452
|
+
* });
|
|
1453
|
+
* // ➔ "(+44) 8123-4567-890"
|
|
1454
|
+
* ```
|
|
1455
|
+
* ---
|
|
1456
|
+
* 2. #### *Digits-Only Mode:*
|
|
1205
1457
|
* ```ts
|
|
1206
1458
|
* formatPhoneNumber("(0812) 3456-7890", {
|
|
1207
1459
|
* takeNumberOnly: true,
|
|
@@ -1230,7 +1482,8 @@ type FormatPhoneNumberAllPassingTakeOnly = OverrideTypes<FormatPhoneNumberMain,
|
|
|
1230
1482
|
* formatPhoneNumber("49 (151) 2345 6789", { takeNumberOnly: true });
|
|
1231
1483
|
* // ➔ ""
|
|
1232
1484
|
* ```
|
|
1233
|
-
*
|
|
1485
|
+
* ---
|
|
1486
|
+
* 3. #### *Validity-Check Mode:*
|
|
1234
1487
|
* ```ts
|
|
1235
1488
|
* formatPhoneNumber("+6281234567890", { checkValidOnly: true });
|
|
1236
1489
|
* // ➔ true
|
|
@@ -1267,29 +1520,39 @@ type FormatPhoneNumberAllPassingTakeOnly = OverrideTypes<FormatPhoneNumberMain,
|
|
|
1267
1520
|
declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: FormatPhoneNumberTransform): string;
|
|
1268
1521
|
/** -------------------------------------------------------
|
|
1269
1522
|
* * ***Utility: `formatPhoneNumber`.***
|
|
1270
|
-
*
|
|
1523
|
+
* --------------------------------------------------------
|
|
1271
1524
|
* **Formats a phone number into a customizable local or international style.**
|
|
1525
|
+
*
|
|
1526
|
+
* ---
|
|
1272
1527
|
* - **Type:** ***`Digits-only Mode`.***
|
|
1273
1528
|
* - **Can also:**
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1529
|
+
* - Return only digits string when **digits-only mode** (`takeNumberOnly`).
|
|
1530
|
+
* - Return boolean when **validity-check mode** (`checkValidOnly`) using a
|
|
1531
|
+
* regex for international-style phone numbers:
|
|
1532
|
+
* - ***Valid if:***
|
|
1533
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`,
|
|
1534
|
+
* hyphens `-`, or dots `.`.
|
|
1535
|
+
* - Digits-only length < 16.
|
|
1281
1536
|
* - **E.164 compliance:**
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1537
|
+
* - Optional leading `+` is recommended but **not required**.
|
|
1538
|
+
* - If Without leading `+`, you must passing `defaultCountry`.
|
|
1539
|
+
*
|
|
1540
|
+
* ---
|
|
1286
1541
|
* @param {ValueFormatPhoneNumber} value
|
|
1287
1542
|
* Phone number to format. Accepts:
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1290
|
-
*
|
|
1543
|
+
* - `string` (recommended to preserve leading zeros).
|
|
1544
|
+
* - `number` (leading zeros will be lost).
|
|
1545
|
+
* - `null` or `undefined` (returns empty string).
|
|
1291
1546
|
* @param {FormatPhoneNumberTakeNumberOnly} [options] Options to customize format output (country code, separator, etc).
|
|
1547
|
+
*
|
|
1548
|
+
* ---
|
|
1549
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not string, number, null or undefined.
|
|
1550
|
+
* @throws **{@link TypeError | `TypeError`}** if `options` is not an object or contains wrong types.
|
|
1551
|
+
*
|
|
1552
|
+
* ---
|
|
1292
1553
|
* @returns {string} Digits-only mode, return string a digits-only.
|
|
1554
|
+
*
|
|
1555
|
+
* ---
|
|
1293
1556
|
* @example
|
|
1294
1557
|
* ```ts
|
|
1295
1558
|
* formatPhoneNumber("(0812) 3456-7890", {
|
|
@@ -1323,29 +1586,39 @@ declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: Form
|
|
|
1323
1586
|
declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: FormatPhoneNumberTakeNumberOnly): string;
|
|
1324
1587
|
/** -------------------------------------------------------
|
|
1325
1588
|
* * ***Utility: `formatPhoneNumber`.***
|
|
1326
|
-
*
|
|
1589
|
+
* --------------------------------------------------------
|
|
1327
1590
|
* **Formats a phone number into a customizable local or international style.**
|
|
1591
|
+
*
|
|
1592
|
+
* ---
|
|
1328
1593
|
* - **Type:** ***`Validity-check Mode`.***
|
|
1329
1594
|
* - **Can also:**
|
|
1330
|
-
*
|
|
1331
|
-
*
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1595
|
+
* - Return only digits string when **digits-only mode** (`takeNumberOnly`).
|
|
1596
|
+
* - Return boolean when **validity-check mode** (`checkValidOnly`) using a
|
|
1597
|
+
* regex for international-style phone numbers:
|
|
1598
|
+
* - ***Valid if:***
|
|
1599
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`,
|
|
1600
|
+
* hyphens `-`, or dots `.`.
|
|
1601
|
+
* - Digits-only length < 16.
|
|
1337
1602
|
* - **E.164 compliance:**
|
|
1338
|
-
*
|
|
1339
|
-
*
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1603
|
+
* - Optional leading `+` is recommended but **not required**.
|
|
1604
|
+
* - If Without leading `+`, you must passing `defaultCountry`.
|
|
1605
|
+
*
|
|
1606
|
+
* ---
|
|
1342
1607
|
* @param {ValueFormatPhoneNumber} value
|
|
1343
1608
|
* Phone number to format. Accepts:
|
|
1344
1609
|
* - `string` (recommended to preserve leading zeros).
|
|
1345
1610
|
* - `number` (leading zeros will be lost).
|
|
1346
1611
|
* - `null` or `undefined` (returns empty string).
|
|
1347
1612
|
* @param {FormatPhoneNumberTakeNumberOnly} [options] Options to customize format output (country code, separator, etc).
|
|
1613
|
+
*
|
|
1614
|
+
* ---
|
|
1615
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not string, number, null or undefined.
|
|
1616
|
+
* @throws **{@link TypeError | `TypeError`}** if `options` is not an object or contains wrong types.
|
|
1617
|
+
*
|
|
1618
|
+
* ---
|
|
1348
1619
|
* @returns {boolean} Validity-check mode, return a boolean.
|
|
1620
|
+
*
|
|
1621
|
+
* ---
|
|
1349
1622
|
* @example
|
|
1350
1623
|
* ```ts
|
|
1351
1624
|
* formatPhoneNumber("+6281234567890", { checkValidOnly: true });
|
|
@@ -1383,29 +1656,39 @@ declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: Form
|
|
|
1383
1656
|
declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: FormatPhoneNumberCheckValidOnly): boolean;
|
|
1384
1657
|
/** -------------------------------------------------------
|
|
1385
1658
|
* * ***Utility: `formatPhoneNumber`.***
|
|
1386
|
-
*
|
|
1659
|
+
* --------------------------------------------------------
|
|
1387
1660
|
* **Formats a phone number into a customizable local or international style.**
|
|
1661
|
+
*
|
|
1662
|
+
* ---
|
|
1388
1663
|
* - **Type:** ***Forced to `Validity-check Mode`***, because `checkValidOnly` has set to `true`.
|
|
1389
1664
|
* - **Can also:**
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1396
|
-
*
|
|
1665
|
+
* - Return only digits string when **digits-only mode** (`takeNumberOnly`).
|
|
1666
|
+
* - Return boolean when **validity-check mode** (`checkValidOnly`) using a
|
|
1667
|
+
* regex for international-style phone numbers:
|
|
1668
|
+
* - ***Valid if:***
|
|
1669
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`,
|
|
1670
|
+
* hyphens `-`, or dots `.`.
|
|
1671
|
+
* - Digits-only length < 16.
|
|
1397
1672
|
* - **E.164 compliance:**
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1673
|
+
* - Optional leading `+` is recommended but **not required**.
|
|
1674
|
+
* - If Without leading `+`, you must passing `defaultCountry`.
|
|
1675
|
+
*
|
|
1676
|
+
* ---
|
|
1402
1677
|
* @param {ValueFormatPhoneNumber} value
|
|
1403
1678
|
* Phone number to format. Accepts:
|
|
1404
1679
|
* - `string` (recommended to preserve leading zeros).
|
|
1405
1680
|
* - `number` (leading zeros will be lost).
|
|
1406
1681
|
* - `null` or `undefined` (returns empty string).
|
|
1407
1682
|
* @param {FormatPhoneNumberTakeNumberOnly} [options] Options to customize format output (country code, separator, etc).
|
|
1683
|
+
*
|
|
1684
|
+
* ---
|
|
1685
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not string, number, null or undefined.
|
|
1686
|
+
* @throws **{@link TypeError | `TypeError`}** if `options` is not an object or contains wrong types.
|
|
1687
|
+
*
|
|
1688
|
+
* ---
|
|
1408
1689
|
* @returns {boolean} Validity-check mode, return a boolean.
|
|
1690
|
+
*
|
|
1691
|
+
* ---
|
|
1409
1692
|
* @example
|
|
1410
1693
|
* ```ts
|
|
1411
1694
|
* formatPhoneNumber("+6281234567890", {
|
|
@@ -1499,29 +1782,39 @@ declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: Form
|
|
|
1499
1782
|
declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: FormatPhoneNumberAllPassingValidOnly): boolean;
|
|
1500
1783
|
/** -------------------------------------------------------
|
|
1501
1784
|
* * ***Utility: `formatPhoneNumber`.***
|
|
1502
|
-
*
|
|
1785
|
+
* --------------------------------------------------------
|
|
1503
1786
|
* **Formats a phone number into a customizable local or international style.**
|
|
1787
|
+
*
|
|
1788
|
+
* ---
|
|
1504
1789
|
* - **Type:** ***Forced to `Digits-only Mode`***, because `takeNumberOnly` has set to `true`.
|
|
1505
1790
|
* - **Can also:**
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
*
|
|
1509
|
-
*
|
|
1510
|
-
*
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1791
|
+
* - Return only digits string when **digits-only mode** (`takeNumberOnly`).
|
|
1792
|
+
* - Return boolean when **validity-check mode** (`checkValidOnly`) using a
|
|
1793
|
+
* regex for international-style phone numbers:
|
|
1794
|
+
* - ***Valid if:***
|
|
1795
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`,
|
|
1796
|
+
* hyphens `-`, or dots `.`.
|
|
1797
|
+
* - Digits-only length < 16.
|
|
1513
1798
|
* - **E.164 compliance:**
|
|
1514
|
-
*
|
|
1515
|
-
*
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1799
|
+
* - Optional leading `+` is recommended but **not required**.
|
|
1800
|
+
* - If Without leading `+`, you must passing `defaultCountry`.
|
|
1801
|
+
*
|
|
1802
|
+
* ---
|
|
1518
1803
|
* @param {ValueFormatPhoneNumber} value
|
|
1519
|
-
*
|
|
1804
|
+
* Phone number to format. Accepts:
|
|
1520
1805
|
* - `string` (recommended to preserve leading zeros)
|
|
1521
1806
|
* - `number` (leading zeros will be lost)
|
|
1522
1807
|
* - `null` or `undefined` (returns empty string).
|
|
1523
1808
|
* @param {FormatPhoneNumberTakeNumberOnly} [options] Options to customize format output (country code, separator, etc).
|
|
1809
|
+
*
|
|
1810
|
+
* ---
|
|
1811
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not string, number, null or undefined.
|
|
1812
|
+
* @throws **{@link TypeError | `TypeError`}** if `options` is not an object or contains wrong types.
|
|
1813
|
+
*
|
|
1814
|
+
* ---
|
|
1524
1815
|
* @returns {string} Digits-only mode, return string a digits-only.
|
|
1816
|
+
*
|
|
1817
|
+
* ---
|
|
1525
1818
|
* @example
|
|
1526
1819
|
* ```ts
|
|
1527
1820
|
* formatPhoneNumber("(0812) 3456-7890", {
|
|
@@ -1577,30 +1870,40 @@ declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: Form
|
|
|
1577
1870
|
declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: FormatPhoneNumberAllPassingTakeOnly): string;
|
|
1578
1871
|
/** -------------------------------------------------------
|
|
1579
1872
|
* * ***Utility: `formatPhoneNumber`.***
|
|
1580
|
-
*
|
|
1873
|
+
* --------------------------------------------------------
|
|
1581
1874
|
* **Formats a phone number into a customizable local or international style.**
|
|
1875
|
+
*
|
|
1876
|
+
* ---
|
|
1582
1877
|
* - **Type:** ***Forced to `Validity-check Mode`***, because `checkValidOnly` and `takeNumberOnly` has set to `true`,
|
|
1583
|
-
*
|
|
1878
|
+
* but `checkValidOnly` will prioritize one.
|
|
1584
1879
|
* - **Can also:**
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1880
|
+
* - Return only digits string when **digits-only mode** (`takeNumberOnly`).
|
|
1881
|
+
* - Return boolean when **validity-check mode** (`checkValidOnly`) using a
|
|
1882
|
+
* regex for international-style phone numbers:
|
|
1883
|
+
* - ***Valid if:***
|
|
1884
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`,
|
|
1885
|
+
* hyphens `-`, or dots `.`.
|
|
1886
|
+
* - Digits-only length < 16.
|
|
1592
1887
|
* - **E.164 compliance:**
|
|
1593
|
-
*
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
1596
|
-
*
|
|
1888
|
+
* - Optional leading `+` is recommended but **not required**.
|
|
1889
|
+
* - If Without leading `+`, you must passing `defaultCountry`.
|
|
1890
|
+
*
|
|
1891
|
+
* ---
|
|
1597
1892
|
* @param {ValueFormatPhoneNumber} value
|
|
1598
1893
|
* Phone number to format. Accepts:
|
|
1599
1894
|
* - `string` (recommended to preserve leading zeros).
|
|
1600
1895
|
* - `number` (leading zeros will be lost).
|
|
1601
1896
|
* - `null` or `undefined` (returns empty string).
|
|
1602
1897
|
* @param {FormatPhoneNumberTakeNumberOnly} [options] Options to customize format output (country code, separator, etc).
|
|
1898
|
+
*
|
|
1899
|
+
* ---
|
|
1900
|
+
* @throws **{@link TypeError | `TypeError`}** if `value` is not string, number, null or undefined.
|
|
1901
|
+
* @throws **{@link TypeError | `TypeError`}** if `options` is not an object or contains wrong types.
|
|
1902
|
+
*
|
|
1903
|
+
* ---
|
|
1603
1904
|
* @returns {boolean} Validity-check mode, return a boolean.
|
|
1905
|
+
*
|
|
1906
|
+
* ---
|
|
1604
1907
|
* @example
|
|
1605
1908
|
* ```ts
|
|
1606
1909
|
* formatPhoneNumber("+6281234567890", {
|
|
@@ -1719,91 +2022,130 @@ declare function formatPhoneNumber(value: ValueFormatPhoneNumber, options?: Form
|
|
|
1719
2022
|
type CensorEmailOptions = {
|
|
1720
2023
|
/** ----------------------------------------------------------
|
|
1721
2024
|
* * ***Censorship Mode.***
|
|
1722
|
-
*
|
|
2025
|
+
* -----------------------------------------------------------
|
|
1723
2026
|
* - **Valid value:**
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
2027
|
+
* - `"random"` – Each character is randomly replaced every time the function is called.
|
|
2028
|
+
* - `"fixed"` ***(default)*** – Deterministic censorship based on a hash of the email, same input always produces the same output.
|
|
2029
|
+
*
|
|
2030
|
+
* ---
|
|
2031
|
+
* @default "fixed"
|
|
1726
2032
|
*/
|
|
1727
2033
|
mode?: "random" | "fixed";
|
|
1728
2034
|
};
|
|
1729
2035
|
/** ----------------------------------------------------------
|
|
1730
2036
|
* * ***Utility: `censorEmail`.***
|
|
1731
|
-
*
|
|
2037
|
+
* -----------------------------------------------------------
|
|
1732
2038
|
* **Censors an email by replacing characters with `"*"` while supporting random or fixed mode.**
|
|
2039
|
+
*
|
|
2040
|
+
* ---
|
|
1733
2041
|
* - **This function replaces parts of an email with asterisks to protect privacy.**
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1736
|
-
*
|
|
1737
|
-
*
|
|
1738
|
-
*
|
|
2042
|
+
* - **Modes:**
|
|
2043
|
+
* - `"fixed"` **(default)** – Deterministic censorship based on a hash of the email, same input always produces the same output.
|
|
2044
|
+
* - `"random"` – Each character is randomly replaced every time the function is called.
|
|
2045
|
+
* - **Note:**
|
|
2046
|
+
* - Invalid emails or non-string input will return an empty-string (`""`).
|
|
2047
|
+
*
|
|
2048
|
+
* ---
|
|
1739
2049
|
* @param {string | null | undefined} email - The email address to censor.
|
|
1740
2050
|
* @param {CensorEmailOptions} [options={}] - Options object for mode.
|
|
1741
|
-
*
|
|
2051
|
+
*
|
|
2052
|
+
* ---
|
|
1742
2053
|
* @throws **{@link TypeError | `TypeError`}** if `options` is not a plain object or `mode` is invalid.
|
|
1743
|
-
* @example
|
|
1744
|
-
* // Fixed mode (default, deterministic)
|
|
1745
|
-
* censorEmail("john.doe@gmail.com");
|
|
1746
|
-
* // ➔ "j**n.**e@g***l.com"
|
|
1747
2054
|
*
|
|
1748
|
-
*
|
|
1749
|
-
*
|
|
1750
|
-
* // ➔ "j**n.**e@g***l.com"
|
|
2055
|
+
* ---
|
|
2056
|
+
* @returns {string} The censored email, or an empty string if input is invalid.
|
|
1751
2057
|
*
|
|
1752
|
-
*
|
|
1753
|
-
*
|
|
1754
|
-
* // ➔ "j*hn.***e@g***l.com" (random)
|
|
2058
|
+
* ---
|
|
2059
|
+
* @example
|
|
1755
2060
|
*
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
2061
|
+
* 1. #### Fixed mode (default, deterministic):
|
|
2062
|
+
* ```ts
|
|
2063
|
+
* censorEmail("john.doe@gmail.com");
|
|
2064
|
+
* // ➔ "j**n.**e@g***l.com"
|
|
2065
|
+
* ```
|
|
2066
|
+
* ---
|
|
2067
|
+
* 2. #### Fixed mode explicitly:
|
|
2068
|
+
* ```ts
|
|
2069
|
+
* censorEmail("john.doe@gmail.com", { mode: "fixed" });
|
|
2070
|
+
* // ➔ "j**n.**e@g***l.com"
|
|
2071
|
+
* ```
|
|
2072
|
+
* ---
|
|
2073
|
+
* 3. #### Random mode (output may vary each time):
|
|
2074
|
+
* ```ts
|
|
2075
|
+
* censorEmail("john.doe@gmail.com", { mode: "random" });
|
|
2076
|
+
* // ➔ "j*hn.***e@g***l.com" (random)
|
|
2077
|
+
* ```
|
|
2078
|
+
* ---
|
|
2079
|
+
* 4. #### Invalid email returns empty string:
|
|
2080
|
+
* ```ts
|
|
2081
|
+
* censorEmail("invalid-email");
|
|
2082
|
+
* // ➔ ""
|
|
2083
|
+
* ```
|
|
1759
2084
|
*/
|
|
1760
2085
|
declare const censorEmail: (email: string | null | undefined, options?: CensorEmailOptions) => string;
|
|
1761
2086
|
type ChunkStringOptions = {
|
|
1762
|
-
/**
|
|
2087
|
+
/** ---------------------------------------------------------
|
|
2088
|
+
* * ***The separator string to insert between characters or words.***
|
|
2089
|
+
* ----------------------------------------------------------
|
|
1763
2090
|
*
|
|
1764
|
-
* -
|
|
1765
|
-
*
|
|
2091
|
+
* - #### *Behavior:*
|
|
2092
|
+
* - Used when inserting separators every `limiter` characters.
|
|
2093
|
+
* - Default is a single space `" "`.
|
|
1766
2094
|
*
|
|
2095
|
+
* ---
|
|
1767
2096
|
* @default " "
|
|
1768
2097
|
*/
|
|
1769
2098
|
separator?: string;
|
|
1770
|
-
/**
|
|
2099
|
+
/** ---------------------------------------------------------
|
|
2100
|
+
* * ***Determines whether counting for `limiter` resets after each space.***
|
|
2101
|
+
* ----------------------------------------------------------
|
|
1771
2102
|
*
|
|
1772
|
-
* -
|
|
1773
|
-
*
|
|
1774
|
-
*
|
|
1775
|
-
*
|
|
2103
|
+
* - #### *Behavior:*
|
|
2104
|
+
* - If `true`, the string is treated as words separated by spaces,
|
|
2105
|
+
* and separators are applied within words, then words are grouped.
|
|
2106
|
+
* - If `false` ***(default)***, counting is continuous across the whole string,
|
|
2107
|
+
* treating spaces as normal characters.
|
|
1776
2108
|
*
|
|
2109
|
+
* ---
|
|
1777
2110
|
* @default false
|
|
1778
2111
|
*/
|
|
1779
2112
|
reCountAfterSpace?: boolean;
|
|
1780
2113
|
};
|
|
1781
|
-
/**
|
|
2114
|
+
/** ---------------------------------------------------------
|
|
1782
2115
|
* * ***Utility: `chunkString`.***
|
|
1783
|
-
*
|
|
2116
|
+
* ----------------------------------------------------------
|
|
1784
2117
|
* **Chunks a string by inserting a separator every `limiter` characters.**
|
|
1785
|
-
*
|
|
1786
|
-
*
|
|
1787
|
-
*
|
|
1788
|
-
* -
|
|
1789
|
-
*
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
1794
|
-
* -
|
|
1795
|
-
*
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1798
|
-
*
|
|
1799
|
-
*
|
|
2118
|
+
*
|
|
2119
|
+
* - #### **This function handles two main behaviors based on `reCountAfterSpace`:**
|
|
2120
|
+
* 1. #### *If `reCountAfterSpace` is `false` (default):*
|
|
2121
|
+
* - The separator is inserted strictly every `limiter` characters throughout the entire string, regardless of spaces, spaces are
|
|
2122
|
+
* treated as regular characters in the count.
|
|
2123
|
+
* - Example: `chunkString("1234567890", 3, "-")` ➔ `"123-456-789-0"`.
|
|
2124
|
+
* - Example: `chunkString("Hello World", 3, "-")` ➔ `"Hel-lo -Wor-ld"`.
|
|
2125
|
+
* ---
|
|
2126
|
+
* 2. #### *If `reCountAfterSpace` is `true`:*
|
|
2127
|
+
* - The function first processes the input string to replace any multiple consecutive spaces with a
|
|
2128
|
+
* single space (e.g., `"A B"` becomes `"A B"`).
|
|
2129
|
+
* Then, it treats the string as a sequence of **"words"** (segments separated by single spaces).
|
|
2130
|
+
* - Each word is processed independently:
|
|
2131
|
+
* - if a word's length exceeds the `limiter`, separators are inserted internally within that word.
|
|
2132
|
+
* - Words are then grouped. Each group will contain `limiter` number of words.
|
|
2133
|
+
* - Words within the same group are joined by the specified `separator`.
|
|
2134
|
+
* - Finally, these groups are joined by a single space, preserving the original word separation
|
|
2135
|
+
* structure between groups.
|
|
2136
|
+
*
|
|
2137
|
+
* ---
|
|
1800
2138
|
* @param {string} subject - ***The target string to chunk.****
|
|
1801
2139
|
* @param {number} limiter
|
|
1802
2140
|
* ***The interval (number of characters) for inserting separators, behavior:***
|
|
1803
2141
|
* - If `reCountAfterSpace = false`, it counts characters.
|
|
1804
2142
|
* - If `reCountAfterSpace = true`, it counts both characters within words and words per group.
|
|
1805
2143
|
* @param {ChunkStringOptions} [options={}] - ***Optional settings for separator and counting behavior.***
|
|
2144
|
+
*
|
|
2145
|
+
* ---
|
|
1806
2146
|
* @returns {string} Return the formatted string with separators.
|
|
2147
|
+
*
|
|
2148
|
+
* ---
|
|
1807
2149
|
* @example
|
|
1808
2150
|
* // Basic usage
|
|
1809
2151
|
* chunkString("1234567890", 3);
|
|
@@ -1831,19 +2173,25 @@ type ChunkStringOptions = {
|
|
|
1831
2173
|
*/
|
|
1832
2174
|
declare function chunkString(subject: string, limiter: number, options?: ChunkStringOptions): string;
|
|
1833
2175
|
type TruncateStringOptions = {
|
|
1834
|
-
/**
|
|
2176
|
+
/** ---------------------------------------------------------
|
|
2177
|
+
* * ***Maximum length of the truncated string **(default: `10`)**.***
|
|
2178
|
+
* ----------------------------------------------------------
|
|
1835
2179
|
*
|
|
1836
2180
|
* @default 10
|
|
1837
2181
|
*/
|
|
1838
2182
|
length?: number;
|
|
1839
|
-
/**
|
|
2183
|
+
/** ---------------------------------------------------------
|
|
2184
|
+
* * ***String to append if truncation occurs.***
|
|
2185
|
+
* ----------------------------------------------------------
|
|
1840
2186
|
*
|
|
1841
2187
|
* - Will be trimmed first; defaults to `"..."` if empty.
|
|
1842
2188
|
*
|
|
1843
2189
|
* @default "..."
|
|
1844
2190
|
*/
|
|
1845
2191
|
ending?: string;
|
|
1846
|
-
/**
|
|
2192
|
+
/** ---------------------------------------------------------
|
|
2193
|
+
* * ***Whether to trim the input string before truncation ***(default: `true`)***.***
|
|
2194
|
+
* ----------------------------------------------------------
|
|
1847
2195
|
*
|
|
1848
2196
|
* @default true
|
|
1849
2197
|
*/
|
|
@@ -1851,22 +2199,30 @@ type TruncateStringOptions = {
|
|
|
1851
2199
|
};
|
|
1852
2200
|
/** ----------------------------------------------------------
|
|
1853
2201
|
* * ***Utility: `truncateString`.***
|
|
1854
|
-
*
|
|
1855
|
-
* **Features:**
|
|
1856
|
-
*
|
|
1857
|
-
*
|
|
1858
|
-
*
|
|
1859
|
-
*
|
|
2202
|
+
* -----------------------------------------------------------
|
|
2203
|
+
* - **Features:**
|
|
2204
|
+
* - Truncates a string to a specified length and optionally appends an ending.
|
|
2205
|
+
* - Supports trimming the input before truncation.
|
|
2206
|
+
* - If truncation occurs, trailing spaces before the ending are removed.
|
|
2207
|
+
* - The `ending` parameter is always trimmed first; if empty, it defaults to `"..."`.
|
|
2208
|
+
*
|
|
2209
|
+
* ---
|
|
1860
2210
|
* @param {string|null|undefined} text
|
|
1861
2211
|
* ***The input string to truncate, behavior:***
|
|
1862
2212
|
* - If `null`, `undefined`, or empty after trim, returns `""`.
|
|
1863
2213
|
* @param {TruncateStringOptions} [options]
|
|
1864
2214
|
* ***Optional settings:***
|
|
1865
|
-
*
|
|
1866
|
-
*
|
|
1867
|
-
*
|
|
1868
|
-
*
|
|
2215
|
+
* - `length` (number, default 10): Maximum length of the truncated string.
|
|
2216
|
+
* - `ending` (string, default `"..."`): String to append if truncation occurs.
|
|
2217
|
+
* - `trim` (boolean, default `true`): Whether to trim the input before truncation.
|
|
2218
|
+
*
|
|
2219
|
+
* ---
|
|
1869
2220
|
* @throws **{@link TypeError | `TypeError`}** if `options.length` is not a finite number, or if `options.ending` is not a string, or if `options.trim` is not a boolean.
|
|
2221
|
+
*
|
|
2222
|
+
* ---
|
|
2223
|
+
* @returns {string} The truncated string with optional trimming and ending, returns `""` if input is empty or length < 1.
|
|
2224
|
+
*
|
|
2225
|
+
* ---
|
|
1870
2226
|
* @example
|
|
1871
2227
|
* truncateString("hello world", { length: 5 });
|
|
1872
2228
|
* // ➔ "hello..."
|
|
@@ -1886,7 +2242,7 @@ type TruncateStringOptions = {
|
|
|
1886
2242
|
declare const truncateString: (text: string | null | undefined, options?: TruncateStringOptions) => string;
|
|
1887
2243
|
/** ----------------------------------------------------------------------
|
|
1888
2244
|
* * ***Options for formatting dates with `date-fns/format`.***
|
|
1889
|
-
*
|
|
2245
|
+
* -----------------------------------------------------------------------
|
|
1890
2246
|
*
|
|
1891
2247
|
* Extends the base **{@link FormatOptions | *`FormatOptions`*}** (without **`locale`**) with extra options
|
|
1892
2248
|
* for handling output formatting, localization, and parsing non-standard inputs.
|
|
@@ -1896,23 +2252,43 @@ type FormatDateFnsOptions = Prettify<OmitStrict<FormatOptions, "locale", {
|
|
|
1896
2252
|
}> & {
|
|
1897
2253
|
/** ------------------------------------------------------------
|
|
1898
2254
|
* * ***Output format string passed to `date-fns/format`.***
|
|
1899
|
-
*
|
|
2255
|
+
* -------------------------------------------------------------
|
|
1900
2256
|
* - **Behavior:**
|
|
1901
|
-
*
|
|
1902
|
-
*
|
|
2257
|
+
* - Determines how the date will be rendered.
|
|
2258
|
+
* - Uses the full power of `date-fns` tokens.
|
|
2259
|
+
*
|
|
2260
|
+
* ---
|
|
1903
2261
|
* - ***Default Value***: `"dd MMM yyyy - HH:mm:ss"`.
|
|
2262
|
+
*
|
|
2263
|
+
* ---
|
|
2264
|
+
* @default
|
|
2265
|
+
* ```ts
|
|
2266
|
+
* "dd MMM yyyy - HH:mm:ss"
|
|
2267
|
+
* ```
|
|
2268
|
+
*
|
|
2269
|
+
* ---
|
|
1904
2270
|
* @example
|
|
1905
2271
|
* "dd MMMM yyyy, HH:mm:ss" // ➔ "03 September 2025, 10:25:42"
|
|
1906
|
-
* @default "dd MMM yyyy - HH:mm:ss"
|
|
1907
2272
|
*/
|
|
1908
2273
|
format?: string;
|
|
1909
2274
|
/** ------------------------------------------------------------
|
|
1910
2275
|
* * ***Locale used for formatting.***
|
|
1911
|
-
*
|
|
2276
|
+
* -------------------------------------------------------------
|
|
1912
2277
|
* - **Behavior:**
|
|
1913
|
-
*
|
|
1914
|
-
*
|
|
2278
|
+
* - If `string`: only accepts `"id"` (Indonesian) or `"en"` (English) - **(default)**.
|
|
2279
|
+
* - If `Locale`: accepts a locale object from `date-fns/locale`.
|
|
2280
|
+
*
|
|
2281
|
+
* ---
|
|
1915
2282
|
* - ***Default Value***: `"en"`.
|
|
2283
|
+
*
|
|
2284
|
+
* ---
|
|
2285
|
+
* @default
|
|
2286
|
+
* ```ts
|
|
2287
|
+
* "en"
|
|
2288
|
+
* ```
|
|
2289
|
+
* ---
|
|
2290
|
+
* @example
|
|
2291
|
+
*
|
|
1916
2292
|
* ```ts
|
|
1917
2293
|
* import { ar } from "date-fns/locale";
|
|
1918
2294
|
*
|
|
@@ -1922,17 +2298,27 @@ type FormatDateFnsOptions = Prettify<OmitStrict<FormatOptions, "locale", {
|
|
|
1922
2298
|
* });
|
|
1923
2299
|
* // ➔ "03 سبتمبر 2025"
|
|
1924
2300
|
* ```
|
|
1925
|
-
* @default "en"
|
|
1926
2301
|
*/
|
|
1927
2302
|
locale?: "id" | "en" | AnyString | Locale;
|
|
1928
2303
|
/** ------------------------------------------------------------
|
|
1929
2304
|
* * ***Input locale used when parsing non-standard string dates.***
|
|
1930
|
-
*
|
|
2305
|
+
* -------------------------------------------------------------
|
|
1931
2306
|
* - **Behavior:**
|
|
1932
|
-
*
|
|
1933
|
-
*
|
|
1934
|
-
*
|
|
2307
|
+
* - Required if `date` is a **localized string**
|
|
2308
|
+
* (e.g. `"03 Mei 2025 10:25:42"` in Indonesian).
|
|
2309
|
+
* - Same accepted types as `locale` parameter.
|
|
2310
|
+
*
|
|
2311
|
+
* ---
|
|
1935
2312
|
* - ***Default Value***: `"en"`.
|
|
2313
|
+
*
|
|
2314
|
+
* ---
|
|
2315
|
+
* @default
|
|
2316
|
+
* ```ts
|
|
2317
|
+
* "en"
|
|
2318
|
+
* ```
|
|
2319
|
+
*
|
|
2320
|
+
* ---
|
|
2321
|
+
* @example
|
|
1936
2322
|
* ```ts
|
|
1937
2323
|
* import { ar } from "date-fns/locale";
|
|
1938
2324
|
*
|
|
@@ -1943,58 +2329,74 @@ type FormatDateFnsOptions = Prettify<OmitStrict<FormatOptions, "locale", {
|
|
|
1943
2329
|
* });
|
|
1944
2330
|
* // ➔ "May 3, 2025 at 10:25:42 AM"
|
|
1945
2331
|
* ```
|
|
1946
|
-
* @default "en"
|
|
1947
2332
|
*/
|
|
1948
2333
|
inputLocale?: "id" | "en" | AnyString | Locale;
|
|
1949
2334
|
/** ------------------------------------------------------------
|
|
1950
2335
|
* * ***Input format string for parsing non-ISO string dates.***
|
|
1951
|
-
*
|
|
2336
|
+
* -------------------------------------------------------------
|
|
1952
2337
|
* - **Behavior:**
|
|
1953
|
-
*
|
|
1954
|
-
*
|
|
2338
|
+
* - Required if `date` is **not ISO-8601** and not a native `Date`.
|
|
2339
|
+
* - Works together with `inputLocale` parameter.
|
|
2340
|
+
*
|
|
2341
|
+
* ---
|
|
1955
2342
|
* - ***Default Value***: `undefined`.
|
|
1956
|
-
*
|
|
2343
|
+
*
|
|
2344
|
+
* ---
|
|
2345
|
+
* @default
|
|
2346
|
+
* ```ts
|
|
2347
|
+
* undefined
|
|
2348
|
+
* ```
|
|
2349
|
+
*
|
|
2350
|
+
* ---
|
|
1957
2351
|
* @example
|
|
1958
2352
|
* "dd MMMM yyyy HH:mm:ss" // ➔ "03 May 2025 10:25:42"
|
|
1959
2353
|
*/
|
|
1960
2354
|
inputFormat?: string;
|
|
1961
2355
|
}>;
|
|
1962
|
-
/**
|
|
2356
|
+
/** --------------------------------------------------------------------------------------------------
|
|
1963
2357
|
* * ***Utility: `formatDateFns`.***
|
|
1964
|
-
*
|
|
2358
|
+
* ---------------------------------------------------------------------------------------------------
|
|
1965
2359
|
* **Formats a date into a human-readable string using `date-fns`.**
|
|
1966
|
-
*
|
|
1967
|
-
*
|
|
1968
|
-
*
|
|
1969
|
-
*
|
|
1970
|
-
*
|
|
2360
|
+
*
|
|
2361
|
+
* ---
|
|
2362
|
+
* - **Features:**
|
|
2363
|
+
* - Supports custom output formats using `date-fns/format`.
|
|
2364
|
+
* - Can parse localized non-ISO strings via `inputFormat` & `inputLocale`.
|
|
2365
|
+
* - Supports `locale` as `"id"`, `"en"` or `date-fns` `Locale` objects (like `id` or `enUS`).
|
|
2366
|
+
* - Returns `null` if the date is invalid, not provided, or parsing fails.
|
|
2367
|
+
*
|
|
2368
|
+
* ---
|
|
1971
2369
|
* @param {string | Date | null | undefined} date
|
|
1972
2370
|
* ***The date input to format, can be:***
|
|
1973
|
-
*
|
|
1974
|
-
*
|
|
1975
|
-
*
|
|
2371
|
+
* - A `Date` object.
|
|
2372
|
+
* - An ISO string (e.g. `"2024-01-01T12:00:00Z"`).
|
|
2373
|
+
* - A localized string (requires `inputFormat` + `inputLocale`).
|
|
1976
2374
|
* @param {FormatDateFnsOptions} [options] ***Options for formatting and parsing.***
|
|
1977
2375
|
* @param {FormatDateFnsOptions["format"]} [options.format="dd MMM yyyy - HH:mm:ss"]
|
|
1978
2376
|
* ***The output format string (passed to `date-fns/format`), e.g:***
|
|
1979
|
-
*
|
|
2377
|
+
* - `"dd MMMM yyyy, HH:mm:ss" ➔ "14 Juli 2025, 17:25:42"`.
|
|
1980
2378
|
* @param {FormatDateFnsOptions["locale"]} [options.locale="id"]
|
|
1981
2379
|
* The output locale. If string, only `"id"` (Indonesian) or `"en"` (English)
|
|
1982
2380
|
* is recognized. Or you can pass a `date-fns` `Locale` object.
|
|
1983
2381
|
* - Example:
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
1987
|
-
*
|
|
2382
|
+
* ```ts
|
|
2383
|
+
* import { ar } from "date-fns/locale";
|
|
2384
|
+
* formatDateFns(new Date(), { locale: ar, format: "PPPppp" });
|
|
2385
|
+
* ```
|
|
1988
2386
|
* @param {FormatDateFnsOptions["inputLocale"]} [options.inputLocale]
|
|
1989
|
-
*
|
|
2387
|
+
* Required if `date` is a localized non-ISO string. Used with `inputFormat`.
|
|
1990
2388
|
* - Example for Indonesian string:
|
|
1991
|
-
*
|
|
1992
|
-
*
|
|
1993
|
-
*
|
|
2389
|
+
* ```ts
|
|
2390
|
+
* formatDateFns("14 Juli 2025 10:25:42", { inputFormat: "dd MMMM yyyy HH:mm:ss", inputLocale: "id" });
|
|
2391
|
+
* ```
|
|
1994
2392
|
* @param {FormatDateFnsOptions["inputFormat"]} [options.inputFormat]
|
|
1995
2393
|
* The format string to parse `date` if it is a non-ISO string.
|
|
1996
2394
|
* Required together with `inputLocale`.
|
|
2395
|
+
*
|
|
2396
|
+
* ---
|
|
1997
2397
|
* @returns {string | null} A formatted date string or `null` if input is invalid.
|
|
2398
|
+
*
|
|
2399
|
+
* ---
|
|
1998
2400
|
* @example
|
|
1999
2401
|
* formatDateFns(new Date());
|
|
2000
2402
|
* // ➔ "14 Jul 2025 - 17:25:42"
|
|
@@ -2012,14 +2414,18 @@ type FormatDateFnsOptions = Prettify<OmitStrict<FormatOptions, "locale", {
|
|
|
2012
2414
|
declare const formatDateFns: (date: string | Date | null | undefined, options?: FormatDateFnsOptions) => string | null;
|
|
2013
2415
|
/** -------------------------------------------------------------
|
|
2014
2416
|
* * ***Supported IETF BCP-47 locale codes for Intl API.***
|
|
2015
|
-
*
|
|
2417
|
+
* --------------------------------------------------------------
|
|
2016
2418
|
* **This type ensures proper autocompletion & validation in TS
|
|
2017
2419
|
* but does not restrict at runtime (must validate separately).**
|
|
2420
|
+
*
|
|
2421
|
+
* ---
|
|
2018
2422
|
* - **Includes:**
|
|
2019
|
-
*
|
|
2020
|
-
*
|
|
2021
|
-
*
|
|
2022
|
-
*
|
|
2423
|
+
* - Major global locales (`en-US`, `fr-FR`, `zh-CN`, `etc`).
|
|
2424
|
+
* - Regional & minor locales (`mi-NZ`, `rw-RW`, `bi-VU`, `etc`).
|
|
2425
|
+
* - Useful for `Intl.DateTimeFormat`, `Intl.NumberFormat`, `etc`.
|
|
2426
|
+
* - Still allows fallback via `({} & string)` for arbitrary locales.
|
|
2427
|
+
*
|
|
2428
|
+
* ---
|
|
2023
2429
|
* @example
|
|
2024
2430
|
* const locale: SupportedLocales = "fr-CA";
|
|
2025
2431
|
* new Intl.DateTimeFormat(locale).format(new Date());
|
|
@@ -2027,7 +2433,7 @@ declare const formatDateFns: (date: string | Date | null | undefined, options?:
|
|
|
2027
2433
|
type SupportedLocales = "en-US" | "en-GB" | "en-AU" | "en-CA" | "en-NZ" | "en-ZA" | "en-IN" | "en-IE" | "en-SG" | "en-HK" | "en-PH" | "en-MY" | "en-PK" | "en-KE" | "en-TZ" | "en-NG" | "en-LK" | "en-BW" | "en-ZM" | "id-ID" | "ms-MY" | "th-TH" | "vi-VN" | "tl-PH" | "ms-BN" | "zh-CN" | "zh-HK" | "zh-TW" | "zh-SG" | "zh-MO" | "ja-JP" | "ko-KR" | "fr-FR" | "fr-CA" | "fr-BE" | "fr-CH" | "fr-LU" | "fr-MA" | "fr-SN" | "fr-CM" | "fr-CI" | "fr-HT" | "fr-DZ" | "fr-TN" | "fr-ML" | "fr-NC" | "fr-PF" | "fr-GP" | "fr-MQ" | "fr-GF" | "de-DE" | "de-AT" | "de-CH" | "de-LU" | "de-LI" | "es-ES" | "es-MX" | "es-AR" | "es-CL" | "es-CO" | "es-PE" | "es-UY" | "es-VE" | "es-CR" | "es-EC" | "es-GT" | "es-HN" | "es-NI" | "es-PA" | "es-PR" | "es-SV" | "es-BO" | "es-PY" | "es-DO" | "es-CU" | "es-GQ" | "pt-BR" | "pt-PT" | "pt-MZ" | "pt-AO" | "pt-GW" | "pt-CV" | "pt-ST" | "it-IT" | "it-CH" | "it-SM" | "it-VA" | "nl-NL" | "nl-BE" | "nl-SR" | "nl-AW" | "nl-CW" | "ru-RU" | "uk-UA" | "kk-KZ" | "uz-UZ" | "ky-KG" | "tt-RU" | "ba-RU" | "cv-RU" | "sah-RU" | "pl-PL" | "cs-CZ" | "sk-SK" | "hu-HU" | "sl-SI" | "sv-SE" | "da-DK" | "no-NO" | "fi-FI" | "is-IS" | "ro-RO" | "bg-BG" | "hr-HR" | "sr-RS" | "mk-MK" | "bs-BA" | "me-ME" | "sq-AL" | "sq-XK" | "el-GR" | "el-CY" | "tr-TR" | "tr-CY" | "he-IL" | "ar-SA" | "ar-AE" | "ar-EG" | "ar-MA" | "ar-JO" | "ar-LB" | "ar-QA" | "ar-KW" | "ar-OM" | "ar-BH" | "ar-IQ" | "ar-LY" | "ar-TN" | "ar-YE" | "ar-SY" | "ar-PS" | "ar-SD" | "ar-DZ" | "ar-MR" | "ar-DJ" | "ar-SO" | "lt-LT" | "lv-LV" | "et-EE" | "hi-IN" | "bn-BD" | "pa-IN" | "ta-IN" | "te-IN" | "ml-IN" | "gu-IN" | "kn-IN" | "mr-IN" | "or-IN" | "as-IN" | "ne-IN" | "fa-IR" | "ur-PK" | "ps-AF" | "dv-MV" | "sw-KE" | "sw-TZ" | "zu-ZA" | "af-ZA" | "xh-ZA" | "ss-SZ" | "ts-ZA" | "tn-BW" | "ny-MW" | "lo-LA" | "mt-MT" | "ga-IE" | "cy-GB" | "ne-NP" | "si-LK" | "am-ET" | "om-ET" | "ti-ER" | "km-KH" | "my-MM" | "mn-MN" | "tg-TJ" | "tk-TM" | "hy-AM" | "ka-GE" | "az-AZ" | "be-BY" | "mo-MD" | "ro-MD" | "ht-HT" | "jw-ID" | "su-ID" | "to-TO" | "sm-WS" | "mi-NZ" | "bi-VU" | "fj-FJ" | "ty-PF" | "pau-PW" | "niu-NU" | "ck-CK" | "rw-RW" | "ln-CD" | "kg-CD" | "ha-NE" | "yo-NG" | "ig-NG" | "ak-GH" | "lg-UG" | "bo-CN" | "dz-BT" | "iu-CA" | "kl-GL" | "cv-RU" | "pap-AW" | "chr-US" | "haw-US" | "gv-IM" | "gd-GB" | "br-FR" | "co-FR" | "rm-CH" | "wa-BE" | "lb-LU" | "fur-IT" | "sc-IT" | "vec-IT" | "nap-IT" | "gsw-CH" | "rha-CH" | ({} & string);
|
|
2028
2434
|
/** ----------------------------------------------------------------
|
|
2029
2435
|
* * ***Options for formatting dates with `Intl.DateTimeFormat`.***
|
|
2030
|
-
*
|
|
2436
|
+
* -----------------------------------------------------------------
|
|
2031
2437
|
* **Extends the native
|
|
2032
2438
|
* **{@link Intl.DateTimeFormatOptions | `Intl.DateTimeFormatOptions`}** with
|
|
2033
2439
|
* an additional `locale` property that is validated against **{@link SupportedLocales | `SupportedLocales`}**.**
|
|
@@ -2035,13 +2441,20 @@ type SupportedLocales = "en-US" | "en-GB" | "en-AU" | "en-CA" | "en-NZ" | "en-ZA
|
|
|
2035
2441
|
type FormatDateIntlOptions = Prettify<Intl.DateTimeFormatOptions & {
|
|
2036
2442
|
/** ------------------------------------------------------------
|
|
2037
2443
|
* * ***Locale for date formatting.***
|
|
2038
|
-
*
|
|
2444
|
+
* -------------------------------------------------------------
|
|
2039
2445
|
* - **Behavior:**
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2042
|
-
*
|
|
2043
|
-
*
|
|
2044
|
-
*
|
|
2446
|
+
* - Must be a valid [***BCP-47 locale***](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument),
|
|
2447
|
+
* validated against {@link SupportedLocales | **`SupportedLocales`**}.
|
|
2448
|
+
* - If `locale` is `undefined` or an empty string (after trimming),
|
|
2449
|
+
* it will **default to `"en-US"`**.
|
|
2450
|
+
*
|
|
2451
|
+
* ---
|
|
2452
|
+
* @default
|
|
2453
|
+
* ```ts
|
|
2454
|
+
* "en-US"
|
|
2455
|
+
* ```
|
|
2456
|
+
*
|
|
2457
|
+
* ---
|
|
2045
2458
|
* @example
|
|
2046
2459
|
* { year: "numeric", month: "long" }
|
|
2047
2460
|
* // Unset locale, default locale ➔ "en-US"
|
|
@@ -2055,23 +2468,32 @@ type FormatDateIntlOptions = Prettify<Intl.DateTimeFormatOptions & {
|
|
|
2055
2468
|
*/
|
|
2056
2469
|
locale?: SupportedLocales;
|
|
2057
2470
|
}>;
|
|
2058
|
-
/**
|
|
2471
|
+
/** ------------------------------------------------------------------------------------------
|
|
2059
2472
|
* * ***Utility: `formatDateIntl`.***
|
|
2060
|
-
*
|
|
2473
|
+
* -------------------------------------------------------------------------------------------
|
|
2061
2474
|
* **Formats a date using the `Intl.DateTimeFormat` API.**
|
|
2062
|
-
*
|
|
2063
|
-
*
|
|
2064
|
-
*
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2475
|
+
*
|
|
2476
|
+
* ---
|
|
2477
|
+
* - **Features:**
|
|
2478
|
+
* - Supports custom locales (type-safe `SupportedLocales`).
|
|
2479
|
+
* - Accepts additional `Intl.DateTimeFormatOptions` like `timeZone`, `hour12`, etc.
|
|
2480
|
+
* - Defaults to `"en-US"` if `locale` is not provided or is an empty string.
|
|
2481
|
+
* - Returns `null` if the date is invalid, not provided, or options are invalid.
|
|
2482
|
+
*
|
|
2483
|
+
* ---
|
|
2067
2484
|
* @param {string | Date | null | undefined} date
|
|
2068
2485
|
* ***The date to format.***
|
|
2069
|
-
*
|
|
2070
|
-
*
|
|
2486
|
+
* - Can be a `Date` object or an ISO string.
|
|
2487
|
+
* - If invalid or not provided, returns `null`.
|
|
2488
|
+
*
|
|
2071
2489
|
* @param {FormatDateIntlOptions} [options] ***Optional formatting options for `Intl.DateTimeFormat`, use `locale` to specify the language & region format.***
|
|
2490
|
+
*
|
|
2491
|
+
* ---
|
|
2072
2492
|
* @returns {string | null}
|
|
2073
2493
|
* - Formatted date string.
|
|
2074
2494
|
* - Returns `null` if date is invalid or options are of wrong type.
|
|
2495
|
+
*
|
|
2496
|
+
* ---
|
|
2075
2497
|
* @example
|
|
2076
2498
|
* formatDateIntl(new Date());
|
|
2077
2499
|
* // ➔ "7/14/2025"
|
|
@@ -2083,18 +2505,26 @@ type FormatDateIntlOptions = Prettify<Intl.DateTimeFormatOptions & {
|
|
|
2083
2505
|
* // ➔ "01:30 AM"
|
|
2084
2506
|
*/
|
|
2085
2507
|
declare const formatDateIntl: (date: string | Date | null | undefined, options?: FormatDateIntlOptions) => string | null;
|
|
2086
|
-
/**
|
|
2508
|
+
/** -----------------------------------------------------------------------------------
|
|
2087
2509
|
* * ***Utility: `formatDateTime`.***
|
|
2088
|
-
*
|
|
2510
|
+
* ------------------------------------------------------------------------------------
|
|
2089
2511
|
* **Formats a date and time into a custom string format.**
|
|
2512
|
+
*
|
|
2513
|
+
* ---
|
|
2090
2514
|
* - **Features:**
|
|
2091
|
-
*
|
|
2092
|
-
*
|
|
2093
|
-
*
|
|
2094
|
-
*
|
|
2515
|
+
* - Supports only `YYYY`, `MM`, `DD`, `hh`, `mm`, and `ss` as placeholders.
|
|
2516
|
+
* - Uses a simple string replace (no locale).
|
|
2517
|
+
* - Returns `null` if the date is invalid or not provided.
|
|
2518
|
+
* - Defaults to `"YYYY-MM-DD hh:mm:ss"` format if none is specified.
|
|
2519
|
+
*
|
|
2520
|
+
* ---
|
|
2095
2521
|
* @param {string | Date | null| undefined} date - The date to format.
|
|
2096
2522
|
* @param {string} [format="YYYY-MM-DD hh:mm:ss"] - The desired date format, if format is `null` or `undefined` will force to defaultValue, defaultValue is: `"YYYY-MM-DD hh:mm:ss"`.
|
|
2523
|
+
*
|
|
2524
|
+
* ---
|
|
2097
2525
|
* @returns {string | null} The formatted date string or `null` if invalid.
|
|
2526
|
+
*
|
|
2527
|
+
* ---
|
|
2098
2528
|
* @example
|
|
2099
2529
|
* formatDateTime(new Date());
|
|
2100
2530
|
* // ➔ "2024-02-09 14:30:45" (example output with current time)
|
|
@@ -2124,24 +2554,32 @@ declare const formatDateIntl: (date: string | Date | null | undefined, options?:
|
|
|
2124
2554
|
* // ➔ null
|
|
2125
2555
|
*/
|
|
2126
2556
|
declare const formatDateTime: (date: string | Date | null | undefined, format?: string) => string | null;
|
|
2127
|
-
/**
|
|
2557
|
+
/** ----------------------------------------------------------------------------------------------
|
|
2128
2558
|
* * ***Utility: `getGMTOffset`.***
|
|
2129
|
-
*
|
|
2559
|
+
* -----------------------------------------------------------------------------------------------
|
|
2130
2560
|
* **Returns the formatted GMT offset (e.g., `+0700`, `-0500`) for a given date.**
|
|
2561
|
+
*
|
|
2562
|
+
* ---
|
|
2131
2563
|
* - **Features:**
|
|
2132
|
-
*
|
|
2133
|
-
*
|
|
2134
|
-
*
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
2137
|
-
*
|
|
2564
|
+
* - If `date` is **not provided** or empty string, it defaults to the current date/time.
|
|
2565
|
+
* - If `date` is **invalid** or of wrong type (like object or number), it returns `"0"`.
|
|
2566
|
+
* - The returned string follows the **GMT offset format** (`±HHMM`), where:
|
|
2567
|
+
* - `±` is `+` if ahead of UTC, `-` if behind.
|
|
2568
|
+
* - `HH` is two-digit hours.
|
|
2569
|
+
* - `MM` is two-digit minutes.
|
|
2570
|
+
*
|
|
2571
|
+
* ---
|
|
2138
2572
|
* @param {string | Date | null} [date]
|
|
2139
2573
|
* ***The date to get the GMT offset from.***
|
|
2140
|
-
*
|
|
2141
|
-
*
|
|
2142
|
-
*
|
|
2574
|
+
* - Accepts `Date` object or ISO date string (e.g., `"2024-01-01T12:00:00Z"`).
|
|
2575
|
+
* - If `null`, `undefined`, or empty string, uses current system date.
|
|
2576
|
+
* - If invalid date or wrong type (like `123` or `{}`), returns `"0"`.
|
|
2577
|
+
*
|
|
2578
|
+
* ---
|
|
2143
2579
|
* @returns {string} The GMT offset string in format `±HHMM`,
|
|
2144
2580
|
* e.g. `"+0700"`, `"-0530"`, or `"0"` if invalid.
|
|
2581
|
+
*
|
|
2582
|
+
* ---
|
|
2145
2583
|
* @example
|
|
2146
2584
|
* getGMTOffset();
|
|
2147
2585
|
* // ➔ "+0700" (depends on your system timezone)
|