@rzl-zone/utils-js 3.2.5-beta.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -20
- package/dist/NumberRangeUnion-B6bhM2s7.d.ts +33 -0
- package/dist/{any-BmdI8UbK.d.ts → any-v4TsK9ES.d.ts} +25 -26
- package/dist/{arrays-normalize-recursive-CnjYJ9xg.d.ts → arrays-normalize-recursive-BqmVuFlD.d.ts} +20 -20
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +96 -70
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-2CQX5CBG.js +1 -0
- package/dist/chunk-2IOOEY45.cjs +1 -0
- package/dist/chunk-3IBQ5MOM.js +1 -0
- package/dist/{chunk-OGPPP2S3.js → chunk-3VA554KW.js} +1 -1
- package/dist/{chunk-FV7SEBKD.cjs → chunk-5757UBXJ.cjs} +1 -1
- package/dist/{chunk-MTUBDVJ2.js → chunk-5IGC6PBH.js} +1 -1
- package/dist/{chunk-O7UT5AN3.cjs → chunk-5KJFVIQT.cjs} +1 -1
- package/dist/chunk-6JFCSH7J.js +1 -0
- package/dist/{chunk-VHAPTHEA.cjs → chunk-6JFZL7YE.cjs} +1 -1
- package/dist/chunk-7ODAAXX5.cjs +1 -0
- package/dist/{chunk-6C3ATUGM.cjs → chunk-CAH33WOQ.cjs} +1 -1
- package/dist/{chunk-ECRNH4FW.js → chunk-CKTLUNWX.js} +1 -1
- package/dist/chunk-CMW2TBOQ.js +1 -0
- package/dist/chunk-D3ENH7H6.cjs +1 -0
- package/dist/{chunk-3YCFMGRB.js → chunk-DEZZUYE2.js} +1 -1
- package/dist/chunk-DWF2R5GD.cjs +1 -0
- package/dist/chunk-E55EQK2U.cjs +1 -0
- package/dist/chunk-E74U6CYP.cjs +1 -0
- package/dist/{chunk-XC3QHAK2.cjs → chunk-EL6A35UR.cjs} +1 -1
- package/dist/chunk-F6IPNNSJ.cjs +1 -0
- package/dist/chunk-FJZGG54N.cjs +1 -0
- package/dist/chunk-FWCKOJZM.js +1 -0
- package/dist/{chunk-IMCLPT5V.cjs → chunk-FWHNWL2P.cjs} +1 -1
- package/dist/chunk-GGEADHZO.js +1 -0
- package/dist/{chunk-IRGE5W7L.js → chunk-GQR4R5WY.js} +1 -1
- package/dist/chunk-H66AC7GK.cjs +1 -0
- package/dist/{chunk-M47QIBXI.cjs → chunk-HQWOFR56.cjs} +1 -1
- package/dist/{chunk-VCFXNV3Q.cjs → chunk-HYRQMTRH.cjs} +1 -1
- package/dist/{chunk-EUANTHVN.js → chunk-IRFL4MAX.js} +1 -1
- package/dist/{chunk-GGWPB23G.cjs → chunk-IVL7CKVH.cjs} +1 -1
- package/dist/chunk-IZPBKKPO.js +1 -0
- package/dist/chunk-JBQMXC5I.cjs +1 -0
- package/dist/chunk-JEQEF5WD.js +1 -0
- package/dist/chunk-JMJQCN74.js +1 -0
- package/dist/chunk-JYQTCICM.js +1 -0
- package/dist/chunk-KVAL5PAG.cjs +1 -0
- package/dist/chunk-LS6U7FAY.cjs +1 -0
- package/dist/chunk-NBZWMBO6.js +1 -0
- package/dist/chunk-NRF6LWBC.cjs +1 -0
- package/dist/chunk-OI5XKNZO.js +1 -0
- package/dist/chunk-OYTYSY7G.js +1 -0
- package/dist/chunk-PET42Z7W.js +1 -0
- package/dist/chunk-PZQ6I4JJ.cjs +1 -0
- package/dist/chunk-QBKAEVYG.js +1 -0
- package/dist/{chunk-YV3K2EKJ.js → chunk-RIPKY4RU.js} +1 -1
- package/dist/chunk-RZW35UN5.cjs +1 -0
- package/dist/chunk-SBFNXGTJ.js +1 -0
- package/dist/{chunk-T4CIAKEK.js → chunk-SBKGWRS5.js} +1 -1
- package/dist/{chunk-5Z2G23WP.js → chunk-SIM77PU4.js} +1 -1
- package/dist/chunk-T2T7K3KR.js +1 -0
- package/dist/chunk-T7PU2V7X.cjs +1 -0
- package/dist/chunk-V45XJKHW.cjs +1 -0
- package/dist/chunk-W2WNBUDE.js +1 -0
- package/dist/chunk-XABCB3Y7.cjs +1 -0
- package/dist/chunk-XEDXFSGI.js +1 -0
- package/dist/chunk-YKPSRP5G.js +1 -0
- package/dist/chunk-YLA3DURS.cjs +1 -0
- package/dist/chunk-ZETAZZLD.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +515 -321
- package/dist/conversions/index.js +1 -1
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +25 -20
- package/dist/events/index.js +1 -1
- package/dist/{extends-Bk_SBGdT.d.ts → extends-DtdRjDyU.d.ts} +63 -87
- package/dist/{formatting → formatters}/index.cjs +1 -1
- package/dist/formatters/index.d.ts +2106 -0
- package/dist/formatters/index.js +1 -0
- package/dist/generators/index.cjs +1 -0
- package/dist/{generator → generators}/index.d.ts +57 -59
- package/dist/generators/index.js +1 -0
- package/dist/{if-CvT4R7Kh.d.ts → if-ChM35c_q.d.ts} +6 -5
- package/dist/index.d.ts +14 -0
- package/dist/{is-array--YjXV-Wx.d.ts → is-array-BJeHxPM3.d.ts} +287 -542
- package/dist/{isPlainObject-BVhBAPHX.d.ts → isPlainObject-DGJkcFYw.d.ts} +6 -6
- package/dist/{never-BfayMBF9.d.ts → never-D89PbPh5.d.ts} +10 -19
- package/dist/next/index.cjs +1 -1
- package/dist/next/index.d.ts +15 -12
- package/dist/next/index.js +1 -1
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +1 -1
- package/dist/next/server/index.js +1 -1
- package/dist/{nils-DMz3kU7M.d.ts → nils-CO8zLHSB.d.ts} +39 -65
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +4 -4
- package/dist/operations/index.js +1 -1
- package/dist/or-C6qzKt2I.d.ts +82 -0
- package/dist/override-CL2olHE5.d.ts +59 -0
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.js +1 -1
- package/dist/pick-BSMX6Xe2.d.ts +15 -0
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +425 -106
- package/dist/predicates/index.js +1 -1
- package/dist/prettify-3o8_Kw6b.d.ts +564 -0
- package/dist/promises/index.cjs +1 -0
- package/dist/promises/index.d.ts +107 -0
- package/dist/promises/index.js +1 -0
- package/dist/promises-LU7K00H0.d.ts +72 -0
- package/dist/rzl-utils.global.js +1 -1
- package/dist/{string-XA-til3C.d.ts → string-B1jlOnws.d.ts} +82 -121
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +209 -210
- package/dist/strings/index.js +1 -1
- package/dist/tailwind/index.cjs +1 -1
- package/dist/tailwind/index.d.ts +23 -17
- package/dist/tailwind/index.js +1 -1
- package/dist/types/index.d.ts +899 -1181
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +113 -108
- package/dist/urls/index.js +1 -1
- package/package.json +33 -40
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +0 -26
- package/dist/chunk-2HSNUPEO.cjs +0 -1
- package/dist/chunk-4Z75R3IT.cjs +0 -1
- package/dist/chunk-AJ25PWXX.cjs +0 -1
- package/dist/chunk-BHIBDDQF.js +0 -1
- package/dist/chunk-CE4JI2YB.js +0 -1
- package/dist/chunk-CMJ6UYWW.cjs +0 -1
- package/dist/chunk-D3VSHABU.cjs +0 -1
- package/dist/chunk-DG2GWBTS.cjs +0 -1
- package/dist/chunk-EKS4IZJR.cjs +0 -1
- package/dist/chunk-EOZKYR5S.cjs +0 -1
- package/dist/chunk-EW3I4O7X.js +0 -1
- package/dist/chunk-F3E77L46.js +0 -1
- package/dist/chunk-G5LXIEFO.js +0 -0
- package/dist/chunk-GVWGQNLF.js +0 -1
- package/dist/chunk-H3FXL4DU.cjs +0 -1
- package/dist/chunk-HHPDLSX2.cjs +0 -1
- package/dist/chunk-JARPXKBM.cjs +0 -1
- package/dist/chunk-JFJUPYDT.cjs +0 -1
- package/dist/chunk-JLP56WSM.js +0 -1
- package/dist/chunk-K3MV4AIN.cjs +0 -1
- package/dist/chunk-KOVO72OM.js +0 -1
- package/dist/chunk-LJ4M3VGE.js +0 -1
- package/dist/chunk-LJVGJLP4.js +0 -1
- package/dist/chunk-MISCBZJC.js +0 -1
- package/dist/chunk-MMSYCIJ2.cjs +0 -1
- package/dist/chunk-OLPKAX7F.cjs +0 -1
- package/dist/chunk-ORZFHBEY.js +0 -1
- package/dist/chunk-OWV2P376.js +0 -1
- package/dist/chunk-RV2WK5E6.js +0 -1
- package/dist/chunk-SBF43G3B.cjs +0 -1
- package/dist/chunk-X74TUJSE.cjs +0 -1
- package/dist/chunk-XLDAIZRK.js +0 -1
- package/dist/chunk-XZJ7C4N6.js +0 -1
- package/dist/chunk-ZHV5ZYVN.cjs +0 -1
- package/dist/chunk-ZL7J6GTP.js +0 -1
- package/dist/chunk-ZTCLKKMB.js +0 -1
- package/dist/env/index.cjs +0 -1
- package/dist/env/index.d.ts +0 -16
- package/dist/env/index.js +0 -1
- package/dist/formatting/index.d.ts +0 -950
- package/dist/formatting/index.js +0 -1
- package/dist/generator/index.cjs +0 -1
- package/dist/generator/index.js +0 -1
- package/dist/omit-VvmIsZmX.d.ts +0 -28
- package/dist/prettify-C4xLcYOP.d.ts +0 -353
- package/dist/promise/index.cjs +0 -1
- package/dist/promise/index.d.ts +0 -31
- package/dist/promise/index.js +0 -1
- package/dist/type-data-DDs-u2kq.d.ts +0 -261
- /package/dist/{chunk-5C2SMIGX.cjs → chunk-BAV5T2E3.cjs} +0 -0
- /package/dist/{chunk-MC3LXMCQ.js → chunk-L5RDAVVH.js} +0 -0
- /package/dist/{chunk-J2RGTPGK.cjs → chunk-VJDDGRIK.cjs} +0 -0
- /package/dist/{chunk-FIAAX3UE.js → chunk-YWHHVDT4.js} +0 -0
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
🚀 <strong>Rzl Utility
|
|
6
|
+
🚀 <strong>Rzl Utility JS</strong> 🚀<br/>
|
|
7
7
|
A lightweight, modern TypeScript utility library for Node.js & browser (via bundlers like Webpack/Vite).<br/>
|
|
8
|
-
Provides reusable helpers to simplify your JavaScript
|
|
8
|
+
Provides reusable helpers to simplify your JavaScript or TypeScript projects.<br/>
|
|
9
9
|
<strong>Built with ❤️ by <a href="https://github.com/rzl-app" target="_blank" rel="nofollow noreferrer noopener">@rzl-app</a>.</strong>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
@@ -19,7 +19,7 @@ Provides reusable helpers to simplify your JavaScript / TypeScript projects.<br/
|
|
|
19
19
|
<img src="https://img.shields.io/npm/dt/@rzl-zone/utils-js?style=flat-rounded" alt="Downloads">
|
|
20
20
|
</a>
|
|
21
21
|
<a href="https://nodejs.org/en/" target="_blank" rel="nofollow noreferrer noopener">
|
|
22
|
-
<img src="https://img.shields.io/badge/node-≥16.0.0
|
|
22
|
+
<img src="https://img.shields.io/badge/node-≥16.0.0-blue.svg?logo=node.js&style=flat-rounded" alt="Node.js">
|
|
23
23
|
</a>
|
|
24
24
|
<a href="https://github.com/rzl-zone/utils-js/blob/main/CONTRIBUTING.md" target="_blank" rel="nofollow noreferrer noopener">
|
|
25
25
|
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome">
|
|
@@ -50,7 +50,7 @@ Provides reusable helpers to simplify your JavaScript / TypeScript projects.<br/
|
|
|
50
50
|
- ❤️ [Sponsor](#sponsor-this-package)
|
|
51
51
|
- 📜 [Changelog](#changelog)
|
|
52
52
|
- 🤝 [Contributing](#contributing)
|
|
53
|
-
-
|
|
53
|
+
- 🔒 [Security](#security)
|
|
54
54
|
- 🙌 [Credits](#credits)
|
|
55
55
|
- 📄 [License](#license)
|
|
56
56
|
|
|
@@ -58,7 +58,7 @@ Provides reusable helpers to simplify your JavaScript / TypeScript projects.<br/
|
|
|
58
58
|
|
|
59
59
|
<h2 id="requirements">💻 Requirements</h2>
|
|
60
60
|
|
|
61
|
-
- **Node.js `≥16.0.0
|
|
61
|
+
- **Node.js `≥16.0.0`**
|
|
62
62
|
This package leverages modern JavaScript & TypeScript features that require Node.js version 16.0.0 if not using Next.js, and for Next.js it must follow the official minimum Node.js version requirement depending on the version you use.
|
|
63
63
|
- 🔗 See official Next.js documentation:
|
|
64
64
|
<a href="https://nextjs.org/docs/getting-started/installation#system-requirements" target="_blank" rel="nofollow noreferrer noopener">NextJS Installation Requirements</a>
|
|
@@ -99,7 +99,7 @@ Provides reusable helpers to simplify your JavaScript / TypeScript projects.<br/
|
|
|
99
99
|
- 📦 Works in **Node.js** & modern browsers
|
|
100
100
|
- ❤️ Simple API, easy to extend
|
|
101
101
|
- 🧬 **Next.js support**: helpers for dynamic routes, building URLs, reading env, extracting client IP
|
|
102
|
-
- 🛠 Additional TypeScript types: `OmitStrict`, `
|
|
102
|
+
- 🛠 Additional TypeScript types: `OmitStrict`, `PartialOnly`, etc.
|
|
103
103
|
|
|
104
104
|
---
|
|
105
105
|
|
|
@@ -132,25 +132,23 @@ This package also provides utilities specially built for Next.js environments, n
|
|
|
132
132
|
|
|
133
133
|
```ts
|
|
134
134
|
import { | } from "@rzl-zone/utils-js/assertions";
|
|
135
|
-
import { | } from "@rzl-zone/utils-js/conversions";
|
|
136
|
-
import { | } from "@rzl-zone/utils-js/env";
|
|
135
|
+
import { | } from "@rzl-zone/utils-js/conversions";
|
|
137
136
|
import { | } from "@rzl-zone/utils-js/events";
|
|
138
|
-
import { | } from "@rzl-zone/utils-js/
|
|
139
|
-
import { | } from "@rzl-zone/utils-js/
|
|
140
|
-
import { | } from "@rzl-zone/utils-js/generator";
|
|
137
|
+
import { | } from "@rzl-zone/utils-js/formatters";
|
|
138
|
+
import { | } from "@rzl-zone/utils-js/generators";
|
|
141
139
|
import { | } from "@rzl-zone/utils-js/next";
|
|
142
140
|
import { | } from "@rzl-zone/utils-js/next/server";
|
|
143
141
|
import { | } from "@rzl-zone/utils-js/operations";
|
|
144
142
|
import { | } from "@rzl-zone/utils-js/parsers";
|
|
145
143
|
import { | } from "@rzl-zone/utils-js/predicates";
|
|
146
|
-
import { | } from "@rzl-zone/utils-js/
|
|
144
|
+
import { | } from "@rzl-zone/utils-js/promises";
|
|
147
145
|
import { | } from "@rzl-zone/utils-js/strings";
|
|
148
|
-
import { | } from "@rzl-zone/utils-js/
|
|
146
|
+
import { | } from "@rzl-zone/utils-js/tailwind";
|
|
149
147
|
import { | } from "@rzl-zone/utils-js/urls";
|
|
150
148
|
|
|
151
149
|
import type { | } from "@rzl-zone/utils-js/types";
|
|
152
150
|
```
|
|
153
|
-
#### Just place your cursor right inside `{ }` or
|
|
151
|
+
#### Just place your cursor right inside `{ }` or after import from `"@rzl-zone/utils-js/{{ | }}"` like the pipe ("|") above then ctrl + space, there are many functions or types and then hover to each function is complete with how to use it because I have added tsDoc.
|
|
154
152
|
|
|
155
153
|
<!-- - <h4 id="detailed-features--assertions">
|
|
156
154
|
Assertions -
|
|
@@ -182,10 +180,10 @@ This package also provides utilities specially built for Next.js environments, n
|
|
|
182
180
|
#### Example Function Import:
|
|
183
181
|
|
|
184
182
|
```ts
|
|
185
|
-
import { isServer } from "@rzl-zone/utils-js/
|
|
183
|
+
import { isServer } from "@rzl-zone/utils-js/predicates";
|
|
186
184
|
|
|
187
185
|
console.log(isServer());
|
|
188
|
-
// true if running on
|
|
186
|
+
// ➔ `true` if running on server-side, `false` if in browser.
|
|
189
187
|
```
|
|
190
188
|
|
|
191
189
|
#### Example Types Helper Import:
|
|
@@ -193,7 +191,7 @@ console.log(isServer());
|
|
|
193
191
|
```ts
|
|
194
192
|
import type { OmitStrict } from "@rzl-zone/utils-js/types";
|
|
195
193
|
|
|
196
|
-
type MyType = OmitStrict<OtherType, "
|
|
194
|
+
type MyType = OmitStrict<OtherType, "omittingProps">;
|
|
197
195
|
// Fully strict TS omit that requires all keys to exist in target
|
|
198
196
|
```
|
|
199
197
|
|
|
@@ -218,9 +216,7 @@ See [CONTRIBUTING](CONTRIBUTING.md).
|
|
|
218
216
|
|
|
219
217
|
---
|
|
220
218
|
|
|
221
|
-
<h2 id="security"
|
|
222
|
-
<path d="M466.5 83.7L266.5 15.7c-6.4-2.1-13.5-2.1-19.9 0l-200 68c-9.4 3.2-15.7 12-15.7 22.1V256c0 120.9 83.7 230.2 200 256 116.3-25.8 200-135.1 200-256V105.8c0-10.1-6.3-18.9-15.7-22.1z"/>
|
|
223
|
-
</svg> Security</h2>
|
|
219
|
+
<h2 id="security">🔒 Security</h2>
|
|
224
220
|
|
|
225
221
|
Please report issues to [rizalvindwiky1998@gmail.com](mailto:rizalvindwiky1998@gmail.com).
|
|
226
222
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** --------------------------------------------------
|
|
2
|
+
* * ***Internal Utility Type for: {@link NumberRangeUnion | `NumberRangeUnion`}.***
|
|
3
|
+
* --------------------------------------------------
|
|
4
|
+
* @template N - Starting/Ending number of the range (inclusive).
|
|
5
|
+
* @template Acc - Internal accumulator for recursion (do not set manually).
|
|
6
|
+
*/
|
|
7
|
+
type Enumerate<N extends number,Acc extends number[]=[]>=Acc["length"] extends N?Acc[number]:Enumerate<N,[...Acc,Acc["length"]]>;
|
|
8
|
+
/** --------------------------------------------------
|
|
9
|
+
* * ***Utility Type: `NumberRangeUnion`.***
|
|
10
|
+
* --------------------------------------------------
|
|
11
|
+
* **Generate a union type of numbers from `From` to `To` using enumeration.**
|
|
12
|
+
* @description
|
|
13
|
+
* Produces a **numeric union type** from `From` to `To` (inclusive),
|
|
14
|
+
* using a simpler approach based on `Enumerate<N>` helper type.
|
|
15
|
+
* - ✅ Straightforward & easy to reason about.
|
|
16
|
+
* - ⚠️ Still limited by TypeScript recursion depth (safe up to `999`).
|
|
17
|
+
* - ⚙️ Best used for **smaller ranges** (`≤ 100`) or when readability matters.
|
|
18
|
+
* - ℹ️ For **larger ranges** (`≥ 101`) use {@link NumberRangeLimit | `NumberRangeLimit`} instead.
|
|
19
|
+
* @template From - Starting number of the range (inclusive).
|
|
20
|
+
* @template To - Ending number of the range (inclusive).
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* type RangeA = NumberRangeUnion<3, 6>;
|
|
24
|
+
* // ➔ 3 | 4 | 5 | 6
|
|
25
|
+
* type RangeB = NumberRangeUnion<0, 2>;
|
|
26
|
+
* // ➔ 0 | 1 | 2
|
|
27
|
+
* type RangeC = NumberRangeUnion<8, 8>;
|
|
28
|
+
* // ➔ 8
|
|
29
|
+
* type RangeD = NumberRangeUnion<20, 10>;
|
|
30
|
+
* // ➔ 10
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
type NumberRangeUnion<From extends number,To extends number>=From extends To?From:Exclude<Enumerate<To>,Enumerate<From>>extends never?To:Exclude<Enumerate<To>,Enumerate<From>>|To;export type{NumberRangeUnion as N};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{I as If}from'./if-
|
|
1
|
+
import{I as If}from'./if-ChM35c_q.js';
|
|
2
2
|
/** -------------------------------------------------------
|
|
3
|
-
* * ***IsAny
|
|
3
|
+
* * ***Utility Type: `IsAny`.***
|
|
4
4
|
* -------------------------------------------------------
|
|
5
|
-
* A type-level utility that checks whether a type is ***`any
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* **A type-level utility that checks whether a type is ***`any`***.**
|
|
6
|
+
* - **Behavior:**
|
|
7
|
+
* - Returns `true` if `T` is `any`.
|
|
8
|
+
* - Returns `false` for otherwise.
|
|
9
9
|
* @template T - The type to evaluate.
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -17,18 +17,16 @@ import{I as If}from'./if-CvT4R7Kh.js';
|
|
|
17
17
|
*/
|
|
18
18
|
type IsAny<T>=0 extends 1 & T?true:false;
|
|
19
19
|
/** -------------------------------------------------------
|
|
20
|
-
* * ***IfAny
|
|
20
|
+
* * ***Utility Type: `IfAny`.***
|
|
21
21
|
* -------------------------------------------------------
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* **A type-level conditional utility that returns one type if ***`T` is `any`***,
|
|
23
|
+
* and another type otherwise.**
|
|
24
|
+
* - **Behavior:**
|
|
25
|
+
* - Defaults to `true` when `T` is `any`.
|
|
26
|
+
* - Defaults to `false` for otherwise.
|
|
28
27
|
* @template T - The type to check.
|
|
29
|
-
* @template IfTrue - The type to return if `T` is `any
|
|
30
|
-
* @template IfFalse - The type to return if `T` is not `any
|
|
31
|
-
*
|
|
28
|
+
* @template IfTrue - The type to return if `T` is `any`, *(default: `true`)*.
|
|
29
|
+
* @template IfFalse - The type to return if `T` is not `any`, *(default: `false`)*.
|
|
32
30
|
* @example
|
|
33
31
|
* ```ts
|
|
34
32
|
* type A = IfAny<any, string, number>;
|
|
@@ -38,7 +36,9 @@ type IsAny<T>=0 extends 1 & T?true:false;
|
|
|
38
36
|
* ```
|
|
39
37
|
*/
|
|
40
38
|
type IfAny<T,IfTrue=true,IfFalse=false>=If<IsAny<T>,IfTrue,IfFalse>;
|
|
41
|
-
/** Configuration options for a type-level utility
|
|
39
|
+
/** * ***Configuration options for a type-level utility for
|
|
40
|
+
* {@link AnifyProperties | `AnifyProperties`}.***
|
|
41
|
+
*/
|
|
42
42
|
type AnifyPropertiesOptions={
|
|
43
43
|
/** If `makeOptional: true`, all properties become optional, otherwise, all properties are required and typed as `any`, defaultValue: `false`.
|
|
44
44
|
*
|
|
@@ -46,20 +46,19 @@ type AnifyPropertiesOptions={
|
|
|
46
46
|
*/
|
|
47
47
|
makeOptional:boolean;};
|
|
48
48
|
/** -------------------------------------------------------
|
|
49
|
-
* * ***AnifyProperties
|
|
49
|
+
* * ***Utility Type: `AnifyProperties`.***
|
|
50
50
|
* -------------------------------------------------------
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* -
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @template T
|
|
57
|
-
* @template Options
|
|
51
|
+
* **A type-level utility that transforms all properties of an object
|
|
52
|
+
* into ***`any`***.**
|
|
53
|
+
* - **Behavior:**
|
|
54
|
+
* - If `makeOptional: true`, all properties become optional.
|
|
55
|
+
* - Otherwise, all properties are required and typed as `any`.
|
|
56
|
+
* @template T The object type to transform.
|
|
57
|
+
* @template Options Configuration options, defaults to `{ makeOptional: false }`.
|
|
58
58
|
* @example
|
|
59
59
|
* ```ts
|
|
60
60
|
* type A = AnifyProperties<{a: string; b: number}>;
|
|
61
61
|
* // ➔ { a: any; b: any }
|
|
62
|
-
*
|
|
63
62
|
* type B = AnifyProperties<{a: string; b: number}, { makeOptional: true }>;
|
|
64
63
|
* // ➔ { a?: any; b?: any }
|
|
65
64
|
* ```
|
package/dist/{arrays-normalize-recursive-CnjYJ9xg.d.ts → arrays-normalize-recursive-BqmVuFlD.d.ts}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** -------------------------------------------------------
|
|
2
|
-
* * ***FixNeverArrayRecursive
|
|
2
|
+
* * ***Utility Type: `FixNeverArrayRecursive`.***
|
|
3
3
|
* -------------------------------------------------------
|
|
4
|
-
* A type-level utility that **recursively transforms arrays of type `never[]` into empty arrays
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* **A type-level utility that **recursively transforms arrays of type `never[]` into empty arrays**.**
|
|
5
|
+
* - **Behavior:**
|
|
6
|
+
* - Preserves `readonly` modifiers.
|
|
7
|
+
* - Applies recursively for nested arrays.
|
|
8
|
+
* - Leaves other types unchanged.
|
|
9
9
|
* @template T - The input type to recursively fix.
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
*/
|
|
24
24
|
type FixNeverArrayRecursive<T>=T extends readonly never[]?T extends never[]?[]:readonly []:T extends(infer U)[]?FixNeverArrayRecursive<U>[]:T extends readonly(infer U)[]?readonly FixNeverArrayRecursive<U>[]:T;
|
|
25
25
|
/** -------------------------------------------------------
|
|
26
|
-
* * ***NormalizeEmptyArraysRecursive
|
|
26
|
+
* * ***Utility Type: `NormalizeEmptyArraysRecursive`.***
|
|
27
27
|
* -------------------------------------------------------
|
|
28
|
-
* A type-level utility that **recursively normalizes empty array types** by converting arrays whose element type is `never`, `null`, or `undefined` into empty tuple types (`[]`)
|
|
29
|
-
* -
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
28
|
+
* **A type-level utility that **recursively normalizes empty array types** by converting arrays whose element type is `never`, `null`, or `undefined` into empty tuple types (`[]`).**
|
|
29
|
+
* - **Behavior:**
|
|
30
|
+
* - Preserves `readonly` modifiers.
|
|
31
|
+
* - Recurses into nested arrays.
|
|
32
|
+
* - Leaves other array types unchanged.
|
|
33
33
|
* @template T - The input type to normalize.
|
|
34
34
|
* @example
|
|
35
35
|
* ```ts
|
|
@@ -47,15 +47,15 @@ type FixNeverArrayRecursive<T>=T extends readonly never[]?T extends never[]?[]:r
|
|
|
47
47
|
*/
|
|
48
48
|
type NormalizeEmptyArraysRecursive<T>=T extends readonly(infer U)[]?U extends never|null|undefined?T extends readonly unknown[]?T extends(infer E)[]?[]:readonly []:never:T extends(infer E)[]?NormalizeEmptyArraysRecursive<U>[]:readonly NormalizeEmptyArraysRecursive<U>[]:T;
|
|
49
49
|
/** -------------------------------------------------------
|
|
50
|
-
* * ***RemoveEmptyArrayElements
|
|
50
|
+
* * ***Utility Type: `RemoveEmptyArrayElements`.***
|
|
51
51
|
* -------------------------------------------------------
|
|
52
|
-
* A type-level utility that **recursively removes empty array elements (`[]`) from a tuple type
|
|
53
|
-
* -
|
|
54
|
-
* - If `
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
52
|
+
* **A type-level utility that **recursively removes empty array elements (`[]`) from a tuple type**.**
|
|
53
|
+
* - **Behavior:**
|
|
54
|
+
* - If `T` is a tuple, checks the first element:
|
|
55
|
+
* - If `Head` is an empty array type (`[]`), it is removed.
|
|
56
|
+
* - Otherwise, `Head` is preserved.
|
|
57
|
+
* - Repeats recursively on the rest of the tuple.
|
|
58
|
+
* - Leaves non-tuple types unchanged.
|
|
59
59
|
* @template T - The tuple type to process.
|
|
60
60
|
* @example
|
|
61
61
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../chunk-
|
|
1
|
+
"use strict";var e=require("../chunk-IVL7CKVH.cjs"),r=require("../chunk-HYRQMTRH.cjs"),t=require("../chunk-6JFZL7YE.cjs");require("../chunk-UDA26MCU.cjs");var s=require("../chunk-PZQ6I4JJ.cjs");Object.defineProperty(exports,"assertIsBigInt",{enumerable:!0,get:function(){return e.assertIsBigInt}}),Object.defineProperty(exports,"assertIsNumber",{enumerable:!0,get:function(){return e.assertIsNumber}}),Object.defineProperty(exports,"assertIsString",{enumerable:!0,get:function(){return r.assertIsString}}),Object.defineProperty(exports,"assertIsArray",{enumerable:!0,get:function(){return t.assertIsArray}}),Object.defineProperty(exports,"assertIsBoolean",{enumerable:!0,get:function(){return s.assertIsBoolean}}),Object.defineProperty(exports,"assertIsPlainObject",{enumerable:!0,get:function(){return s.assertIsPlainObject}});
|
|
@@ -1,51 +1,64 @@
|
|
|
1
|
-
import{G as GetPreciseTypeOptions,I as IsNumberOptions,a as IsPlainObjectResult}from'../isPlainObject-
|
|
1
|
+
import{P as Prettify}from'../prettify-3o8_Kw6b.js';import{P as PickStrict}from'../pick-BSMX6Xe2.js';import{G as GetPreciseTypeOptions,I as IsNumberOptions,a as IsPlainObjectResult}from'../isPlainObject-DGJkcFYw.js';import'../if-ChM35c_q.js';import'../never-D89PbPh5.js';
|
|
2
2
|
/** -------------------------------------------------------
|
|
3
3
|
* * ***Shape of the object passed to custom error message functions.***
|
|
4
4
|
* -------------------------------------------------------
|
|
5
|
-
* This type describes the parameters received when `options.message`
|
|
6
|
-
* is defined as a function in `OptionsAssertIs
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* **This type describes the parameters received when `options.message`
|
|
6
|
+
* is defined as a function in {@link OptionsAssertIs | `OptionsAssertIs`}.**
|
|
7
|
+
* - **Parameter:**
|
|
8
|
+
* - `currentType` ➔ the actual detected runtime type of the value.
|
|
9
|
+
* - `validType` ➔ the required/expected type name that the value must match.
|
|
11
10
|
* @example
|
|
12
11
|
* ```ts
|
|
13
12
|
* const options: OptionsAssertIs = {
|
|
14
|
-
* message: ({ currentType, validType }) =>
|
|
15
|
-
* `Expected ${validType} but got ${currentType}
|
|
13
|
+
* message: ({ currentType, validType }) => {
|
|
14
|
+
* return `Expected ${validType} but got ${currentType}`;
|
|
15
|
+
* };
|
|
16
16
|
* };
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
type OptionsMessageFunctionAssertIs={
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
/** ---------------------------------------------------------------------------
|
|
21
|
+
* * ***The actual runtime type of the value being checked.***
|
|
22
|
+
* ---------------------------------------------------------------------------
|
|
23
|
+
* - ***Example:***
|
|
24
|
+
* - `"number"`, `"big-int"`, `"plain-object"`, (depends `formatCase` options).
|
|
23
25
|
*/
|
|
24
26
|
currentType:string;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
27
|
+
/** ---------------------------------------------------------------------------
|
|
28
|
+
* * ***The required/expected type that the value must conform to.***
|
|
29
|
+
* ---------------------------------------------------------------------------
|
|
30
|
+
* - ***Example:***
|
|
31
|
+
* - `"boolean"`, `"string"`, `"big-int"`, `"plain-object"`, (will force format to `kebab-case`).
|
|
32
|
+
*/
|
|
33
|
+
validType:string;};
|
|
34
|
+
/** -------------------------------------------------------
|
|
35
|
+
* * ***Custom error-message type for assertions option {@link OptionsAssertIs | `OptionsAssertIs`}.***
|
|
36
|
+
* -------------------------------------------------------
|
|
37
|
+
* - ***Accepts:***
|
|
38
|
+
* - A static string message.
|
|
39
|
+
* - A function receiving `{ currentType, validType }` and returning a string.
|
|
40
|
+
*/
|
|
41
|
+
type OptionsMessageAssertIs=string|(({currentType,validType}:OptionsMessageFunctionAssertIs)=>string);
|
|
42
|
+
/** ---------------------------------------------------------------------------
|
|
43
|
+
* * ***Base options for `assertIs*` functions.***
|
|
44
|
+
* ---------------------------------------------------------------------------
|
|
28
45
|
*/
|
|
29
|
-
|
|
46
|
+
type OptionsAssertIs=Prettify<{
|
|
30
47
|
/** -------------------------------------------------------
|
|
31
48
|
* * ***Custom error message for assertion failures.***
|
|
32
49
|
* -------------------------------------------------------
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* This option allows overriding the **default error message** when a value
|
|
36
|
-
* does not match the required type.
|
|
37
|
-
*
|
|
50
|
+
* **This option allows overriding the **default error message** when a value
|
|
51
|
+
* does not match the required type.**
|
|
38
52
|
* - If a **string** is provided:
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
53
|
+
* - Must be non-empty after trimming.
|
|
54
|
+
* - Will be used directly as the error message.
|
|
42
55
|
* - If a **function** is provided:
|
|
43
56
|
* - Receives an object containing:
|
|
44
57
|
* - `currentType` ➔ the detected runtime type of the value (depends `formatCase` options, e.g., `"number"`).
|
|
45
58
|
* - `validType` ➔ the expected type name (with format `kebab-case`, e.g., `"boolean"`, `"big-int"`, `"plain-object"`).
|
|
46
|
-
* - Must return a string
|
|
47
|
-
*
|
|
48
|
-
*
|
|
59
|
+
* - **Must** return a **string**:
|
|
60
|
+
* - **If** the **returned string is** `empty` or `whitespace`,
|
|
61
|
+
* the **default message** will be used instead.
|
|
49
62
|
* @example
|
|
50
63
|
* ```ts
|
|
51
64
|
* // Static message
|
|
@@ -53,25 +66,27 @@ validType:string;};type OptionsAssertIs={
|
|
|
53
66
|
*
|
|
54
67
|
* // Dynamic message
|
|
55
68
|
* {
|
|
56
|
-
* message: ({ currentType, validType }) =>
|
|
57
|
-
* `Expected ${validType} but got ${currentType}
|
|
69
|
+
* message: ({ currentType, validType }) => {
|
|
70
|
+
* return `Expected ${validType} but got ${currentType}`;
|
|
71
|
+
* };
|
|
58
72
|
* }
|
|
59
73
|
* ```
|
|
60
74
|
*/
|
|
61
|
-
message?:
|
|
75
|
+
message?:OptionsMessageAssertIs;}& PickStrict<GetPreciseTypeOptions,"formatCase">,{recursive:true;}>;
|
|
62
76
|
/** -------------------------------------------------------
|
|
63
77
|
* * ***Type guard assertion: `assertIsBoolean`.***
|
|
64
78
|
* -------------------------------------------------------
|
|
65
79
|
* **This function is an **assertion function**.**
|
|
66
|
-
* - Validates that the given `value` is a **boolean**.
|
|
67
|
-
* - After it returns successfully, TypeScript narrows the type of `value` to `boolean`.
|
|
68
80
|
* - **Behavior:**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
81
|
+
* - Validates that the given `value` is a **boolean**.
|
|
82
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `boolean`.
|
|
83
|
+
* - ✅ If `value` is a `boolean` ➔ execution continues normally.
|
|
84
|
+
* - ❌ If `value` is not a `boolean` ➔ throws a `TypeError` with either:
|
|
85
|
+
* - A custom error message (`options.message`), or
|
|
86
|
+
* - A default message including the actual type.
|
|
87
|
+
* @param {*} value - ***The value to validate.***
|
|
88
|
+
* @param {OptionsAssertIs} [options]
|
|
89
|
+
* ***Optional configuration:***
|
|
75
90
|
* - `message`: A custom error message (`string` or `function`).
|
|
76
91
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
77
92
|
* @returns {boolean} Narrows `value` to `boolean` if no error is thrown.
|
|
@@ -92,8 +107,9 @@ message?:string|(({currentType,validType}:OptionsMessageFunctionAssertIs)=>strin
|
|
|
92
107
|
*
|
|
93
108
|
* // ❌ Throws with custom function message + case formatting
|
|
94
109
|
* assertIsBoolean(123n, {
|
|
95
|
-
* message: ({ currentType, validType }) =>
|
|
96
|
-
* `Expected ${validType} but got (${currentType})
|
|
110
|
+
* message: ({ currentType, validType }) => {
|
|
111
|
+
* return `Expected ${validType} but got (${currentType}).`;
|
|
112
|
+
* },
|
|
97
113
|
* formatCase: "toKebabCase"
|
|
98
114
|
* });
|
|
99
115
|
* // ➔ TypeError: "Expected boolean but got (big-int)."
|
|
@@ -117,9 +133,9 @@ declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts
|
|
|
117
133
|
* * ***Type guard assertion: `assertIsBigInt`.***
|
|
118
134
|
* -------------------------------------------------------
|
|
119
135
|
* **This function is an **assertion function**.**
|
|
120
|
-
* - Validates that the given `value` is a **bigint**.
|
|
121
|
-
* - After it returns successfully, TypeScript narrows the type of `value` to `bigint`.
|
|
122
136
|
* - **Behavior:**
|
|
137
|
+
* - Validates that the given `value` is a **bigint**.
|
|
138
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `bigint`.
|
|
123
139
|
* - ✅ If `value` is a `bigint` ➔ execution continues normally.
|
|
124
140
|
* - ❌ If `value` is not a `bigint` ➔ throws a `TypeError` with either:
|
|
125
141
|
* - A custom error message (`options.message`), or
|
|
@@ -127,8 +143,9 @@ declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts
|
|
|
127
143
|
* - **ℹ️ Note:**
|
|
128
144
|
* - A `bigint` refers strictly to the JavaScript `bigint` primitive type (e.g., `123n`, `0n`, `-999999999999999999999n`).
|
|
129
145
|
* - This excludes `BigInt` objects created with `Object(BigInt(123))`.
|
|
130
|
-
* @param {*} value - The value to validate
|
|
131
|
-
* @param {OptionsAssertIs} [options]
|
|
146
|
+
* @param {*} value - ***The value to validate.***
|
|
147
|
+
* @param {OptionsAssertIs} [options]
|
|
148
|
+
* ***Optional configuration:***
|
|
132
149
|
* - `message`: A custom error message (`string` or `function`).
|
|
133
150
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
134
151
|
* @returns {boolean} Narrows `value` to `bigint` if no error is thrown.
|
|
@@ -149,8 +166,9 @@ declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts
|
|
|
149
166
|
*
|
|
150
167
|
* // ❌ Throws with custom function message + case formatting
|
|
151
168
|
* assertIsBigInt(42, {
|
|
152
|
-
* message: ({ currentType, validType }) =>
|
|
153
|
-
* `Expected ${validType} but got (${currentType})
|
|
169
|
+
* message: ({ currentType, validType }) => {
|
|
170
|
+
* return `Expected ${validType} but got (${currentType}).`;
|
|
171
|
+
* },
|
|
154
172
|
* formatCase: "toKebabCase"
|
|
155
173
|
* });
|
|
156
174
|
* // ➔ TypeError: "Expected bigint but got (number)."
|
|
@@ -174,9 +192,9 @@ declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts v
|
|
|
174
192
|
* * ***Type guard assertion: `assertIsNumber`.***
|
|
175
193
|
* -------------------------------------------------------
|
|
176
194
|
* **This function is an **assertion function**.**
|
|
177
|
-
* - Validates that the given `value` is a **number**.
|
|
178
|
-
* - After it returns successfully, TypeScript narrows the type of `value` to `number`.
|
|
179
195
|
* - **Behavior:**
|
|
196
|
+
* - Validates that the given `value` is a **number**.
|
|
197
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `number`.
|
|
180
198
|
* - ✅ If `value` is a `number` ➔ execution continues normally.
|
|
181
199
|
* - ❌ If `value` is not a `number` ➔ throws a `TypeError` with either:
|
|
182
200
|
* - A custom error message (`options.message`), or
|
|
@@ -185,8 +203,9 @@ declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts v
|
|
|
185
203
|
* - A `number` refers strictly to the JavaScript `number` primitive type (e.g., `42`, `3.14`, `-1`, `0`).
|
|
186
204
|
* - This excludes `Number` objects created with `new Number(123)`.
|
|
187
205
|
* - By default, `NaN` is **not considered** valid, you can allow it with `{ includeNaN: true }`.
|
|
188
|
-
* @param {*} value - The value to validate
|
|
189
|
-
* @param {OptionsAssertIsNumber} [options]
|
|
206
|
+
* @param {*} value - ***The value to validate.***
|
|
207
|
+
* @param {OptionsAssertIsNumber} [options]
|
|
208
|
+
* ***Optional configuration:***
|
|
190
209
|
* - `message`: A custom error message (`string` or `function`).
|
|
191
210
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
192
211
|
* - `includeNaN`: Whether to treat `NaN` as valid.
|
|
@@ -208,8 +227,9 @@ declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts v
|
|
|
208
227
|
*
|
|
209
228
|
* // ❌ Throws with custom function message + case formatting
|
|
210
229
|
* assertIsNumber("hello", {
|
|
211
|
-
* message: ({ currentType, validType }) =>
|
|
212
|
-
* `Expected ${validType} but got (${currentType})
|
|
230
|
+
* message: ({ currentType, validType }) => {
|
|
231
|
+
* return `Expected ${validType} but got (${currentType}).`;
|
|
232
|
+
* },
|
|
213
233
|
* formatCase: "toKebabCase"
|
|
214
234
|
* });
|
|
215
235
|
* // ➔ TypeError: "Expected number but got (string)."
|
|
@@ -242,16 +262,17 @@ declare const assertIsNumber:(value:unknown,options?:OptionsAssertIsNumber)=>ass
|
|
|
242
262
|
* * ***Type guard assertion: `assertIsArray`.***
|
|
243
263
|
* -------------------------------------------------------
|
|
244
264
|
* **This function is an **assertion function**.**
|
|
245
|
-
* - Validates that the given `value` is a **array**.
|
|
246
|
-
* - After it returns successfully, TypeScript narrows the type of `value` to `array` **(generic support)**.
|
|
247
265
|
* - **Behavior:**
|
|
266
|
+
* - Validates that the given `value` is a **array**.
|
|
267
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `array` **(generic support)**.
|
|
248
268
|
* - ✅ If `value` is an `array` ➔ execution continues normally.
|
|
249
269
|
* - ❌ If `value` is not an `array` ➔ throws a `TypeError` with either:
|
|
250
270
|
* - A custom error message (`options.message`), or
|
|
251
271
|
* - A default message including the actual type.
|
|
252
272
|
* @template T - The input type being asserted.
|
|
253
|
-
* @param {*} value - The value to validate
|
|
254
|
-
* @param {OptionsAssertIs} [options]
|
|
273
|
+
* @param {*} value - ***The value to validate.***
|
|
274
|
+
* @param {OptionsAssertIs} [options]
|
|
275
|
+
* ***Optional configuration:***
|
|
255
276
|
* - `message`: A custom error message (`string` or `function`).
|
|
256
277
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
257
278
|
* @returns {boolean} Narrows `value` to an `array` **(generic support)** if no error is thrown.
|
|
@@ -272,13 +293,13 @@ declare const assertIsNumber:(value:unknown,options?:OptionsAssertIsNumber)=>ass
|
|
|
272
293
|
*
|
|
273
294
|
* // ❌ Throws with custom function message + case formatting
|
|
274
295
|
* assertIsArray(42n, {
|
|
275
|
-
* message: ({ currentType, validType }) =>
|
|
276
|
-
* `Expected ${validType} but got (${currentType})
|
|
296
|
+
* message: ({ currentType, validType }) => {
|
|
297
|
+
* return `Expected ${validType} but got (${currentType}).`;
|
|
298
|
+
* },
|
|
277
299
|
* formatCase: "toKebabCase"
|
|
278
300
|
* });
|
|
279
301
|
* // ➔ TypeError: "Expected array but got (big-int)."
|
|
280
302
|
* ```
|
|
281
|
-
*
|
|
282
303
|
* -------------------------------------------------------
|
|
283
304
|
* ✅ ***Real-world usage with generic narrowing***:
|
|
284
305
|
* ```ts
|
|
@@ -298,16 +319,17 @@ declare function assertIsArray<T extends unknown[]>(value:T,options?:OptionsAsse
|
|
|
298
319
|
* * ***Type guard assertion: `assertIsPlainObject`.***
|
|
299
320
|
* -------------------------------------------------------
|
|
300
321
|
* **This function is an **assertion function**.**
|
|
301
|
-
* - Validates that the given `value` is a **plain-object**.
|
|
302
|
-
* - After it returns successfully, TypeScript narrows the type of `value` to `plain-object` **(generic support)**.
|
|
303
322
|
* - **Behavior:**
|
|
323
|
+
* - Validates that the given `value` is a **plain-object**.
|
|
324
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `plain-object` **(generic support)**.
|
|
304
325
|
* - ✅ If `value` is a `plain-object` ➔ execution continues normally.
|
|
305
326
|
* - ❌ If `value` is not a `plain-object` ➔ throws a `TypeError` with either:
|
|
306
327
|
* - A custom error message (`options.message`), or
|
|
307
328
|
* - A default message including the actual type.
|
|
308
329
|
* @template T - The input type being asserted.
|
|
309
|
-
* @param {*} value - The value to validate
|
|
310
|
-
* @param {OptionsAssertIs} [options]
|
|
330
|
+
* @param {*} value - ***The value to validate.***
|
|
331
|
+
* @param {OptionsAssertIs} [options]
|
|
332
|
+
* ***Optional configuration:***
|
|
311
333
|
* - `message`: A custom error message (`string` or `function`).
|
|
312
334
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
313
335
|
* @returns {boolean} Narrows `value` to a `plain-object` **(generic support)** if no error is thrown.
|
|
@@ -328,8 +350,9 @@ declare function assertIsArray<T extends unknown[]>(value:T,options?:OptionsAsse
|
|
|
328
350
|
*
|
|
329
351
|
* // ❌ Throws with custom message function and formatCase
|
|
330
352
|
* assertIsPlainObject(42n, {
|
|
331
|
-
* message: ({ currentType, validType }) =>
|
|
332
|
-
* `Expected ${validType} but got (${currentType})
|
|
353
|
+
* message: ({ currentType, validType }) => {
|
|
354
|
+
* return `Expected ${validType} but got (${currentType}).`;
|
|
355
|
+
* },
|
|
333
356
|
* formatCase: "toKebabCase"
|
|
334
357
|
* });
|
|
335
358
|
* // ➔ TypeError: "Expected plain-object but got (big-int)."
|
|
@@ -353,9 +376,9 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
353
376
|
* * ***Type guard assertion: `assertIsString`.***
|
|
354
377
|
* -------------------------------------------------------
|
|
355
378
|
* **This function is an **assertion function**.**
|
|
356
|
-
* - Validates that the given `value` is a **primitive-string**.
|
|
357
|
-
* - After it returns successfully, TypeScript narrows the type of `value` to `primitive-string`.
|
|
358
379
|
* - **Behavior:**
|
|
380
|
+
* - Validates that the given `value` is a **primitive-string**.
|
|
381
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `primitive-string`.
|
|
359
382
|
* - ✅ If `value` is a `primitive-string` ➔ execution continues normally.
|
|
360
383
|
* - ❌ If `value` is not a `primitive-string` ➔ throws a `TypeError` with either:
|
|
361
384
|
* - A custom error message (`options.message`), or
|
|
@@ -363,8 +386,9 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
363
386
|
* - **ℹ️ Note:**
|
|
364
387
|
* - A "string" refers strictly to a JavaScript `primitive-string` type (e.g., `"hello"`, `""`, `"123"`).
|
|
365
388
|
* - This function excludes `String` objects created with `new String()`.
|
|
366
|
-
* @param {*} value - The value to validate
|
|
367
|
-
* @param {OptionsAssertIs} [options]
|
|
389
|
+
* @param {*} value - ***The value to validate.***
|
|
390
|
+
* @param {OptionsAssertIs} [options]
|
|
391
|
+
* ***Optional configuration:***
|
|
368
392
|
* - `message`: A custom error message (`string` or `function`).
|
|
369
393
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
370
394
|
* @returns {boolean} Narrows `value` to `string` if no error is thrown.
|
|
@@ -385,7 +409,9 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
385
409
|
*
|
|
386
410
|
* // ❌ Throws with custom message function and formatCase
|
|
387
411
|
* assertIsString(42n, {
|
|
388
|
-
* message: ({ currentType, validType }) =>
|
|
412
|
+
* message: ({ currentType, validType }) => {
|
|
413
|
+
* return `Expected ${validType} but got (${currentType}).`;
|
|
414
|
+
* },
|
|
389
415
|
* formatCase: "toKebabCase"
|
|
390
416
|
* });
|
|
391
417
|
* // ➔ TypeError: "Expected string but got (big-int)."
|
package/dist/assertions/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{assertIsBigInt,assertIsNumber}from"../chunk-
|
|
1
|
+
export{assertIsBigInt,assertIsNumber}from"../chunk-3VA554KW.js";export{assertIsString}from"../chunk-SBKGWRS5.js";export{assertIsArray}from"../chunk-CKTLUNWX.js";import"../chunk-QNKGP5DY.js";export{assertIsBoolean,assertIsPlainObject}from"../chunk-CMW2TBOQ.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isEmptyArray as e,isEmptyObject as r}from"./chunk-6JFCSH7J.js";import{noop as t}from"./chunk-YWHHVDT4.js";import{safeStableStringify as o}from"./chunk-PET42Z7W.js";import{isNonEmptyString as n,getPreciseType as s,isNull as a,isUndefined as c,isString as i,isArray as m,isObject as l,isNumber as u,isNaN as v,isError as f,assertIsPlainObject as N,hasOwnProp as d,isBoolean as p,isFunction as g}from"./chunk-CMW2TBOQ.js";var y=(e,r)=>{if(!n(e)||!n(r))throw new TypeError(`Parameter \`dateString\` and \`format\` must be of type \`string\` and not empty-string, but received: "['dateString': \`${s(e)}\` - (current value: \`${o(e)}\`), 'format': \`${s(r)}\` - (current value: \`${o(r)}\`)]".`);const t=e.split(/[-/]/).map(Number);if(3!==t.length||t.some(isNaN))return null;let a,c,i;if("DD/MM/YYYY"===r)[a,c,i]=t;else{if("MM/DD/YYYY"!==r)return null;[c,a,i]=t}c-=1;const m=new Date(i,c,a);return m.getFullYear()!==i||m.getMonth()!==c||m.getDate()!==a?null:m},b=(e={})=>{N(e,{message:({currentType:e,validType:r})=>`Second parameter (\`options\`) must be of type \`${r}\`, but received: \`${e}\`.`});const r=!!d(e,"convertBooleans")&&e.convertBooleans,o=!!d(e,"convertDates")&&e.convertDates,n=!!d(e,"convertNumbers")&&e.convertNumbers,a=!!d(e,"loggingOnFail")&&e.loggingOnFail,c=!!d(e,"removeEmptyArrays")&&e.removeEmptyArrays,i=!!d(e,"removeEmptyObjects")&&e.removeEmptyObjects,l=!!d(e,"removeNulls")&&e.removeNulls,u=!!d(e,"removeUndefined")&&e.removeUndefined,v=!!d(e,"strictMode")&&e.strictMode,f=!!d(e,"checkSymbols")&&e.checkSymbols,y=!!d(e,"convertNaN")&&e.convertNaN,b=d(e,"customDateFormats")?e.customDateFormats:[],E=d(e,"onError")?e.onError:t;if(!(p(r)&&p(o)&&p(n)&&p(y)&&p(f)&&p(a)&&p(c)&&p(i)&&p(l)&&p(u)&&p(v)&&m(b)&&g(E)))throw new TypeError(`Invalid \`options\` parameter (second argument): \`convertBooleans\`, \`convertDates\`, \`convertNumbers\`, \`loggingOnFail\`, \`removeEmptyArrays\`, \`removeEmptyObjects\`, \`removeNulls\`, \`removeUndefined\`, \`strictMode\` expected to be a \`boolean\` type, \`customDateFormats\` expected to be a \`array\` type and \`onError\` expected to be a \`void function\` type. But received: ['convertBooleans': \`${s(r)}\`, 'convertDates': \`${s(o)}\`, 'convertNumbers': \`${s(n)}\`, 'loggingOnFail': \`${s(a)}\`, 'removeEmptyArrays': \`${s(c)}\`, 'removeEmptyObjects': \`${s(i)}\`, 'removeNulls': \`${s(l)}\`, 'removeUndefined': \`${s(u)}\`, 'strictMode': \`${s(v)}\`, 'customDateFormats': \`${s(b)}\`, 'onError': \`${s(E)}\`].`);return{convertBooleans:r,convertDates:o,convertNumbers:n,convertNaN:y,loggingOnFail:a,removeEmptyArrays:c,removeEmptyObjects:i,removeNulls:l,removeUndefined:u,strictMode:v,customDateFormats:b,onError:E,checkSymbols:f}},E=(t,o={})=>{const n=b(o);if(a(t))return n.removeNulls?void 0:null;if(!c(t)){if(i(t)){const e=t.trim();if(n.convertNaN&&"NaN"===e)return NaN;if(n.convertNumbers&&!isNaN(Number(e)))return Number(e);if(n.convertBooleans){if("true"===e)return!0;if("false"===e)return!1}if(n.convertDates){if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(e))return new Date(e);if(n.customDateFormats?.length)for(const r of n.customDateFormats){const t=y(e,r);if(t)return t}}return n.strictMode?void 0:e}if(m(t)){const r=t.map(e=>E(e,n)).filter(e=>!c(e));return n.removeEmptyArrays&&e(r)?void 0:r}if(l(t)){const e={};for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const o=E(t[r],n);c(o)||(e[r]=o)}return n.removeEmptyObjects&&r(e,{checkSymbols:n.checkSymbols})?void 0:e}return n.strictMode?void 0:t}n.removeUndefined},D=e=>{if(!i(e)&&!u(e))return 0;const r=String(e).trim().replace(/[^0-9]/g,"");return Number(r)||0};function h(e,r={}){if(a(e))return null;const t=b(r);if(t.convertNaN&&(v(e)||n(e)&&"NaN"===e))return NaN;if(t.convertNumbers&&!v(Number(e))&&u(D(e)))return Number(e);if(i(e))try{let r=function(e){const r=new Set(["\\",'"',"/","b","f","n","r","t","u"]);let t="",o=!1,n=!1,s=!1;for(let a=0;a<e.length;a++){const c=e[a];if(s)o?"'"===c?t+="'":r.has(c)?t+="\\"===c?"\\\\":'"'===c?'\\"':"\\"+c:t+="\\\\"+c:n?'"'===c?t+='\\"':r.has(c)?t+="\\"+c:t+="\\\\"+c:t+="\\"+c,s=!1;else if("\\"!==c){if(o||n){if(o){if("'"===c){t+='"',o=!1;continue}}else if(n&&'"'===c){t+='"',n=!1;continue}}else{if("'"===c){t+='"',o=!0;continue}if('"'===c){t+='"',n=!0;continue}}t+=c}else s=!0}return t}(e);r=t.removeUndefined?r.replace(/,\s*"[^"]*"\s*:\s*undefined(?=\s*[},])/g,"").replace(/"[^"]*"\s*:\s*undefined\s*(,)?/g,""):r.replace(/:\s*undefined(?=\s*[,}])/g,":null"),r=t.convertNaN?r.replace(/:\s*NaN(?=\s*[,}])/g,':"NaN"'):r.replace(/:\s*NaN(?=\s*[,}])/g,':"NaN"').replace(/,\s*"[^"]*"\s*:\s*NaN(?=\s*[},])/g,"").replace(/"[^"]*"\s*:\s*NaN\s*(,)?/g,""),r=r.replace(/,(\s*[}\]])/g,"$1");const o=JSON.parse(r);return E(o,t)}catch(e){return t.loggingOnFail&&console.error("Failed to parsing at `safeJsonParse`:",e),void t.onError(f(e)?new Error(e.message.replace(/^JSON\.parse:/,"Failed to parsing")):new Error(String(e)))}}export{E as cleanParsedData,D as extractDigits,y as parseCustomDate,h as safeJsonParse};
|