@rzl-zone/utils-js 3.12.1-beta.0 → 3.13.0-beta.2
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 +15 -35
- package/dist/.references/index.d.cts +1 -3
- package/dist/.references/index.d.ts +1 -3
- package/dist/{assertIsArray-BfAbIUfa.js → assertIsArray-6BcSdNa-.js} +3 -3
- package/dist/{assertIsArray-BfAbIUfa.js.map → assertIsArray-6BcSdNa-.js.map} +1 -1
- package/dist/{assertIsArray-BChqwPiP.cjs → assertIsArray-BqjMoan3.cjs} +3 -3
- package/dist/{assertIsArray-BChqwPiP.cjs.map → assertIsArray-BqjMoan3.cjs.map} +1 -1
- package/dist/{assertIsBoolean-BlBct0Fc.js → assertIsBoolean-Bv6gL-xe.js} +8 -8
- package/dist/assertIsBoolean-Bv6gL-xe.js.map +1 -0
- package/dist/{assertIsBoolean-DozdtbNi.cjs → assertIsBoolean-amRiJHnh.cjs} +8 -8
- package/dist/assertIsBoolean-amRiJHnh.cjs.map +1 -0
- package/dist/{assertIsString-DqV9NwbI.js → assertIsString-1WiUjgqf.js} +3 -3
- package/dist/{assertIsString-DqV9NwbI.js.map → assertIsString-1WiUjgqf.js.map} +1 -1
- package/dist/{assertIsString-Bvk7bUL7.cjs → assertIsString-C0b28AU1.cjs} +3 -3
- package/dist/{assertIsString-Bvk7bUL7.cjs.map → assertIsString-C0b28AU1.cjs.map} +1 -1
- package/dist/assertions/index.cjs +5 -5
- package/dist/assertions/index.d.cts +2 -2
- package/dist/assertions/index.d.ts +2 -2
- package/dist/assertions/index.js +5 -5
- 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-EMJa3g-D.js → conversions-BrI0GIOr.js} +16 -18
- package/dist/conversions-BrI0GIOr.js.map +1 -0
- package/dist/{conversions-CBs8-REq.cjs → conversions-lvvAYiZs.cjs} +16 -18
- package/dist/conversions-lvvAYiZs.cjs.map +1 -0
- package/dist/events/index.cjs +4 -4
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.cts +153 -151
- package/dist/events/index.d.ts +153 -151
- package/dist/events/index.js +4 -4
- package/dist/events/index.js.map +1 -1
- 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-lAYgA11L.cjs → formatters-DQr05EUA.cjs} +17 -15
- package/dist/formatters-DQr05EUA.cjs.map +1 -0
- package/dist/{formatters-QcZO_Cpx.js → formatters-zDzQvtb4.js} +17 -15
- package/dist/formatters-zDzQvtb4.js.map +1 -0
- package/dist/generators/index.cjs +12 -8
- 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 +12 -8
- package/dist/generators/index.js.map +1 -1
- package/dist/index-3jBnthag.d.cts +340 -0
- package/dist/index-BXwimNPA.d.cts +2361 -0
- package/dist/index-BlTCrSyc.d.cts +2158 -0
- package/dist/index-CEm8ZOvj.d.ts +2158 -0
- package/dist/index-CLq5kZmQ.d.cts +822 -0
- package/dist/index-Ckao53JY.d.ts +2361 -0
- package/dist/index-DHHrLc0B.d.ts +947 -0
- package/dist/index-DIeR8qa-.d.ts +340 -0
- package/dist/index-DxZlGbAH.d.ts +1716 -0
- package/dist/index-DyVWeYP3.d.cts +765 -0
- package/dist/index-GSUN6rjA.d.ts +822 -0
- package/dist/index-_dJhBl1h.d.ts +765 -0
- package/dist/index-bMa-0Yr4.d.cts +1716 -0
- package/dist/index-z_uCh5KW.d.cts +947 -0
- package/dist/{isBigInt-B1cijjqm.cjs → isBigInt-CIFRnsdx.cjs} +2 -2
- package/dist/{isBigInt-B1cijjqm.cjs.map → isBigInt-CIFRnsdx.cjs.map} +1 -1
- package/dist/{isBigInt-C0bN0Rhu.js → isBigInt-D-Pu9sxp.js} +2 -2
- package/dist/{isBigInt-C0bN0Rhu.js.map → isBigInt-D-Pu9sxp.js.map} +1 -1
- package/dist/{isEmptyObject-DI42NEo0.cjs → isEmptyObject-CEySmyHK.cjs} +3 -3
- package/dist/{isEmptyObject-DI42NEo0.cjs.map → isEmptyObject-CEySmyHK.cjs.map} +1 -1
- package/dist/{isEmptyObject-DeLVIJpl.js → isEmptyObject-CZ9DLi7R.js} +3 -3
- package/dist/{isEmptyObject-DeLVIJpl.js.map → isEmptyObject-CZ9DLi7R.js.map} +1 -1
- package/dist/{isEmptyString-BTUWYTbw.js → isEmptyString-DFDtBbNr.js} +3 -3
- package/dist/{isEmptyString-BTUWYTbw.js.map → isEmptyString-DFDtBbNr.js.map} +1 -1
- package/dist/{isEmptyString-CCK3bP74.cjs → isEmptyString-DI64RQCy.cjs} +3 -3
- package/dist/{isEmptyString-CCK3bP74.cjs.map → isEmptyString-DI64RQCy.cjs.map} +1 -1
- package/dist/{isEmptyValue-DMSMFTU8.cjs → isEmptyValue-Cw6ovu7z.cjs} +5 -5
- package/dist/{isEmptyValue-DMSMFTU8.cjs.map → isEmptyValue-Cw6ovu7z.cjs.map} +1 -1
- package/dist/{isEmptyValue-fjnfQnt5.js → isEmptyValue-aGyeClwA.js} +5 -5
- package/dist/{isEmptyValue-fjnfQnt5.js.map → isEmptyValue-aGyeClwA.js.map} +1 -1
- package/dist/{isEqual-DhyP8fB_.js → isEqual-Dtb2sXUv.js} +4 -4
- package/dist/{isEqual-DhyP8fB_.js.map → isEqual-Dtb2sXUv.js.map} +1 -1
- package/dist/{isEqual-B1fRgEuU.cjs → isEqual-UsvOwrlY.cjs} +4 -4
- package/dist/{isEqual-B1fRgEuU.cjs.map → isEqual-UsvOwrlY.cjs.map} +1 -1
- package/dist/{isFinite-BYMOo0os.js → isFinite-Cz_IFXuV.js} +3 -3
- package/dist/{isFinite-BYMOo0os.js.map → isFinite-Cz_IFXuV.js.map} +1 -1
- package/dist/{isFinite-sFkps2TY.cjs → isFinite-uukWvxJh.cjs} +3 -3
- package/dist/{isFinite-sFkps2TY.cjs.map → isFinite-uukWvxJh.cjs.map} +1 -1
- package/dist/{isInteger-FTCthMre.cjs → isInteger-DPYjliLZ.cjs} +2 -2
- package/dist/{isInteger-FTCthMre.cjs.map → isInteger-DPYjliLZ.cjs.map} +1 -1
- package/dist/{isInteger-DS9V7l_f.js → isInteger-DZ163OQg.js} +2 -2
- package/dist/{isInteger-DS9V7l_f.js.map → isInteger-DZ163OQg.js.map} +1 -1
- package/dist/isPlainObject-CBABRyEX.d.cts +339 -0
- package/dist/isPlainObject-Dr8gi89U.d.ts +339 -0
- package/dist/{isServer-D1TXfOs3.js → isServer-BDShLyVJ.js} +2 -2
- package/dist/{isServer-D1TXfOs3.js.map → isServer-BDShLyVJ.js.map} +1 -1
- package/dist/{isServer-q-QLFCqE.cjs → isServer-BzDeYuGg.cjs} +2 -2
- package/dist/{isServer-q-QLFCqE.cjs.map → isServer-BzDeYuGg.cjs.map} +1 -1
- package/dist/{isTypedArray-DiCoqffZ.cjs → isTypedArray-DaYAkyrt.cjs} +3 -3
- package/dist/{isTypedArray-DiCoqffZ.cjs.map → isTypedArray-DaYAkyrt.cjs.map} +1 -1
- package/dist/{isTypedArray-47R0wdrc.js → isTypedArray-DuUUA4CL.js} +3 -3
- package/dist/{isTypedArray-47R0wdrc.js.map → isTypedArray-DuUUA4CL.js.map} +1 -1
- package/dist/{isValidDomain-BSXshgkC.cjs → isValidDomain-BxyToAlh.cjs} +74 -8
- package/dist/isValidDomain-BxyToAlh.cjs.map +1 -0
- package/dist/{isValidDomain-DwA2EN79.js → isValidDomain-CTw5vZFY.js} +57 -9
- package/dist/isValidDomain-CTw5vZFY.js.map +1 -0
- package/dist/{noop-B2mTBhW-.cjs → noop-7KrqC9DC.cjs} +2 -2
- package/dist/{noop-B2mTBhW-.cjs.map → noop-7KrqC9DC.cjs.map} +1 -1
- package/dist/{noop-BzktGBVz.js → noop-DGg9vMSD.js} +2 -2
- package/dist/{noop-BzktGBVz.js.map → noop-DGg9vMSD.js.map} +1 -1
- package/dist/{normalizeSpaces-DQHR3Tlr.cjs → normalizeSpaces-B6ZQOZRX.cjs} +3 -3
- package/dist/{normalizeSpaces-DQHR3Tlr.cjs.map → normalizeSpaces-B6ZQOZRX.cjs.map} +1 -1
- package/dist/{normalizeSpaces-WS_iERJk.js → normalizeSpaces-C1eLwykD.js} +3 -3
- package/dist/{normalizeSpaces-WS_iERJk.js.map → normalizeSpaces-C1eLwykD.js.map} +1 -1
- package/dist/operations/index.cjs +10 -10
- package/dist/operations/index.cjs.map +1 -1
- package/dist/operations/index.d.cts +120 -120
- package/dist/operations/index.d.ts +120 -120
- package/dist/operations/index.js +10 -10
- package/dist/operations/index.js.map +1 -1
- package/dist/parsers/index.cjs +2 -2
- package/dist/parsers/index.d.cts +222 -222
- package/dist/parsers/index.d.ts +222 -222
- package/dist/parsers/index.js +2 -2
- package/dist/{parsers-DXtpsDyj.cjs → parsers-DEFpCYhw.cjs} +4 -4
- package/dist/{parsers-DXtpsDyj.cjs.map → parsers-DEFpCYhw.cjs.map} +1 -1
- package/dist/{parsers-Dpuq-V4u.js → parsers-bQQ9mStV.js} +4 -4
- package/dist/{parsers-Dpuq-V4u.js.map → parsers-bQQ9mStV.js.map} +1 -1
- package/dist/{parsing-B43x1sxn.js → parsing-BngARhmu.js} +3 -3
- package/dist/{parsing-B43x1sxn.js.map → parsing-BngARhmu.js.map} +1 -1
- package/dist/{parsing-lRoxn1Nz.cjs → parsing-lI5EN4LY.cjs} +3 -3
- package/dist/{parsing-lRoxn1Nz.cjs.map → parsing-lI5EN4LY.cjs.map} +1 -1
- package/dist/predicates/index.cjs +15 -16
- package/dist/predicates/index.d.cts +3 -3
- package/dist/predicates/index.d.ts +3 -3
- package/dist/predicates/index.js +14 -15
- package/dist/{predicates-DiaYA7Ps.cjs → predicates-CMmP3fPJ.cjs} +15 -16
- package/dist/{predicates-DiaYA7Ps.cjs.map → predicates-CMmP3fPJ.cjs.map} +1 -1
- package/dist/{predicates-gNepszvo.js → predicates-V87QD8hs.js} +13 -14
- package/dist/{predicates-gNepszvo.js.map → predicates-V87QD8hs.js.map} +1 -1
- package/dist/promises/index.cjs +4 -4
- package/dist/promises/index.d.cts +101 -101
- package/dist/promises/index.d.ts +101 -101
- package/dist/promises/index.js +4 -4
- package/dist/{punyCode-hmiFzLWT.js → punyCode-BeFYDjj0.js} +6 -6
- package/dist/punyCode-BeFYDjj0.js.map +1 -0
- package/dist/{punyCode-CTWXVVFo.cjs → punyCode-DmTsB7q_.cjs} +6 -6
- package/dist/punyCode-DmTsB7q_.cjs.map +1 -0
- package/dist/{removeSpaces-BE8lfh-4.js → removeSpaces-B96axxP6.js} +7 -4
- package/dist/removeSpaces-B96axxP6.js.map +1 -0
- package/dist/{removeSpaces-DRRxNWlb.cjs → removeSpaces-C8mu_yp3.cjs} +12 -3
- package/dist/removeSpaces-C8mu_yp3.cjs.map +1 -0
- package/dist/rzl-utils.global.js +21 -0
- package/dist/{safeJsonParse-BBnQElk8.cjs → safeJsonParse-BXbtX_j7.cjs} +9 -9
- package/dist/safeJsonParse-BXbtX_j7.cjs.map +1 -0
- package/dist/{safeJsonParse-CXruaP0p.js → safeJsonParse-DyCsTXlU.js} +9 -9
- package/dist/safeJsonParse-DyCsTXlU.js.map +1 -0
- package/dist/{safeStableStringify-BNh3D0K0.js → safeStableStringify-BrOcdX9n.js} +4 -4
- package/dist/{safeStableStringify-BNh3D0K0.js.map → safeStableStringify-BrOcdX9n.js.map} +1 -1
- package/dist/{safeStableStringify-Cc62pfRp.cjs → safeStableStringify-DRYQ56Dg.cjs} +4 -4
- package/dist/{safeStableStringify-Cc62pfRp.cjs.map → safeStableStringify-DRYQ56Dg.cjs.map} +1 -1
- package/dist/strings/index.cjs +12 -10
- 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 +11 -9
- package/dist/strings/index.js.map +1 -1
- package/dist/tailwind/index.cjs +6 -2
- 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-IJvOdkZp.js → tailwind-BZ2_MeNX.js} +18 -8
- package/dist/tailwind-BZ2_MeNX.js.map +1 -0
- package/dist/{tailwind-DJ4cmLUw.cjs → tailwind-C1YtxJ-K.cjs} +39 -5
- package/dist/tailwind-C1YtxJ-K.cjs.map +1 -0
- package/dist/{toStringArrayUnRecursive-xUaU8Ot9.cjs → toStringArrayUnRecursive-D1mPM4wg.cjs} +6 -6
- package/dist/{toStringArrayUnRecursive-xUaU8Ot9.cjs.map → toStringArrayUnRecursive-D1mPM4wg.cjs.map} +1 -1
- package/dist/{toStringArrayUnRecursive-CFs0jTEg.js → toStringArrayUnRecursive-tHp2a7KR.js} +6 -6
- package/dist/{toStringArrayUnRecursive-CFs0jTEg.js.map → toStringArrayUnRecursive-tHp2a7KR.js.map} +1 -1
- package/dist/urls/index.cjs +9 -119
- package/dist/urls/index.d.cts +656 -659
- package/dist/urls/index.d.ts +656 -659
- package/dist/urls/index.js +3 -113
- package/dist/urls-CoxDAoki.js +263 -0
- package/dist/urls-CoxDAoki.js.map +1 -0
- package/dist/urls-DCyx8Wpk.cjs +299 -0
- package/dist/urls-DCyx8Wpk.cjs.map +1 -0
- package/package.json +4 -25
- package/dist/assertIsBoolean-BlBct0Fc.js.map +0 -1
- package/dist/assertIsBoolean-DozdtbNi.cjs.map +0 -1
- package/dist/conversions-CBs8-REq.cjs.map +0 -1
- package/dist/conversions-EMJa3g-D.js.map +0 -1
- package/dist/formatEnvPort-DpIXzPAZ.js +0 -159
- package/dist/formatEnvPort-DpIXzPAZ.js.map +0 -1
- package/dist/formatEnvPort-hHNvOim-.cjs +0 -171
- package/dist/formatEnvPort-hHNvOim-.cjs.map +0 -1
- package/dist/formatters-QcZO_Cpx.js.map +0 -1
- package/dist/formatters-lAYgA11L.cjs.map +0 -1
- package/dist/index-26W7ItWx.d.ts +0 -760
- package/dist/index-BPPQjAfs.d.cts +0 -2359
- package/dist/index-BXjlgBLz.d.cts +0 -2139
- package/dist/index-B_Wwo91H.d.ts +0 -2359
- package/dist/index-CpufydcI.d.cts +0 -704
- package/dist/index-Czc4O526.d.ts +0 -333
- package/dist/index-DPs1_p5G.d.cts +0 -760
- package/dist/index-DRpOyBSC.d.ts +0 -1703
- package/dist/index-DWWvtHUn.d.cts +0 -822
- package/dist/index-DnM0LD0n.d.cts +0 -333
- package/dist/index-GUZ9fK6T.d.ts +0 -2139
- package/dist/index-I4fAzwXV.d.ts +0 -704
- package/dist/index-JDrOl_19.d.ts +0 -822
- package/dist/index-b66P49Qe.d.cts +0 -1703
- package/dist/isPlainObject-DcFGh3_5.d.ts +0 -530
- package/dist/isPlainObject-doTI11Ib.d.cts +0 -530
- package/dist/isURL-CQiowFq2.js +0 -14
- package/dist/isURL-CQiowFq2.js.map +0 -1
- package/dist/isURL-WZypXsax.cjs +0 -20
- package/dist/isURL-WZypXsax.cjs.map +0 -1
- package/dist/isValidDomain-BSXshgkC.cjs.map +0 -1
- package/dist/isValidDomain-DwA2EN79.js.map +0 -1
- package/dist/next/index.cjs +0 -129
- package/dist/next/index.cjs.map +0 -1
- package/dist/next/index.d.cts +0 -226
- package/dist/next/index.d.ts +0 -226
- package/dist/next/index.js +0 -124
- package/dist/next/index.js.map +0 -1
- package/dist/next/server/index.cjs +0 -28
- package/dist/next/server/index.cjs.map +0 -1
- package/dist/next/server/index.d.cts +0 -39
- package/dist/next/server/index.d.ts +0 -39
- package/dist/next/server/index.js +0 -26
- package/dist/next/server/index.js.map +0 -1
- package/dist/normalizeString-2WLth_Gj.js +0 -15
- package/dist/normalizeString-2WLth_Gj.js.map +0 -1
- package/dist/normalizeString-D8euBcRD.cjs +0 -21
- package/dist/normalizeString-D8euBcRD.cjs.map +0 -1
- package/dist/punyCode-CTWXVVFo.cjs.map +0 -1
- package/dist/punyCode-hmiFzLWT.js.map +0 -1
- package/dist/removeSpaces-BE8lfh-4.js.map +0 -1
- package/dist/removeSpaces-DRRxNWlb.cjs.map +0 -1
- package/dist/safeJsonParse-BBnQElk8.cjs.map +0 -1
- package/dist/safeJsonParse-CXruaP0p.js.map +0 -1
- package/dist/tailwind-DJ4cmLUw.cjs.map +0 -1
- package/dist/tailwind-IJvOdkZp.js.map +0 -1
- package/dist/urls/index.cjs.map +0 -1
- package/dist/urls/index.js.map +0 -1
package/dist/promises/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
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
|
* ========================================================================
|
|
@@ -10,114 +10,114 @@
|
|
|
10
10
|
|
|
11
11
|
import { CustomPromiseType } from "@rzl-zone/ts-types-plus";
|
|
12
12
|
/** -------------------------------------------------------------
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
13
|
+
* * ***Utility Class: `CustomPromise`.***
|
|
14
|
+
* -------------------------------------------------------------
|
|
15
|
+
* **A strongly typed extension of the native {@link Promise | **`Promise`**}.**
|
|
16
|
+
* 1. **Behaves exactly like a normal Promise** for `then`/`catch`
|
|
17
|
+
* and `await` semantics.
|
|
18
|
+
* 2. **Stores the final resolution or rejection internally** so
|
|
19
|
+
* it can be retrieved by a custom `finish` handler.
|
|
20
|
+
* 3. **Adds a `finish` method** which runs once after settlement
|
|
21
|
+
* with access to both the fulfilled value *and* the rejection
|
|
22
|
+
* reason (only one will be defined).
|
|
23
|
+
* - **Key Differences from a Native `Promise`:**
|
|
24
|
+
* - Every call to `then`/`catch` returns **`CustomPromise`**
|
|
25
|
+
* again, so the `finish` method remains available on the
|
|
26
|
+
* entire chain.
|
|
27
|
+
* - `finish` provides a tuple-like callback:
|
|
28
|
+
* - `val` → defined when fulfilled.
|
|
29
|
+
* - `err` → defined when rejected.
|
|
30
|
+
* @template Success Type of the resolved value.
|
|
31
|
+
* @template Error Type of the rejection reason (default `unknown`).
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { CustomPromise, type CustomPromiseType } from "@rzl-zone/utils-js/promises";
|
|
35
|
+
*
|
|
36
|
+
* type User = { id: number; name: string };
|
|
37
|
+
* type ApiError = { message: string };
|
|
38
|
+
*
|
|
39
|
+
* function fetchUser(): CustomPromiseType<User, ApiError> {
|
|
40
|
+
* return new CustomPromise<User, ApiError>((resolve, reject) => {
|
|
41
|
+
* setTimeout(
|
|
42
|
+
* () =>
|
|
43
|
+
* void (Math.random() > 0.5
|
|
44
|
+
* ? resolve({ id: 1, name: "Alice" })
|
|
45
|
+
* : reject({ message: "Random failure" })),
|
|
46
|
+
* 500
|
|
47
|
+
* );
|
|
48
|
+
* });
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* fetchUser()
|
|
52
|
+
* .then(user => {
|
|
53
|
+
* console.log("SUCCESS:", user);
|
|
54
|
+
* return user;
|
|
55
|
+
* })
|
|
56
|
+
* .catch(err => {
|
|
57
|
+
* console.error("ERROR:", err);
|
|
58
|
+
* throw err;
|
|
59
|
+
* })
|
|
60
|
+
* .finish((val, err) => {
|
|
61
|
+
* // Runs once after settle, regardless of outcome
|
|
62
|
+
* console.log("FINISH:", { val, err });
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
* ---
|
|
66
|
+
* - **Implementation Notes:**
|
|
67
|
+
* - Uses `Object.setPrototypeOf` to preserve the prototype chain
|
|
68
|
+
* for environments targeting ES5 or when subclassing Promise.
|
|
69
|
+
* - Internal `_value` and `_error` are updated as soon as the
|
|
70
|
+
* executor resolves or rejects, guaranteeing `finish` receives
|
|
71
|
+
* the final state even when added after settlement.
|
|
72
|
+
*/
|
|
73
73
|
declare class CustomPromise<Success, Error = unknown> extends Promise<Success> implements CustomPromiseType<Success, Error> {
|
|
74
74
|
private _value?;
|
|
75
75
|
private _error?;
|
|
76
76
|
private _finish;
|
|
77
77
|
constructor(executor: (resolve: (v: Success) => void, reject: (e: Error) => void) => void);
|
|
78
|
-
then<TResult1 = Success, TResult2 = never>(onfulfilled?: ((value: Success) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null): CustomPromise<TResult1 | TResult2, Error>;
|
|
79
|
-
catch<TResult = never>(onrejected?: ((reason: Error) => TResult | PromiseLike<TResult>) | null): CustomPromise<Success | TResult, Error>;
|
|
78
|
+
override then<TResult1 = Success, TResult2 = never>(onfulfilled?: ((value: Success) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null): CustomPromise<TResult1 | TResult2, Error>;
|
|
79
|
+
override catch<TResult = never>(onrejected?: ((reason: Error) => TResult | PromiseLike<TResult>) | null): CustomPromise<Success | TResult, Error>;
|
|
80
80
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
* Registers a callback to be invoked **exactly once** when the
|
|
82
|
+
* promise settles, with access to both the resolved value and
|
|
83
|
+
* the rejection reason.
|
|
84
|
+
*
|
|
85
|
+
* If the promise is already settled when `finish` is called,
|
|
86
|
+
* the callback executes immediately on the same tick.
|
|
87
|
+
*
|
|
88
|
+
* @param cb Callback receiving the final `(value, error)`.
|
|
89
|
+
* @returns `this` for fluent chaining.
|
|
90
|
+
*/
|
|
91
91
|
finish(cb: (val?: Success, err?: Error) => void): this;
|
|
92
92
|
}
|
|
93
93
|
/** ------------------------------------------------------------
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
94
|
+
* * ***Utility: `delay`.***
|
|
95
|
+
* ------------------------------------------------------------
|
|
96
|
+
* **Creates a Promise-based delay that resolves after a given number
|
|
97
|
+
* of milliseconds, optionally supports cancellation with `AbortSignal`.**
|
|
98
|
+
* - **Behavior:**
|
|
99
|
+
* - Validates `milliSeconds` is a non-zero, non-negative integer.
|
|
100
|
+
* - Validates `signal` is an `AbortSignal` instance when provided.
|
|
101
|
+
* - Cleans up event listeners and timers properly.
|
|
102
|
+
* @param {number} [milliSeconds=1000]
|
|
103
|
+
* The duration of the delay in milliseconds, default is `1000`.
|
|
104
|
+
* @param {AbortSignal} [signal]
|
|
105
|
+
* An optional `AbortSignal` that can cancel the delay.
|
|
106
|
+
* @returns {Promise<void>}
|
|
107
|
+
* A promise that resolves after the specified delay or
|
|
108
|
+
* rejects with an `AbortError` if aborted.
|
|
109
|
+
* @throws **{@link TypeError | `TypeError`}** while validates `milliSeconds` and `signal`:
|
|
110
|
+
* - If `milliSeconds` **is not a valid** an `integer-number`, `NaN`, `negative-number`, or `≤ 0`.
|
|
111
|
+
* - If `signal` **is not a valid** an`AbortSignal`.
|
|
112
|
+
* @throws **{@link DOMException | `DOMException`}** if the delay is aborted using the signal, rejects with `AbortError`.
|
|
113
|
+
* @example
|
|
114
|
+
* // Waits for 2 seconds
|
|
115
|
+
* await delay(2000);
|
|
116
|
+
*
|
|
117
|
+
* // Delay with AbortSignal
|
|
118
|
+
* const controller = new AbortController();
|
|
119
|
+
* delay(5000, controller.signal).catch(err => console.log(err.name)); // "AbortError"
|
|
120
|
+
* controller.abort();
|
|
121
|
+
*/
|
|
122
122
|
declare const delay: (milliSeconds?: number, signal?: AbortSignal) => Promise<void>;
|
|
123
123
|
export { CustomPromise, type CustomPromiseType, delay };
|
package/dist/promises/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
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
|
-
import { E as isNull, r as getPreciseType } from "../assertIsBoolean-
|
|
11
|
-
import { t as safeStableStringify } from "../safeStableStringify-
|
|
12
|
-
import { t as isInteger } from "../isInteger-
|
|
10
|
+
import { E as isNull, r as getPreciseType } from "../assertIsBoolean-Bv6gL-xe.js";
|
|
11
|
+
import { t as safeStableStringify } from "../safeStableStringify-BrOcdX9n.js";
|
|
12
|
+
import { t as isInteger } from "../isInteger-DZ163OQg.js";
|
|
13
13
|
var CustomPromise = class extends Promise {
|
|
14
14
|
_value;
|
|
15
15
|
_error;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
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
|
-
import { r as getPreciseType } from "./assertIsBoolean-
|
|
11
|
-
import { t as assertIsString } from "./assertIsString-
|
|
10
|
+
import { r as getPreciseType } from "./assertIsBoolean-Bv6gL-xe.js";
|
|
11
|
+
import { t as assertIsString } from "./assertIsString-1WiUjgqf.js";
|
|
12
12
|
const maxInt = 2147483647;
|
|
13
13
|
const base = 36, tMin = 1, tMax = 26, skew = 38, damp = 700;
|
|
14
14
|
const initialBias = 72, initialN = 128, delimiter = "-";
|
|
@@ -28,7 +28,7 @@ function error(type) {
|
|
|
28
28
|
function map(array, fn) {
|
|
29
29
|
const result = [];
|
|
30
30
|
let length = array.length;
|
|
31
|
-
while (length--) result[length] = fn(array[length]);
|
|
31
|
+
while (length--) if (array[length]) result[length] = fn(array[length]);
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
34
|
function mapDomain(domain, fn) {
|
|
@@ -36,7 +36,7 @@ function mapDomain(domain, fn) {
|
|
|
36
36
|
let result = "";
|
|
37
37
|
if (parts.length > 1) {
|
|
38
38
|
result = parts[0] + "@";
|
|
39
|
-
domain = parts[1];
|
|
39
|
+
if (parts[1]) domain = parts[1];
|
|
40
40
|
}
|
|
41
41
|
domain = domain.replace(regexSeparators, ".");
|
|
42
42
|
const labels = domain.split(".");
|
|
@@ -176,4 +176,4 @@ const punycodeUtilsJS = {
|
|
|
176
176
|
toUnicode
|
|
177
177
|
};
|
|
178
178
|
export { punycodeUtilsJS as t };
|
|
179
|
-
//# sourceMappingURL=punyCode-
|
|
179
|
+
//# sourceMappingURL=punyCode-BeFYDjj0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"punyCode-BeFYDjj0.js","names":[],"sources":["../src/urls/utils/punyCode.ts"],"sourcesContent":["/** ---------------------------------------------------------\n * * ***Constants for `Punycode-UtilsJS` algorithm.***\n * ---------------------------------------------------------\n * These constants are used internally for encoding and decoding.\n *\n * Unicode domain names to ASCII (`Punycode-UtilsJS`) and vice versa.\n */\n\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { assertIsString } from \"@/assertions/strings/assertIsString\";\n\n/**\n * Constant `maxInt` for validate.\n */\nconst maxInt = 2147483647;\n\n/**\n * Bootstring parameters for `Punycode-UtilsJS`.\n */\nconst base = 36,\n tMin = 1,\n tMax = 26,\n skew = 38,\n damp = 700;\n\n/**\n * Initial bias and code point.\n */\nconst initialBias = 72,\n initialN = 128,\n delimiter = \"-\";\n\n/**\n * Regular expressions used internally.\n * Matches `Punycode-UtilsJS` prefix.\n */\nconst regexPunycode = /^xn--/;\n/**\n * Regular expressions used internally.\n * Matches non-ASCII chars.\n */\nconst regexNonASCII = /[^\\0-\\x7F]/;\n/**\n * Regular expressions used internally.\n * Matches domain label separators.\n */\nconst regexSeparators = /[\\x2E\\u3002\\uFF0E\\uFF61]/g;\n\n/**\n * Error messages used internally.\n */\nconst errors: Record<string, string> = {\n overflow: \"Overflow: input needs wider integers to process\",\n \"not-basic\": \"Illegal input >= 0x80 (not a basic code point)\",\n \"invalid-input\": \"Invalid input\"\n};\n\n/**\n * Aliases of `Math.floor`.\n */\nconst floor = Math.floor;\n/** \n * Aliases of `String.fromCharCode`.\n\n*/\nconst stringFromCharCode = String.fromCharCode;\n\n/** ---------------------------------------------------------\n * * ***Throws a RangeError with a predefined error message.***\n * ---------------------------------------------------------\n *\n * @param type - Key of the error type to throw.\n */\nfunction error(type: keyof typeof errors): never {\n throw new RangeError(errors[type]);\n}\n\n/** ---------------------------------------------------------\n * * ***Maps an array using a callback function.***\n * ---------------------------------------------------------\n *\n * @param array - Array to transform.\n * @param fn - Function to apply to each element.\n * @returns Transformed array.\n */\nfunction map<T, U>(array: T[], fn: (v: T) => U): U[] {\n const result: U[] = [];\n let length = array.length;\n while (length--) {\n if (array[length]) {\n result[length] = fn(array[length]!);\n }\n }\n return result;\n}\n\n/** ---------------------------------------------------------\n * * ***Maps a domain name using a callback on each label.***\n * ---------------------------------------------------------\n *\n * Handles email-like domains (local@domain).\n * @param domain - Domain string to process.\n * @param fn - Function applied to each domain label.\n * @returns Transformed domain string.\n */\nfunction mapDomain(domain: string, fn: (v: string) => string): string {\n const parts = domain.split(\"@\");\n let result = \"\";\n if (parts.length > 1) {\n result = parts[0] + \"@\";\n if (parts[1]) domain = parts[1];\n }\n domain = domain.replace(regexSeparators, \"\\x2E\");\n const labels = domain.split(\".\");\n return result + map(labels, fn).join(\".\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - String to decode.\n * @returns Array of Unicode code points.\n */\nfunction ucs2decode(input: string): number[] {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.ucs2.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n let counter = 0;\n const length = input.length;\n while (counter < length) {\n const value = input.charCodeAt(counter++);\n if (value >= 0xd800 && value <= 0xdbff && counter < length) {\n const extra = input.charCodeAt(counter++);\n if ((extra & 0xfc00) === 0xdc00)\n output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);\n else {\n output.push(value);\n counter--;\n }\n } else output.push(value);\n }\n return output;\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n */\nconst ucs2encode = (points: number[]): string => {\n if (\n !Array.isArray(points) ||\n !points.every((p) => typeof p === \"number\" && Number.isFinite(p))\n ) {\n throw new TypeError(\n `Utils \\`punycodeUtilsJS.ucs2.encode\\`, parameter \\`points\\` must be an array of numbers, but received: \\`${getPreciseType(\n points\n )}\\`.`\n );\n }\n\n return String.fromCodePoint(...points);\n};\n\n/** ---------------------------------------------------------\n * * ***Converts a basic code point to its digit value for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param codePoint - Unicode code point.\n * @returns Digit value.\n */\nfunction basicToDigit(codePoint: number): number {\n if (codePoint >= 0x30 && codePoint < 0x3a) return 26 + (codePoint - 0x30);\n if (codePoint >= 0x41 && codePoint < 0x5b) return codePoint - 0x41;\n if (codePoint >= 0x61 && codePoint < 0x7b) return codePoint - 0x61;\n return base;\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a digit to a basic code point for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param digit - Numeric value.\n * @param flag - Bias flag (0 or 1).\n * @returns Code point.\n */\nfunction digitToBasic(digit: number, flag: number): number {\n return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;\n}\n\n/** ---------------------------------------------------------\n * * ***Bias adaptation function for `Punycode-UtilsJS` encoding/decoding.***\n * ---------------------------------------------------------\n *\n * @param delta - Delta value.\n * @param numPoints - Number of code points.\n * @param firstTime - Indicates first adaptation.\n * @returns Adapted bias.\n */\nfunction adapt(delta: number, numPoints: number, firstTime: boolean): number {\n let k = 0;\n delta = firstTime ? floor(delta / damp) : delta >> 1;\n delta += floor(delta / numPoints);\n while (delta > ((base - tMin) * tMax) >> 1) {\n delta = floor(delta / (base - tMin));\n k += base;\n }\n return floor(k + ((base - tMin + 1) * delta) / (delta + skew));\n}\n\n/** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - `Punycode-UtilsJS` string.\n * @returns Decoded Unicode string.\n */\nfunction decode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n const inputLength = input.length;\n let i = 0,\n n = initialN,\n bias = initialBias;\n\n let basic = input.lastIndexOf(delimiter);\n if (basic < 0) basic = 0;\n\n for (let j = 0; j < basic; j++) {\n if (input.charCodeAt(j) >= 0x80) error(\"not-basic\");\n output.push(input.charCodeAt(j));\n }\n\n for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {\n const oldi = i;\n let w = 1;\n for (let k = base; ; k += base) {\n if (index >= inputLength) error(\"invalid-input\");\n const digit = basicToDigit(input.charCodeAt(index++));\n if (digit >= base) error(\"invalid-input\");\n if (digit > floor((maxInt - i) / w)) error(\"overflow\");\n i += digit * w;\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (digit < t) break;\n const baseMinusT = base - t;\n if (w > floor(maxInt / baseMinusT)) error(\"overflow\");\n w *= baseMinusT;\n }\n const out = output.length + 1;\n bias = adapt(i - oldi, out, oldi === 0);\n if (floor(i / out) > maxInt - n) error(\"overflow\");\n n += floor(i / out);\n i %= out;\n output.splice(i++, 0, n);\n }\n return String.fromCodePoint(...output);\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string.\n * @returns `Punycode-UtilsJS` string.\n */\nfunction encode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.encode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: string[] = [];\n const points = ucs2decode(input);\n const inputLength = points.length;\n let n = initialN,\n delta = 0,\n bias = initialBias;\n\n for (const cp of points) if (cp < 0x80) output.push(stringFromCharCode(cp));\n const basicLength = output.length;\n let handledCPCount = basicLength;\n if (basicLength) output.push(delimiter);\n\n while (handledCPCount < inputLength) {\n let m = maxInt;\n for (const cp of points) if (cp >= n && cp < m) m = cp;\n\n const handledCPCountPlusOne = handledCPCount + 1;\n if (m - n > floor((maxInt - delta) / handledCPCountPlusOne))\n error(\"overflow\");\n delta += (m - n) * handledCPCountPlusOne;\n n = m;\n\n for (const cp of points) {\n if (cp < n) delta++;\n if (cp === n) {\n let q = delta;\n for (let k = base; ; k += base) {\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (q < t) break;\n output.push(\n stringFromCharCode(digitToBasic(t + ((q - t) % (base - t)), 0))\n );\n q = floor((q - t) / (base - t));\n }\n output.push(stringFromCharCode(digitToBasic(q, 0)));\n bias = adapt(\n delta,\n handledCPCountPlusOne,\n handledCPCount === basicLength\n );\n delta = 0;\n handledCPCount++;\n }\n }\n delta++;\n n++;\n }\n\n return output.join(\"\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts `Punycode-UtilsJS` to Unicode for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns Unicode string.\n */\nfunction toUnicode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toUnicode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str\n );\n}\n\n/** ---------------------------------------------------------\n * * ***Converts Unicode to ASCII (`Punycode-UtilsJS`) for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns ASCII string.\n */\nfunction toASCII(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toASCII\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexNonASCII.test(str) ? \"xn--\" + encode(str) : str\n );\n}\n\ntype PunycodeUtilsJS = {\n /** ---------------------------------------------------------\n * * ***Version of the `Punycode-UtilsJS` implementation.***\n * ---------------------------------------------------------\n *\n * @example\n * console.log(punycodeUtilsJS.version); // \"1.0.0\"\n */\n version: string;\n /** ---------------------------------------------------------\n * * ***UCS-2 utility functions.***\n * ---------------------------------------------------------\n */\n ucs2: {\n /** ---------------------------------------------------------\n * * ***Decodes a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - The UCS-2 string to decode.\n * @returns Array of Unicode code points.\n * @example\n * punycodeUtilsJS.ucs2.decode(\"𐍈\");\n * // ➔ [66376]\n */\n decode: (input: string) => number[];\n /** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a UCS-2 string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n * @example\n * punycodeUtilsJS.ucs2.encode([66376]);\n * // ➔ \"𐍈\"\n */\n encode: (points: number[]) => string;\n };\n /** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to a Unicode string.***\n * ---------------------------------------------------------\n *\n * @param input - The `Punycode-UtilsJS` string to decode.\n * @returns Decoded Unicode string.\n * @example\n * punycodeUtilsJS.decode(\"xn--fsq\");\n * // ➔ \"ü\"\n */\n decode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string to encode.\n * @returns `Punycode-UtilsJS` string.\n * @example\n * punycodeUtilsJS.encode(\"ü\");\n * // ➔ \"xn--fsq\"\n */\n encode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts a Unicode domain or label to ASCII (`Punycode-UtilsJS`).***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label string.\n * @returns ASCII string suitable for DNS.\n * @example\n * punycodeUtilsJS.toASCII(\"пример.рф\");\n * // ➔ \"xn--e1afmkfd.xn--p1ai\"\n */\n toASCII: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts an ASCII (`Punycode-UtilsJS`) domain or label to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - ASCII string (with xn-- prefix if needed).\n * @returns Unicode string.\n * @example\n * punycodeUtilsJS.toUnicode(\"xn--e1afmkfd.xn--p1ai\");\n * // ➔ \"пример.рф\"\n */\n toUnicode: (input: string) => string;\n};\n\n/** ---------------------------------------------------------\n * * ***`Punycode-UtilsJS` object exposing all API functions and version.***\n * ---------------------------------------------------------\n * Provides encoding and decoding of Unicode domain names to ASCII (`Punycode-UtilsJS`)\n * and vice versa.\n *\n * - Useful for IDN (Internationalized Domain Names) support.\n */\nconst punycodeUtilsJS: PunycodeUtilsJS = {\n version: \"1.0.0\",\n ucs2: {\n decode: ucs2decode,\n encode: ucs2encode\n },\n decode: decode,\n encode: encode,\n toASCII: toASCII,\n toUnicode: toUnicode\n};\n\n/**\n * Export individual functions.\n */\nexport { punycodeUtilsJS };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,SAAS;;;;AAKf,MAAM,OAAO,IACX,OAAO,GACP,OAAO,IACP,OAAO,IACP,OAAO;;;;AAKT,MAAM,cAAc,IAClB,WAAW,KACX,YAAY;;;;;AAMd,MAAM,gBAAgB;;;;;AAKtB,MAAM,gBAAgB;;;;;AAKtB,MAAM,kBAAkB;;;;AAKxB,MAAM,SAAiC;CACrC,UAAU;CACV,aAAa;CACb,iBAAiB;CAClB;;;;AAKD,MAAM,QAAQ,KAAK;;;;;AAKnB,MAAM,qBAAqB,OAAO;;;;;;;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@@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
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
|
"use strict";
|
|
11
|
-
const require_assertIsBoolean = require('./assertIsBoolean-
|
|
12
|
-
const require_assertIsString = require('./assertIsString-
|
|
11
|
+
const require_assertIsBoolean = require('./assertIsBoolean-amRiJHnh.cjs');
|
|
12
|
+
const require_assertIsString = require('./assertIsString-C0b28AU1.cjs');
|
|
13
13
|
const maxInt = 2147483647;
|
|
14
14
|
const base = 36, tMin = 1, tMax = 26, skew = 38, damp = 700;
|
|
15
15
|
const initialBias = 72, initialN = 128, delimiter = "-";
|
|
@@ -29,7 +29,7 @@ function error(type) {
|
|
|
29
29
|
function map(array, fn) {
|
|
30
30
|
const result = [];
|
|
31
31
|
let length = array.length;
|
|
32
|
-
while (length--) result[length] = fn(array[length]);
|
|
32
|
+
while (length--) if (array[length]) result[length] = fn(array[length]);
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
35
|
function mapDomain(domain, fn) {
|
|
@@ -37,7 +37,7 @@ function mapDomain(domain, fn) {
|
|
|
37
37
|
let result = "";
|
|
38
38
|
if (parts.length > 1) {
|
|
39
39
|
result = parts[0] + "@";
|
|
40
|
-
domain = parts[1];
|
|
40
|
+
if (parts[1]) domain = parts[1];
|
|
41
41
|
}
|
|
42
42
|
domain = domain.replace(regexSeparators, ".");
|
|
43
43
|
const labels = domain.split(".");
|
|
@@ -182,4 +182,4 @@ Object.defineProperty(exports, 'punycodeUtilsJS', {
|
|
|
182
182
|
return punycodeUtilsJS;
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
|
-
//# sourceMappingURL=punyCode-
|
|
185
|
+
//# sourceMappingURL=punyCode-DmTsB7q_.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"punyCode-DmTsB7q_.cjs","names":["getPreciseType"],"sources":["../src/urls/utils/punyCode.ts"],"sourcesContent":["/** ---------------------------------------------------------\n * * ***Constants for `Punycode-UtilsJS` algorithm.***\n * ---------------------------------------------------------\n * These constants are used internally for encoding and decoding.\n *\n * Unicode domain names to ASCII (`Punycode-UtilsJS`) and vice versa.\n */\n\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { assertIsString } from \"@/assertions/strings/assertIsString\";\n\n/**\n * Constant `maxInt` for validate.\n */\nconst maxInt = 2147483647;\n\n/**\n * Bootstring parameters for `Punycode-UtilsJS`.\n */\nconst base = 36,\n tMin = 1,\n tMax = 26,\n skew = 38,\n damp = 700;\n\n/**\n * Initial bias and code point.\n */\nconst initialBias = 72,\n initialN = 128,\n delimiter = \"-\";\n\n/**\n * Regular expressions used internally.\n * Matches `Punycode-UtilsJS` prefix.\n */\nconst regexPunycode = /^xn--/;\n/**\n * Regular expressions used internally.\n * Matches non-ASCII chars.\n */\nconst regexNonASCII = /[^\\0-\\x7F]/;\n/**\n * Regular expressions used internally.\n * Matches domain label separators.\n */\nconst regexSeparators = /[\\x2E\\u3002\\uFF0E\\uFF61]/g;\n\n/**\n * Error messages used internally.\n */\nconst errors: Record<string, string> = {\n overflow: \"Overflow: input needs wider integers to process\",\n \"not-basic\": \"Illegal input >= 0x80 (not a basic code point)\",\n \"invalid-input\": \"Invalid input\"\n};\n\n/**\n * Aliases of `Math.floor`.\n */\nconst floor = Math.floor;\n/** \n * Aliases of `String.fromCharCode`.\n\n*/\nconst stringFromCharCode = String.fromCharCode;\n\n/** ---------------------------------------------------------\n * * ***Throws a RangeError with a predefined error message.***\n * ---------------------------------------------------------\n *\n * @param type - Key of the error type to throw.\n */\nfunction error(type: keyof typeof errors): never {\n throw new RangeError(errors[type]);\n}\n\n/** ---------------------------------------------------------\n * * ***Maps an array using a callback function.***\n * ---------------------------------------------------------\n *\n * @param array - Array to transform.\n * @param fn - Function to apply to each element.\n * @returns Transformed array.\n */\nfunction map<T, U>(array: T[], fn: (v: T) => U): U[] {\n const result: U[] = [];\n let length = array.length;\n while (length--) {\n if (array[length]) {\n result[length] = fn(array[length]!);\n }\n }\n return result;\n}\n\n/** ---------------------------------------------------------\n * * ***Maps a domain name using a callback on each label.***\n * ---------------------------------------------------------\n *\n * Handles email-like domains (local@domain).\n * @param domain - Domain string to process.\n * @param fn - Function applied to each domain label.\n * @returns Transformed domain string.\n */\nfunction mapDomain(domain: string, fn: (v: string) => string): string {\n const parts = domain.split(\"@\");\n let result = \"\";\n if (parts.length > 1) {\n result = parts[0] + \"@\";\n if (parts[1]) domain = parts[1];\n }\n domain = domain.replace(regexSeparators, \"\\x2E\");\n const labels = domain.split(\".\");\n return result + map(labels, fn).join(\".\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - String to decode.\n * @returns Array of Unicode code points.\n */\nfunction ucs2decode(input: string): number[] {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.ucs2.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n let counter = 0;\n const length = input.length;\n while (counter < length) {\n const value = input.charCodeAt(counter++);\n if (value >= 0xd800 && value <= 0xdbff && counter < length) {\n const extra = input.charCodeAt(counter++);\n if ((extra & 0xfc00) === 0xdc00)\n output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);\n else {\n output.push(value);\n counter--;\n }\n } else output.push(value);\n }\n return output;\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n */\nconst ucs2encode = (points: number[]): string => {\n if (\n !Array.isArray(points) ||\n !points.every((p) => typeof p === \"number\" && Number.isFinite(p))\n ) {\n throw new TypeError(\n `Utils \\`punycodeUtilsJS.ucs2.encode\\`, parameter \\`points\\` must be an array of numbers, but received: \\`${getPreciseType(\n points\n )}\\`.`\n );\n }\n\n return String.fromCodePoint(...points);\n};\n\n/** ---------------------------------------------------------\n * * ***Converts a basic code point to its digit value for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param codePoint - Unicode code point.\n * @returns Digit value.\n */\nfunction basicToDigit(codePoint: number): number {\n if (codePoint >= 0x30 && codePoint < 0x3a) return 26 + (codePoint - 0x30);\n if (codePoint >= 0x41 && codePoint < 0x5b) return codePoint - 0x41;\n if (codePoint >= 0x61 && codePoint < 0x7b) return codePoint - 0x61;\n return base;\n}\n\n/** ---------------------------------------------------------\n * * ***Converts a digit to a basic code point for `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param digit - Numeric value.\n * @param flag - Bias flag (0 or 1).\n * @returns Code point.\n */\nfunction digitToBasic(digit: number, flag: number): number {\n return digit + 22 + 75 * (digit < 26 ? 1 : 0) - Number(flag !== 0) * 32;\n}\n\n/** ---------------------------------------------------------\n * * ***Bias adaptation function for `Punycode-UtilsJS` encoding/decoding.***\n * ---------------------------------------------------------\n *\n * @param delta - Delta value.\n * @param numPoints - Number of code points.\n * @param firstTime - Indicates first adaptation.\n * @returns Adapted bias.\n */\nfunction adapt(delta: number, numPoints: number, firstTime: boolean): number {\n let k = 0;\n delta = firstTime ? floor(delta / damp) : delta >> 1;\n delta += floor(delta / numPoints);\n while (delta > ((base - tMin) * tMax) >> 1) {\n delta = floor(delta / (base - tMin));\n k += base;\n }\n return floor(k + ((base - tMin + 1) * delta) / (delta + skew));\n}\n\n/** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - `Punycode-UtilsJS` string.\n * @returns Decoded Unicode string.\n */\nfunction decode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.decode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: number[] = [];\n const inputLength = input.length;\n let i = 0,\n n = initialN,\n bias = initialBias;\n\n let basic = input.lastIndexOf(delimiter);\n if (basic < 0) basic = 0;\n\n for (let j = 0; j < basic; j++) {\n if (input.charCodeAt(j) >= 0x80) error(\"not-basic\");\n output.push(input.charCodeAt(j));\n }\n\n for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {\n const oldi = i;\n let w = 1;\n for (let k = base; ; k += base) {\n if (index >= inputLength) error(\"invalid-input\");\n const digit = basicToDigit(input.charCodeAt(index++));\n if (digit >= base) error(\"invalid-input\");\n if (digit > floor((maxInt - i) / w)) error(\"overflow\");\n i += digit * w;\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (digit < t) break;\n const baseMinusT = base - t;\n if (w > floor(maxInt / baseMinusT)) error(\"overflow\");\n w *= baseMinusT;\n }\n const out = output.length + 1;\n bias = adapt(i - oldi, out, oldi === 0);\n if (floor(i / out) > maxInt - n) error(\"overflow\");\n n += floor(i / out);\n i %= out;\n output.splice(i++, 0, n);\n }\n return String.fromCodePoint(...output);\n}\n\n/** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string.\n * @returns `Punycode-UtilsJS` string.\n */\nfunction encode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.encode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const output: string[] = [];\n const points = ucs2decode(input);\n const inputLength = points.length;\n let n = initialN,\n delta = 0,\n bias = initialBias;\n\n for (const cp of points) if (cp < 0x80) output.push(stringFromCharCode(cp));\n const basicLength = output.length;\n let handledCPCount = basicLength;\n if (basicLength) output.push(delimiter);\n\n while (handledCPCount < inputLength) {\n let m = maxInt;\n for (const cp of points) if (cp >= n && cp < m) m = cp;\n\n const handledCPCountPlusOne = handledCPCount + 1;\n if (m - n > floor((maxInt - delta) / handledCPCountPlusOne))\n error(\"overflow\");\n delta += (m - n) * handledCPCountPlusOne;\n n = m;\n\n for (const cp of points) {\n if (cp < n) delta++;\n if (cp === n) {\n let q = delta;\n for (let k = base; ; k += base) {\n const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;\n if (q < t) break;\n output.push(\n stringFromCharCode(digitToBasic(t + ((q - t) % (base - t)), 0))\n );\n q = floor((q - t) / (base - t));\n }\n output.push(stringFromCharCode(digitToBasic(q, 0)));\n bias = adapt(\n delta,\n handledCPCountPlusOne,\n handledCPCount === basicLength\n );\n delta = 0;\n handledCPCount++;\n }\n }\n delta++;\n n++;\n }\n\n return output.join(\"\");\n}\n\n/** ---------------------------------------------------------\n * * ***Converts `Punycode-UtilsJS` to Unicode for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns Unicode string.\n */\nfunction toUnicode(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toUnicode\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexPunycode.test(str) ? decode(str.slice(4).toLowerCase()) : str\n );\n}\n\n/** ---------------------------------------------------------\n * * ***Converts Unicode to ASCII (`Punycode-UtilsJS`) for domain names.***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label.\n * @returns ASCII string.\n */\nfunction toASCII(input: string): string {\n assertIsString(input, {\n message: ({ currentType, validType }) =>\n `Utils \\`punycodeUtilsJS.toASCII\\`, parameter \\`input\\` must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n return mapDomain(input, (str) =>\n regexNonASCII.test(str) ? \"xn--\" + encode(str) : str\n );\n}\n\ntype PunycodeUtilsJS = {\n /** ---------------------------------------------------------\n * * ***Version of the `Punycode-UtilsJS` implementation.***\n * ---------------------------------------------------------\n *\n * @example\n * console.log(punycodeUtilsJS.version); // \"1.0.0\"\n */\n version: string;\n /** ---------------------------------------------------------\n * * ***UCS-2 utility functions.***\n * ---------------------------------------------------------\n */\n ucs2: {\n /** ---------------------------------------------------------\n * * ***Decodes a UCS-2 encoded string to an array of Unicode code points.***\n * ---------------------------------------------------------\n *\n * @param input - The UCS-2 string to decode.\n * @returns Array of Unicode code points.\n * @example\n * punycodeUtilsJS.ucs2.decode(\"𐍈\");\n * // ➔ [66376]\n */\n decode: (input: string) => number[];\n /** ---------------------------------------------------------\n * * ***Encodes an array of Unicode code points to a UCS-2 string.***\n * ---------------------------------------------------------\n *\n * @param points - Array of Unicode code points.\n * @returns Encoded string.\n * @example\n * punycodeUtilsJS.ucs2.encode([66376]);\n * // ➔ \"𐍈\"\n */\n encode: (points: number[]) => string;\n };\n /** ---------------------------------------------------------\n * * ***Decodes a `Punycode-UtilsJS` string to a Unicode string.***\n * ---------------------------------------------------------\n *\n * @param input - The `Punycode-UtilsJS` string to decode.\n * @returns Decoded Unicode string.\n * @example\n * punycodeUtilsJS.decode(\"xn--fsq\");\n * // ➔ \"ü\"\n */\n decode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Encodes a Unicode string to `Punycode-UtilsJS`.***\n * ---------------------------------------------------------\n *\n * @param input - Unicode string to encode.\n * @returns `Punycode-UtilsJS` string.\n * @example\n * punycodeUtilsJS.encode(\"ü\");\n * // ➔ \"xn--fsq\"\n */\n encode: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts a Unicode domain or label to ASCII (`Punycode-UtilsJS`).***\n * ---------------------------------------------------------\n *\n * @param input - Domain or label string.\n * @returns ASCII string suitable for DNS.\n * @example\n * punycodeUtilsJS.toASCII(\"пример.рф\");\n * // ➔ \"xn--e1afmkfd.xn--p1ai\"\n */\n toASCII: (input: string) => string;\n /** ---------------------------------------------------------\n * * ***Converts an ASCII (`Punycode-UtilsJS`) domain or label to Unicode.***\n * ---------------------------------------------------------\n *\n * @param input - ASCII string (with xn-- prefix if needed).\n * @returns Unicode string.\n * @example\n * punycodeUtilsJS.toUnicode(\"xn--e1afmkfd.xn--p1ai\");\n * // ➔ \"пример.рф\"\n */\n toUnicode: (input: string) => string;\n};\n\n/** ---------------------------------------------------------\n * * ***`Punycode-UtilsJS` object exposing all API functions and version.***\n * ---------------------------------------------------------\n * Provides encoding and decoding of Unicode domain names to ASCII (`Punycode-UtilsJS`)\n * and vice versa.\n *\n * - Useful for IDN (Internationalized Domain Names) support.\n */\nconst punycodeUtilsJS: PunycodeUtilsJS = {\n version: \"1.0.0\",\n ucs2: {\n decode: ucs2decode,\n encode: ucs2encode\n },\n decode: decode,\n encode: encode,\n toASCII: toASCII,\n toUnicode: toUnicode\n};\n\n/**\n * Export individual functions.\n */\nexport { punycodeUtilsJS };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,SAAS;;;;AAKf,MAAM,OAAO,IACX,OAAO,GACP,OAAO,IACP,OAAO,IACP,OAAO;;;;AAKT,MAAM,cAAc,IAClB,WAAW,KACX,YAAY;;;;;AAMd,MAAM,gBAAgB;;;;;AAKtB,MAAM,gBAAgB;;;;;AAKtB,MAAM,kBAAkB;;;;AAKxB,MAAM,SAAiC;CACrC,UAAU;CACV,aAAa;CACb,iBAAiB;CAClB;;;;AAKD,MAAM,QAAQ,KAAK;;;;;AAKnB,MAAM,qBAAqB,OAAO;;;;;;;AAQlC,SAAS,MAAM,MAAkC;CAC/C,MAAM,IAAI,WAAW,OAAO,MAAM;;;;;;;;;;AAWpC,SAAS,IAAU,OAAY,IAAsB;CACnD,MAAM,SAAc,EAAE;CACtB,IAAI,SAAS,MAAM;CACnB,OAAO,UACL,IAAI,MAAM,SACR,OAAO,UAAU,GAAG,MAAM,QAAS;CAGvC,OAAO;;;;;;;;;;;AAYT,SAAS,UAAU,QAAgB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AAK,MAAM;KAC9B,MAAM,IAAI,KAAK,OAAO,OAAO,KAAK,OAAO,OAAO,OAAO,IAAI;KAC3D,IAAI,IAAI,GAAG;KACX,OAAO,KACL,mBAAmB,aAAa,KAAM,IAAI,MAAM,OAAO,IAAK,EAAE,CAAC,CAChE;KACD,IAAI,OAAO,IAAI,MAAM,OAAO,GAAG;;IAEjC,OAAO,KAAK,mBAAmB,aAAa,GAAG,EAAE,CAAC,CAAC;IACnD,OAAO,MACL,OACA,uBACA,mBAAmB,YACpB;IACD,QAAQ;IACR;;;EAGJ;EACA;;CAGF,OAAO,OAAO,KAAK,GAAG;;;;;;;;;AAUxB,SAAS,UAAU,OAAuB;CACxC,sCAAe,OAAO,EACpB,UAAU,EAAE,aAAa,gBACvB,8EAA8E,UAAU,sBAAsB,YAAY,MAC7H,CAAC;CAEF,OAAO,UAAU,QAAQ,QACvB,cAAc,KAAK,IAAI,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC,aAAa,CAAC,GAAG,IAChE;;;;;;;;;AAUH,SAAS,QAAQ,OAAuB;CACtC,sCAAe,OAAO,EACpB,UAAU,EAAE,aAAa,gBACvB,4EAA4E,UAAU,sBAAsB,YAAY,MAC3H,CAAC;CAEF,OAAO,UAAU,QAAQ,QACvB,cAAc,KAAK,IAAI,GAAG,SAAS,OAAO,IAAI,GAAG,IAClD;;;;;;;;;;AA8FH,MAAM,kBAAmC;CACvC,SAAS;CACT,MAAM;EACJ,QAAQ;EACR,QAAQ;EACT;CACO;CACA;CACC;CACE;CACZ"}
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
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
|
-
import { A as isPlainObject, y as isNonEmptyString } from "./assertIsBoolean-
|
|
10
|
+
import { A as isPlainObject, y as isNonEmptyString } from "./assertIsBoolean-Bv6gL-xe.js";
|
|
11
|
+
const normalizeString = (input) => {
|
|
12
|
+
return isNonEmptyString(input) ? input.trim() : "";
|
|
13
|
+
};
|
|
11
14
|
const removeSpaces = (value, options = { trimOnly: false }) => {
|
|
12
15
|
if (!isNonEmptyString(value)) return "";
|
|
13
16
|
if (!isPlainObject(options)) options = {};
|
|
@@ -15,5 +18,5 @@ const removeSpaces = (value, options = { trimOnly: false }) => {
|
|
|
15
18
|
if (trimOnly) return value.trim();
|
|
16
19
|
return value.replace(/\s+/g, "");
|
|
17
20
|
};
|
|
18
|
-
export { removeSpaces as t };
|
|
19
|
-
//# sourceMappingURL=removeSpaces-
|
|
21
|
+
export { normalizeString as n, removeSpaces as t };
|
|
22
|
+
//# sourceMappingURL=removeSpaces-B96axxP6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeSpaces-B96axxP6.js","names":[],"sources":["../src/strings/sanitizations/normalizeString.ts","../src/strings/sanitizations/removeSpaces.ts"],"sourcesContent":["import { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeString`.***\n * ----------------------------------------------------------\n * **Normalizes a string by ensuring it is a valid string and trimming whitespace.**\n * - **Behavior:**\n * - If the input is `undefined`, `null`, or an `empty string` after trimming,\n * it returns an empty string `(\"\")`.\n * @param {string | undefined | null} input - The input string to be normalize. If `null` or `undefined`, returns an empty string.\n * @returns {string} A trimmed string or an empty string if the input is invalid.\n * @example\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\"\");\n * // ➔ \"\"\n * normalizeString(null);\n * // ➔ \"\"\n * normalizeString(undefined);\n * // ➔ \"\"\n */\nexport const normalizeString = (input: string | null | undefined): string => {\n return isNonEmptyString(input) ? input.trim() : \"\";\n};\n","import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype RemoveSpacesOptions = {\n /** If `true`, only trims the string, defaultValue: `false`.\n *\n * @default false\n */\n trimOnly?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `removeSpaces`.***\n * ----------------------------------------------------------\n * **Removes all spaces from a string or trims only, based on the options provided.**\n * - **Behavior:**\n * - If `trimOnly` is `true`, the string is simply trimmed.\n * - Otherwise, removes **all spaces**, tabs, newlines, etc.\n * - If the input is `null` or `undefined`, returns an empty string `(\"\")`.\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {RemoveSpacesOptions} [options] - The options object.\n * @param {RemoveSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, only trims the string without removing spaces inside.\n * @returns {string} The processed string.\n * @example\n * removeSpaces(\" Hello World \");\n * // ➔ \"HelloWorld\"\n * removeSpaces(\" Hello World \", { trimOnly: true });\n * // ➔ \"Hello World\"\n * removeSpaces(null);\n * // ➔ \"\"\n */\nexport const removeSpaces = (\n value: string | null | undefined,\n options: RemoveSpacesOptions = {\n trimOnly: false\n }\n): string => {\n if (!isNonEmptyString(value)) return \"\";\n\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { trimOnly = false } = options;\n\n if (trimOnly) return value.trim();\n\n // Remove all spaces (including tabs, newlines, etc.)\n return value.replace(/\\s+/g, \"\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,mBAAmB,UAA6C;CAC3E,OAAO,iBAAiB,MAAM,GAAG,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;ACOlD,MAAa,gBACX,OACA,UAA+B,EAC7B,UAAU,OACX,KACU;CACX,IAAI,CAAC,iBAAiB,MAAM,EAAE,OAAO;CAErC,IAAI,CAAC,cAAc,QAAQ,EACzB,UAAU,EAAE;CAGd,MAAM,EAAE,WAAW,UAAU;CAE7B,IAAI,UAAU,OAAO,MAAM,MAAM;CAGjC,OAAO,MAAM,QAAQ,QAAQ,GAAG"}
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.
|
|
5
|
+
* Version: `3.13.0-beta.2`
|
|
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
|
"use strict";
|
|
11
|
-
const require_assertIsBoolean = require('./assertIsBoolean-
|
|
11
|
+
const require_assertIsBoolean = require('./assertIsBoolean-amRiJHnh.cjs');
|
|
12
|
+
const normalizeString = (input) => {
|
|
13
|
+
return require_assertIsBoolean.isNonEmptyString(input) ? input.trim() : "";
|
|
14
|
+
};
|
|
12
15
|
const removeSpaces = (value, options = { trimOnly: false }) => {
|
|
13
16
|
if (!require_assertIsBoolean.isNonEmptyString(value)) return "";
|
|
14
17
|
if (!require_assertIsBoolean.isPlainObject(options)) options = {};
|
|
@@ -16,10 +19,16 @@ const removeSpaces = (value, options = { trimOnly: false }) => {
|
|
|
16
19
|
if (trimOnly) return value.trim();
|
|
17
20
|
return value.replace(/\s+/g, "");
|
|
18
21
|
};
|
|
22
|
+
Object.defineProperty(exports, 'normalizeString', {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return normalizeString;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
19
28
|
Object.defineProperty(exports, 'removeSpaces', {
|
|
20
29
|
enumerable: true,
|
|
21
30
|
get: function () {
|
|
22
31
|
return removeSpaces;
|
|
23
32
|
}
|
|
24
33
|
});
|
|
25
|
-
//# sourceMappingURL=removeSpaces-
|
|
34
|
+
//# sourceMappingURL=removeSpaces-C8mu_yp3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeSpaces-C8mu_yp3.cjs","names":["isNonEmptyString","isNonEmptyString","isPlainObject"],"sources":["../src/strings/sanitizations/normalizeString.ts","../src/strings/sanitizations/removeSpaces.ts"],"sourcesContent":["import { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeString`.***\n * ----------------------------------------------------------\n * **Normalizes a string by ensuring it is a valid string and trimming whitespace.**\n * - **Behavior:**\n * - If the input is `undefined`, `null`, or an `empty string` after trimming,\n * it returns an empty string `(\"\")`.\n * @param {string | undefined | null} input - The input string to be normalize. If `null` or `undefined`, returns an empty string.\n * @returns {string} A trimmed string or an empty string if the input is invalid.\n * @example\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\"\");\n * // ➔ \"\"\n * normalizeString(null);\n * // ➔ \"\"\n * normalizeString(undefined);\n * // ➔ \"\"\n */\nexport const normalizeString = (input: string | null | undefined): string => {\n return isNonEmptyString(input) ? input.trim() : \"\";\n};\n","import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype RemoveSpacesOptions = {\n /** If `true`, only trims the string, defaultValue: `false`.\n *\n * @default false\n */\n trimOnly?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `removeSpaces`.***\n * ----------------------------------------------------------\n * **Removes all spaces from a string or trims only, based on the options provided.**\n * - **Behavior:**\n * - If `trimOnly` is `true`, the string is simply trimmed.\n * - Otherwise, removes **all spaces**, tabs, newlines, etc.\n * - If the input is `null` or `undefined`, returns an empty string `(\"\")`.\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {RemoveSpacesOptions} [options] - The options object.\n * @param {RemoveSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, only trims the string without removing spaces inside.\n * @returns {string} The processed string.\n * @example\n * removeSpaces(\" Hello World \");\n * // ➔ \"HelloWorld\"\n * removeSpaces(\" Hello World \", { trimOnly: true });\n * // ➔ \"Hello World\"\n * removeSpaces(null);\n * // ➔ \"\"\n */\nexport const removeSpaces = (\n value: string | null | undefined,\n options: RemoveSpacesOptions = {\n trimOnly: false\n }\n): string => {\n if (!isNonEmptyString(value)) return \"\";\n\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { trimOnly = false } = options;\n\n if (trimOnly) return value.trim();\n\n // Remove all spaces (including tabs, newlines, etc.)\n return value.replace(/\\s+/g, \"\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,mBAAmB,UAA6C;CAC3E,OAAOA,yCAAiB,MAAM,GAAG,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;ACOlD,MAAa,gBACX,OACA,UAA+B,EAC7B,UAAU,OACX,KACU;CACX,IAAI,CAACC,yCAAiB,MAAM,EAAE,OAAO;CAErC,IAAI,CAACC,sCAAc,QAAQ,EACzB,UAAU,EAAE;CAGd,MAAM,EAAE,WAAW,UAAU;CAE7B,IAAI,UAAU,OAAO,MAAM,MAAM;CAGjC,OAAO,MAAM,QAAQ,QAAQ,GAAG"}
|