@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/index-Czc4O526.d.ts
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* ========================================================================
|
|
3
|
-
* @rzl-zone/utils-js
|
|
4
|
-
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.12.1-beta.0`
|
|
6
|
-
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
-
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
-
* ========================================================================
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { Extends, FixNeverArrayRecursive, IfNonEmptyArray, NullToUndefined } from "@rzl-zone/ts-types-plus";
|
|
12
|
-
/** ---------------------------------
|
|
13
|
-
* * ***Utility: `getRandomItem`.***
|
|
14
|
-
* ---------------------------------
|
|
15
|
-
* **Function to get a random element from a given array.**
|
|
16
|
-
* @template T - The type of the input array.
|
|
17
|
-
* @param {*} array - The input array, can be `null`, `undefined`, or an empty array.
|
|
18
|
-
* @returns
|
|
19
|
-
* - If `array` is a non-empty tuple, returns one of its elements.
|
|
20
|
-
* - If `array` is empty, `null`, or `undefined`, returns `undefined`.
|
|
21
|
-
* @example
|
|
22
|
-
* getRandomItem([]);
|
|
23
|
-
* // ➔ undefined
|
|
24
|
-
* getRandomItem(null);
|
|
25
|
-
* // ➔ undefined
|
|
26
|
-
* getRandomItem(undefined);
|
|
27
|
-
* // ➔ undefined
|
|
28
|
-
* getRandomItem([1, 2, 3, 4]);
|
|
29
|
-
* // ➔ number
|
|
30
|
-
* getRandomItem(["apple", "banana", "cherry"]);
|
|
31
|
-
* // ➔ string
|
|
32
|
-
* getRandomItem(["apple", 123, true]);
|
|
33
|
-
* // ➔ string | number | boolean
|
|
34
|
-
* getRandomItem(["apple", 123, true, null]);
|
|
35
|
-
* // ➔ string | number | boolean | undefined
|
|
36
|
-
* getRandomItem(["apple", 123, true, undefined]);
|
|
37
|
-
* // ➔ string | number | boolean | undefined
|
|
38
|
-
*
|
|
39
|
-
* // Tuple example:
|
|
40
|
-
* const tuple = [1, "two", true] as const;
|
|
41
|
-
* getRandomItem(tuple); // 1 | "two" | true
|
|
42
|
-
*/
|
|
43
|
-
declare function getRandomItem(array: undefined): undefined;
|
|
44
|
-
declare function getRandomItem(array: []): undefined;
|
|
45
|
-
declare function getRandomItem<T extends readonly unknown[]>(array: T): T extends never[][] ? undefined : number extends T["length"] ? NullToUndefined<FixNeverArrayRecursive<T[number]>> : IfNonEmptyArray<T, NullToUndefined<FixNeverArrayRecursive<T[number]>>, undefined>;
|
|
46
|
-
declare function getRandomItem<T extends readonly unknown[] | undefined | null>(array: T): T extends readonly unknown[] ? NullToUndefined<FixNeverArrayRecursive<T[number]>> | undefined : undefined;
|
|
47
|
-
declare function getRandomItem<T>(array: T): unknown extends T ? unknown : Extends<any[] | readonly any[], T> extends true ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined : Extends<any[], T> extends true ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined : Extends<readonly any[], T> extends true ? Extract<T, unknown[] | readonly unknown[]>[number] | undefined : undefined;
|
|
48
|
-
/** -----------------------------------------------------------------------
|
|
49
|
-
* * ***Utility: `randomInt`.***
|
|
50
|
-
* ------------------------------------------------------------------------
|
|
51
|
-
* **Generates a random integer within a specified range (inclusive).**
|
|
52
|
-
* - **Generates a random integer between `min` and `max` (inclusive), with safety constraints:**
|
|
53
|
-
* - `min` will be forced to be at least `1`.
|
|
54
|
-
* - `max` will be capped at `Number.MAX_SAFE_INTEGER`.
|
|
55
|
-
* @param {number} min - The minimum value (inclusive), must be an integer.
|
|
56
|
-
* @param {number} max - The maximum value (inclusive), must be an integer.
|
|
57
|
-
* @returns {number} A random integer N where `min ≤ N ≤ max`.
|
|
58
|
-
* @throws **{@link TypeError | `TypeError`}** if:
|
|
59
|
-
* - `min` or `max` is not an integer, or value is `Number.MIN_VALUE`.
|
|
60
|
-
* - `min` is greater than `max`.
|
|
61
|
-
* @example
|
|
62
|
-
* randomInt(1, 10); // ➔ returns 1 up-to 10 (random)
|
|
63
|
-
* randomInt(50, 100); // ➔ returns 50 up-to 100 (random)
|
|
64
|
-
* randomInt(5, 5); // ➔ always returns 5 (exact)
|
|
65
|
-
* randomInt(-5, 3); // ➔ always returns ≥ 1, since min is adjusted (exact)
|
|
66
|
-
* randomInt(1, Number.MAX_SAFE_INTEGER + 10000);
|
|
67
|
-
* // ➔ still safely capped at MAX_SAFE_INTEGER
|
|
68
|
-
* randomInt(Number.MIN_VALUE, 3);
|
|
69
|
-
* // ➔ Error, min or max cant be as `Number.MIN_VALUE` value.
|
|
70
|
-
*/
|
|
71
|
-
declare const randomInt: (min: number, max: number) => number;
|
|
72
|
-
type OptionsRandomIntByLength = {
|
|
73
|
-
/** * Minimum length of the random number, the `allowed minimal value` `integer` is `1` `and not bigger than value of` `maxLength`, defaultValue: `1`.
|
|
74
|
-
*
|
|
75
|
-
* @default 1
|
|
76
|
-
*/
|
|
77
|
-
minLength?: number;
|
|
78
|
-
/** * Maximum length of the random number, the `allowed maximal value` `integer` is `16`, defaultValue: `16`.
|
|
79
|
-
*
|
|
80
|
-
* @default 16
|
|
81
|
-
*/
|
|
82
|
-
maxLength?: number;
|
|
83
|
-
/** * If true, prevents the result from being zero, defaultValue: `false`.
|
|
84
|
-
*
|
|
85
|
-
* @default false
|
|
86
|
-
*/
|
|
87
|
-
avoidZero?: boolean;
|
|
88
|
-
};
|
|
89
|
-
/** ----------------------------------------------------------------------------
|
|
90
|
-
* * ***Utility: `randomIntByLength`.***
|
|
91
|
-
* -----------------------------------------------------------------------------
|
|
92
|
-
* **Generates a random integer within a specified range of digit lengths.**
|
|
93
|
-
* @description
|
|
94
|
-
* This function allows generating random integers that strictly conform to a specified minimum and
|
|
95
|
-
* maximum digit length, it is useful for scenarios such as generating realistic-looking IDs, codes,
|
|
96
|
-
* or random test data.
|
|
97
|
-
* - **The function ensures:**
|
|
98
|
-
* - `minLength` is at least 1 and not greater than `maxLength`.
|
|
99
|
-
* - `maxLength` is no more than 16 (due to JavaScript's `Number.MAX_SAFE_INTEGER`).
|
|
100
|
-
* - If `avoidZero` is `true`, ensures that `0` is never returned.
|
|
101
|
-
* @param {OptionsRandomIntByLength} [options] - Configuration options.
|
|
102
|
-
* @param {OptionsRandomIntByLength["minLength"]} [options.minLength=1] - Minimum number of digits (must be ≥ `1` and ≤ `maxLength`).
|
|
103
|
-
* @param {OptionsRandomIntByLength["maxLength"]} [options.maxLength=16] - Maximum number of digits (must be ≤ `16`).
|
|
104
|
-
* @param {OptionsRandomIntByLength["avoidZero"]} [options.avoidZero=false] - If true, will ensure the result is never zero.
|
|
105
|
-
* @returns {number} A randomly generated integer within the specified constraints.
|
|
106
|
-
* @throws **{@link TypeError | `TypeError`}** if parameters are invalid, such as:
|
|
107
|
-
* - `minLength` < `1`
|
|
108
|
-
* - `maxLength` > `16`
|
|
109
|
-
* - `minLength` > `maxLength`
|
|
110
|
-
* - non-integer values for `minLength` or `maxLength`
|
|
111
|
-
* @example
|
|
112
|
-
* randomIntByLength({ minLength: 3, maxLength: 5 });
|
|
113
|
-
* // ➔ `4829` (random), `192` (random) or `71492` (random).
|
|
114
|
-
* randomIntByLength({ minLength: 4, maxLength: 4 });
|
|
115
|
-
* // ➔ `5930` (exact 4 digits)
|
|
116
|
-
* randomIntByLength({ avoidZero: true });
|
|
117
|
-
* // ➔ never 0
|
|
118
|
-
*/
|
|
119
|
-
declare const randomIntByLength: (options?: OptionsRandomIntByLength) => number;
|
|
120
|
-
type OptionsRandomStr = {
|
|
121
|
-
/** ***Ensures no whitespace characters in the generated string, defaultValue: `true`.***
|
|
122
|
-
* @default true
|
|
123
|
-
*/
|
|
124
|
-
avoidWhiteSpace?: boolean;
|
|
125
|
-
/** ***Custom characters to replace the default number set if `type` is `"number"`, defaultValue: `undefined`.***
|
|
126
|
-
* @default undefined
|
|
127
|
-
*/
|
|
128
|
-
replaceGenInt?: string;
|
|
129
|
-
/** ***Custom characters to replace the default string set if `type` is `"string"`, defaultValue: `undefined`.***
|
|
130
|
-
* @default undefined
|
|
131
|
-
*/
|
|
132
|
-
replaceGenStr?: string;
|
|
133
|
-
/** ***Additional characters to include in the generated string, defaultValue: `undefined`.***
|
|
134
|
-
* @default undefined
|
|
135
|
-
*/
|
|
136
|
-
addChar?: string;
|
|
137
|
-
/** ***Minimum length of the generated string (1 to 5000), defaultValue: `40`.***
|
|
138
|
-
* @default 40
|
|
139
|
-
*/
|
|
140
|
-
minLength?: number;
|
|
141
|
-
/** ***Maximum length of the generated string (1 to 5000), defaultValue: `40`.***
|
|
142
|
-
* @default 40
|
|
143
|
-
*/
|
|
144
|
-
maxLength?: number;
|
|
145
|
-
/** ***Type of output: `"string"` or `"number"`, defaultValue: `"string"`.***
|
|
146
|
-
* @default "string"
|
|
147
|
-
*/
|
|
148
|
-
type?: "string" | "number";
|
|
149
|
-
};
|
|
150
|
-
/** ---------------------------------------------------------------------------------
|
|
151
|
-
* * ***Utility: `randomStr`.***
|
|
152
|
-
* ---------------------------------------------------------------------------------
|
|
153
|
-
* **Generates a random alphanumeric string or number with a specified length range.**
|
|
154
|
-
* @description
|
|
155
|
-
* This function allows you to generate random strings or numbers with fully
|
|
156
|
-
* customizable options, such as length range, character sets, inclusion of
|
|
157
|
-
* additional characters, and whether to avoid whitespace.
|
|
158
|
-
* @param {OptionsRandomStr} [options] - Configuration options for generating the string.
|
|
159
|
-
* @param {OptionsRandomStr["minLength"]} [options.minLength=40] - Minimum length of the generated string (must be `≥` `1`).
|
|
160
|
-
* @param {OptionsRandomStr["maxLength"]} [options.maxLength=40] - Maximum length of the generated string (must be `≤` `5000`).
|
|
161
|
-
* @param {OptionsRandomStr["type"]} [options.type="string"] - Whether to generate a general alphanumeric string or purely numeric string.
|
|
162
|
-
* @param {OptionsRandomStr["avoidWhiteSpace"]} [options.avoidWhiteSpace=true] - If true, removes all whitespace, tabs, and newlines from the character set before generating.
|
|
163
|
-
* @param {OptionsRandomStr["replaceGenStr"]} [options.replaceGenStr] - A custom character set to use when `type` is `"string"`.
|
|
164
|
-
* @param {OptionsRandomStr["replaceGenInt"]} [options.replaceGenInt] - A custom character set to use when `type` is `"number"`.
|
|
165
|
-
* @param {OptionsRandomStr["addChar"]} [options.addChar] - Additional characters to always include in the character set.
|
|
166
|
-
* @returns {string} The randomly generated string or numeric string of the desired length.
|
|
167
|
-
* @throws **{@link TypeError | `TypeError`}** if provided options are invalid (such as minLength > maxLength, invalid type, or empty character set).
|
|
168
|
-
* @example
|
|
169
|
-
* randomStr();
|
|
170
|
-
* // ➔ Generates a 40-character random alphanumeric string
|
|
171
|
-
* randomStr({ minLength: 10, maxLength: 20 });
|
|
172
|
-
* // ➔ Generates a string between 10 and 20 characters
|
|
173
|
-
* randomStr({ type: "number", minLength: 5, maxLength: 5 });
|
|
174
|
-
* // ➔ "48302"
|
|
175
|
-
* randomStr({ replaceGenStr: "ABC ", avoidWhiteSpace: false });
|
|
176
|
-
* // ➔ String using A, B, C and space
|
|
177
|
-
* randomStr({ addChar: "!@#", minLength: 15, maxLength: 15 });
|
|
178
|
-
* // ➔ Guaranteed to include !@# in the set
|
|
179
|
-
*/
|
|
180
|
-
declare const randomStr: (options?: OptionsRandomStr) => string;
|
|
181
|
-
/**
|
|
182
|
-
* Configuration options for `randomUUID()`.
|
|
183
|
-
*/
|
|
184
|
-
type OptionsRandomUUID = {
|
|
185
|
-
/**
|
|
186
|
-
* Specifies which UUID version to generate.
|
|
187
|
-
*
|
|
188
|
-
* - `"v4"` — Fully random UUID (RFC 4122). No timestamp, no ordering guarantees.
|
|
189
|
-
* - `"v7"` — Time-ordered UUID (RFC 9562). Uses Unix timestamp + randomness.
|
|
190
|
-
*
|
|
191
|
-
* @default "v4"
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* // Random v4 UUID
|
|
195
|
-
* randomUUID({ version: "v4" }); // ➔ "3ec0de5a-b8a9-4ffb-a62a-fcc76851e9c2"
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* // Time-ordered v7 UUID
|
|
199
|
-
* randomUUID({ version: "v7" }); // ➔ "0199f3f6-3c5e-744b-affa-46b2cfd496f8"
|
|
200
|
-
*/
|
|
201
|
-
version?: "v4" | "v7";
|
|
202
|
-
/**
|
|
203
|
-
* Enables monotonic sequencing for UUID v7.
|
|
204
|
-
*
|
|
205
|
-
* - Guarantees that multiple UUIDs generated within the same millisecond
|
|
206
|
-
* are strictly non-decreasing (lexicographically and timestamp-wise).
|
|
207
|
-
* - Only valid when `version === "v7"`. Using with `v4` will throw a `TypeError`.
|
|
208
|
-
* - Useful for database inserts, logs, or any system where order matters.
|
|
209
|
-
*
|
|
210
|
-
* @default false
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* // Monotonic v7 UUIDs
|
|
214
|
-
* const a = randomUUID({ version: "v7", monotonic: true });
|
|
215
|
-
* const b = randomUUID({ version: "v7", monotonic: true });
|
|
216
|
-
* console.log(a < b); // true, guaranteed
|
|
217
|
-
*/
|
|
218
|
-
monotonic?: boolean;
|
|
219
|
-
};
|
|
220
|
-
/** -----------------------------------------------------------------------
|
|
221
|
-
* * ***Utility: `randomUUID`.***
|
|
222
|
-
* ------------------------------------------------------------------------
|
|
223
|
-
* **Generates a UUID string according to the specified version and options.**
|
|
224
|
-
*
|
|
225
|
-
* - **Supported versions**:
|
|
226
|
-
* - **`"v4"` (default)** ➔ Fully random UUID, RFC 4122 compliant.
|
|
227
|
-
* - Uses `crypto.randomUUID()` if available.
|
|
228
|
-
* - Falls back to `crypto.getRandomValues()` or `Math.random()`
|
|
229
|
-
* if needed.
|
|
230
|
-
* - **`"v7"`** ➔ Time-ordered UUID, RFC 9562 compliant.
|
|
231
|
-
* - Timestamp (Unix ms, 48 bits) + 80 bits randomness.
|
|
232
|
-
* - Good for database indexing / sorting.
|
|
233
|
-
* - **`"v7"` + `monotonic: true`** ➔ Ensures strictly non-decreasing UUIDs
|
|
234
|
-
* for multiple calls in the same millisecond (per-process).
|
|
235
|
-
*
|
|
236
|
-
* - **Behavior / Safety Notes**:
|
|
237
|
-
* - **v4**: Fully random; probability of duplicates is astronomically low.
|
|
238
|
-
* - **v7**: Time-ordered; collisions extremely unlikely unless same ms + random repeat.
|
|
239
|
-
* - **Monotonic v7**: Guaranteed ordering per-process if multiple UUIDs are generated
|
|
240
|
-
* in the same millisecond.
|
|
241
|
-
* - **All versions**: Fallback safely if `crypto` APIs are unavailable.
|
|
242
|
-
*
|
|
243
|
-
* @param {object} [options] - Optional settings object.
|
|
244
|
-
* @param {"v4" | "v7"} [options.version="v4"] - UUID version to generate.
|
|
245
|
-
* @param {boolean} [options.monotonic=false] - For v7 only: generate monotonic UUIDs
|
|
246
|
-
* to maintain strict lexicographic order
|
|
247
|
-
* when generating multiple UUIDs within the same ms.
|
|
248
|
-
*
|
|
249
|
-
* @returns {string} A 36-character UUID string compliant with the selected version.
|
|
250
|
-
*
|
|
251
|
-
* @throws **{@link TypeError | `TypeError`}** if:
|
|
252
|
-
* - `options` is not a plain object.
|
|
253
|
-
* - `options.version` is provided but not a string.
|
|
254
|
-
* - `options.monotonic` is provided but not a boolean.
|
|
255
|
-
* - `monotonic: true` is used with `version` other than `"v7"`.
|
|
256
|
-
* @throws **{@link RangeError | `RangeError`}** if `options.version` is provided but not `"v4"` or `"v7"`.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* // Default (v4)
|
|
260
|
-
* const id = randomUUID();
|
|
261
|
-
* // ➔ "3b12f1df-5232-4804-897e-917bf397618a"
|
|
262
|
-
*
|
|
263
|
-
* @example
|
|
264
|
-
* // Explicit v4
|
|
265
|
-
* const id4 = randomUUID({ version: "v4" });
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* // Time-ordered v7
|
|
269
|
-
* const id7 = randomUUID({ version: "v7" });
|
|
270
|
-
* // ➔ "018f48d2-84c1-7ccd-b5a3-2f9463b3a889"
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* // Monotonic v7
|
|
274
|
-
* const a = randomUUID({ version: "v7", monotonic: true });
|
|
275
|
-
* const b = randomUUID({ version: "v7", monotonic: true });
|
|
276
|
-
* // a < b lexicographically (guaranteed)
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* // Throws TypeError
|
|
280
|
-
* randomUUID("v4" as any); // options must be object
|
|
281
|
-
* randomUUID({ version: 123 as any }); // version must be string
|
|
282
|
-
* randomUUID({ version: "v4", monotonic: true } as any); // monotonic only for v7
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* // Throws RangeError
|
|
286
|
-
* randomUUID({ version: "v1" as any }); // unsupported version
|
|
287
|
-
*/
|
|
288
|
-
declare function randomUUID(options?: OptionsRandomUUID): string;
|
|
289
|
-
/**
|
|
290
|
-
* --------------------------------------------------
|
|
291
|
-
* * ***Utility: `noop`.***
|
|
292
|
-
* --------------------------------------------------
|
|
293
|
-
* **A no-operation function that performs no action.**
|
|
294
|
-
*
|
|
295
|
-
* @description
|
|
296
|
-
* Commonly used as a **placeholder**, **default callback**, or **stub function**.
|
|
297
|
-
*
|
|
298
|
-
* - **Behavior**:
|
|
299
|
-
* - Does not return any meaningful value (`void`).
|
|
300
|
-
* - Safely callable in any context without side effects.
|
|
301
|
-
*
|
|
302
|
-
* @remarks
|
|
303
|
-
* Although this function returns `void`, it implicitly results in `undefined`,
|
|
304
|
-
* but the return value should never be relied upon.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* **1. Basic usage** — does nothing and returns undefined implicitly:
|
|
308
|
-
* ```
|
|
309
|
-
* import { noop } from "@rzl-zone/utils-js/generators";
|
|
310
|
-
*
|
|
311
|
-
* noop(); // ➔ no effect (void)
|
|
312
|
-
* ```
|
|
313
|
-
* @example
|
|
314
|
-
* **2. Using with type-checking helpers:**
|
|
315
|
-
* ```ts
|
|
316
|
-
* import { noop } from "@rzl-zone/utils-js/generators";
|
|
317
|
-
* import { isFunction, isUndefined } from "@rzl-zone/utils-js/predicates";
|
|
318
|
-
*
|
|
319
|
-
* isFunction(noop); // ➔ true — `noop` is a function
|
|
320
|
-
* isUndefined(noop()); // ➔ true — calling `noop()` returns `undefined`
|
|
321
|
-
* isFunction(noop()); // ➔ false — the return value is `undefined`, not a function
|
|
322
|
-
* ```
|
|
323
|
-
* @example
|
|
324
|
-
* **3. As a default callback:**
|
|
325
|
-
* ```ts
|
|
326
|
-
* import { noop } from "@rzl-zone/utils-js/generators";
|
|
327
|
-
*
|
|
328
|
-
* const callback = noop;
|
|
329
|
-
* callback(); // ➔ no effect (void)
|
|
330
|
-
* ```
|
|
331
|
-
*/
|
|
332
|
-
declare const noop: () => void;
|
|
333
|
-
export { randomInt as a, randomIntByLength as i, randomUUID as n, getRandomItem as o, randomStr as r, noop as t };
|