@rzl-zone/utils-js 3.3.1 → 3.5.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 +94 -45
- package/dist/assertions/index.cjs +34 -1
- package/dist/assertions/index.d.ts +2 -2
- package/dist/assertions/index.js +5 -1
- package/dist/chunk-2CQX5CBG.js +247 -1
- package/dist/chunk-2IOOEY45.cjs +20 -1
- package/dist/chunk-2WA36TC5.cjs +176 -0
- package/dist/chunk-3IBQ5MOM.js +6 -1
- package/dist/chunk-3VA554KW.js +23 -1
- package/dist/chunk-5757UBXJ.cjs +144 -1
- package/dist/chunk-5IGC6PBH.js +22 -1
- package/dist/chunk-5KJFVIQT.cjs +55 -1
- package/dist/chunk-6JFCSH7J.js +24 -1
- package/dist/chunk-6JFZL7YE.cjs +14 -1
- package/dist/chunk-7ODAAXX5.cjs +361 -1
- package/dist/chunk-BAV5T2E3.cjs +5 -1
- package/dist/chunk-CAH33WOQ.cjs +25 -1
- package/dist/chunk-CDCERIZ2.js +164 -0
- package/dist/chunk-CKTLUNWX.js +12 -1
- package/dist/chunk-CMW2TBOQ.js +522 -1
- package/dist/chunk-D3ENH7H6.cjs +87 -1
- package/dist/chunk-DEZZUYE2.js +139 -1
- package/dist/chunk-DVMHRLKP.cjs +6 -1
- package/dist/chunk-DWF2R5GD.cjs +212 -1
- package/dist/chunk-E55EQK2U.cjs +8 -1
- package/dist/chunk-E74U6CYP.cjs +8 -1
- package/dist/chunk-EL6A35UR.cjs +51 -1
- package/dist/chunk-F6IPNNSJ.cjs +531 -1
- package/dist/chunk-FJZGG54N.cjs +252 -1
- package/dist/chunk-FWCKOJZM.js +519 -1
- package/dist/chunk-FWHNWL2P.cjs +409 -1
- package/dist/chunk-GGEADHZO.js +78 -1
- package/dist/chunk-GQR4R5WY.js +21 -1
- package/dist/chunk-H66AC7GK.cjs +81 -1
- package/dist/chunk-HQWOFR56.cjs +23 -1
- package/dist/chunk-HYRQMTRH.cjs +14 -1
- package/dist/chunk-IRFL4MAX.js +53 -1
- package/dist/chunk-IVL7CKVH.cjs +26 -1
- package/dist/chunk-IZPBKKPO.js +6 -1
- package/dist/chunk-JBQMXC5I.cjs +93 -1
- package/dist/chunk-JEQEF5WD.js +81 -1
- package/dist/chunk-JMJQCN74.js +334 -1
- package/dist/chunk-KHO2SBNA.cjs +6 -1
- package/dist/chunk-KVAL5PAG.cjs +16 -1
- package/dist/chunk-L5RDAVVH.js +5 -1
- package/dist/chunk-LS6U7FAY.cjs +98 -1
- package/dist/chunk-NBZWMBO6.js +88 -1
- package/dist/chunk-NRF6LWBC.cjs +45 -1
- package/dist/chunk-OI5XKNZO.js +42 -1
- package/dist/chunk-ONZFBJVW.js +5 -1
- package/dist/chunk-OYTYSY7G.js +94 -1
- package/dist/chunk-PET42Z7W.js +107 -1
- package/dist/chunk-PZQ6I4JJ.cjs +559 -1
- package/dist/chunk-QBKAEVYG.js +102 -1
- package/dist/chunk-QNKGP5DY.js +5 -1
- package/dist/chunk-RIPKY4RU.js +407 -1
- package/dist/chunk-RZW35UN5.cjs +105 -1
- package/dist/chunk-SBFNXGTJ.js +207 -1
- package/dist/chunk-SBKGWRS5.js +12 -1
- package/dist/chunk-SIM77PU4.js +46 -1
- package/dist/chunk-T2T7K3KR.js +18 -1
- package/dist/chunk-T7PU2V7X.cjs +111 -1
- package/dist/chunk-UDA26MCU.cjs +6 -1
- package/dist/chunk-V45XJKHW.cjs +8 -1
- package/dist/chunk-VJDDGRIK.cjs +6 -1
- package/dist/chunk-W2WNBUDE.js +6 -1
- package/dist/chunk-WVSPXFTY.js +5 -1
- package/dist/chunk-XABCB3Y7.cjs +563 -1
- package/dist/chunk-XEDXFSGI.js +14 -1
- package/dist/chunk-YKPSRP5G.js +552 -1
- package/dist/chunk-YWHHVDT4.js +4 -1
- package/dist/chunk-ZETAZZLD.cjs +27 -1
- package/dist/conversions/index.cjs +97 -1
- package/dist/conversions/index.d.ts +2 -2
- package/dist/conversions/index.js +16 -1
- package/dist/events/index.cjs +25 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +4 -1
- package/dist/formatters/index.cjs +55 -1
- package/dist/formatters/index.d.ts +2 -2
- package/dist/formatters/index.js +10 -1
- package/dist/generators/index.cjs +31 -1
- package/dist/generators/index.d.ts +2 -2
- package/dist/generators/index.js +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/{isPlainObject-DGJkcFYw.d.ts → isPlainObject-FWmcJF6k.d.ts} +5 -5
- package/dist/next/index.cjs +205 -1
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +200 -1
- package/dist/next/server/index.cjs +34 -1
- package/dist/next/server/index.d.ts +1 -1
- package/dist/next/server/index.js +32 -1
- package/dist/operations/index.cjs +26 -1
- package/dist/operations/index.d.ts +2 -2
- package/dist/operations/index.js +9 -1
- package/dist/parsers/index.cjs +11 -1
- package/dist/parsers/index.d.ts +1 -1
- package/dist/parsers/index.js +2 -1
- package/dist/predicates/index.cjs +292 -1
- package/dist/predicates/index.d.ts +4 -4
- package/dist/predicates/index.js +15 -1
- package/dist/promises/index.cjs +18 -1
- package/dist/promises/index.d.ts +2 -2
- package/dist/promises/index.js +5 -1
- package/dist/rzl-utils.global.js +16 -1
- package/dist/strings/index.cjs +75 -1
- package/dist/strings/index.d.ts +2 -2
- package/dist/strings/index.js +6 -1
- package/dist/tailwind/index.cjs +36 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tailwind/index.js +3 -1
- package/dist/urls/index.cjs +44 -1
- package/dist/urls/index.d.ts +1 -1
- package/dist/urls/index.js +15 -1
- package/package.json +16 -24
- package/dist/NumberRangeUnion-B6bhM2s7.d.ts +0 -33
- package/dist/any-v4TsK9ES.d.ts +0 -66
- package/dist/arrays-normalize-recursive-BqmVuFlD.d.ts +0 -72
- package/dist/chunk-JYQTCICM.js +0 -1
- package/dist/chunk-YLA3DURS.cjs +0 -1
- package/dist/extends-DtdRjDyU.d.ts +0 -343
- package/dist/if-ChM35c_q.d.ts +0 -19
- package/dist/is-array-BJeHxPM3.d.ts +0 -952
- package/dist/never-D89PbPh5.d.ts +0 -66
- package/dist/nils-CO8zLHSB.d.ts +0 -151
- package/dist/or-C6qzKt2I.d.ts +0 -82
- package/dist/override-CL2olHE5.d.ts +0 -59
- package/dist/pick-BSMX6Xe2.d.ts +0 -15
- package/dist/prettify-3o8_Kw6b.d.ts +0 -564
- package/dist/promises-LU7K00H0.d.ts +0 -72
- package/dist/string-B1jlOnws.d.ts +0 -312
- package/dist/types/index.d.ts +0 -3345
package/README.md
CHANGED
|
@@ -70,6 +70,13 @@
|
|
|
70
70
|
- ✅ Node.js (18.17.0, or higher depending on NextJS version) - With NextJS
|
|
71
71
|
- ✅ Modern browsers (via bundlers like Webpack / Vite)
|
|
72
72
|
|
|
73
|
+
- **TypeScript Build Info:**
|
|
74
|
+
- Target: `ES2022`
|
|
75
|
+
- Module: `ES2022`
|
|
76
|
+
- Module Resolution: `bundler`
|
|
77
|
+
|
|
78
|
+
> ℹ️ Note: These TypeScript settings are used to build the package. Consumers do **not** need to match these settings unless they plan to build or modify the source code.
|
|
79
|
+
|
|
73
80
|
---
|
|
74
81
|
|
|
75
82
|
<h2 id="installation">⚙️ <strong>Installation</strong></h2>
|
|
@@ -101,8 +108,6 @@
|
|
|
101
108
|
- 📦 Works in **Node.js** & modern browsers
|
|
102
109
|
- ❤️ Simple API, easy to extend
|
|
103
110
|
- 🧬 **Next.js support**: helpers for dynamic routes, building URLs, reading env, extracting client IP
|
|
104
|
-
- 🛠 Additional TypeScript types: `OmitStrict`, `PartialOnly`, etc.
|
|
105
|
-
|
|
106
111
|
---
|
|
107
112
|
|
|
108
113
|
<h2 id="nextjs-support">🧬 <strong>Next.js Support</strong></h2>
|
|
@@ -146,42 +151,95 @@
|
|
|
146
151
|
import { | } from "@rzl-zone/utils-js/promises";
|
|
147
152
|
import { | } from "@rzl-zone/utils-js/strings";
|
|
148
153
|
import { | } from "@rzl-zone/utils-js/tailwind";
|
|
149
|
-
import { | } from "@rzl-zone/utils-js/urls";
|
|
150
|
-
|
|
151
|
-
import type { | } from "@rzl-zone/utils-js/types";
|
|
154
|
+
import { | } from "@rzl-zone/utils-js/urls";
|
|
152
155
|
```
|
|
153
156
|
#### Place your cursor inside { } or after "@rzl-zone/utils-js/{{ | }}" then press Ctrl+Space to see all available functions/types with full TSDoc hints.
|
|
154
|
-
---
|
|
155
|
-
### **Hint: Autocomplete**
|
|
156
|
-
|
|
157
|
-
**To get the best autocomplete hints for folders and files, add the `types` field in your configuration file:**
|
|
158
|
-
|
|
159
|
-
#### # **_TypeScript_**:
|
|
160
|
-
Add this to your `tsconfig.json`:
|
|
161
|
-
```jsonc
|
|
162
|
-
// tsconfig.json
|
|
163
|
-
{
|
|
164
|
-
"compilerOptions": {
|
|
165
|
-
"types": [
|
|
166
|
-
"@rzl-zone/utils-js"
|
|
167
|
-
]
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
157
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
158
|
+
> ***⚠️ Note:*** Starting from version `3.4.0+`, the extra TypeScript types (e.g., `OmitStrict`, `PartialOnly`, etc), have been removed from the package. To use them, you now need to install **[`@rzl-zone/ts-types-plus`](https://www.npmjs.com/package/@rzl-zone/ts-types-plus)** separately.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
### **Hint: Autocomplete Setup (Step by Step)**
|
|
162
|
+
|
|
163
|
+
#### Make TypeScript & VSCode automatically provide autocomplete for `@rzl-zone/utils-js` without needing triple-slash references in every file:
|
|
164
|
+
|
|
165
|
+
- 1️⃣ **Install @rzl-zone/utils-js.**
|
|
166
|
+
|
|
167
|
+
- Make sure the package is installed:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
npm install @rzl-zone/utils-js
|
|
171
|
+
# or
|
|
172
|
+
yarn add @rzl-zone/utils-js
|
|
173
|
+
# or
|
|
174
|
+
pnpm add @rzl-zone/utils-js
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- 2️⃣ **Create a types folder.**
|
|
178
|
+
|
|
179
|
+
- Inside your project root, make a folder called `types`:
|
|
180
|
+
|
|
181
|
+
```pgsql
|
|
182
|
+
project-root/
|
|
183
|
+
├─ src/
|
|
184
|
+
├─ types/
|
|
185
|
+
│ └─ index.d.ts
|
|
186
|
+
├─ tsconfig.json
|
|
187
|
+
└─ jsconfig.json
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
- 3️⃣ **Add the global reference file.**
|
|
191
|
+
|
|
192
|
+
- Create `types/index.d.ts` with this content:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
/// <reference types="@rzl-zone/utils-js" />
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
- This tells TypeScript to include the types from `@rzl-zone/utils-js` globally.
|
|
199
|
+
- You can add more references here if needed, for example:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
/// <reference types="node" />
|
|
203
|
+
/// <reference types="@rzl-zone/utils-js" />
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
- 4️⃣ **Update tsconfig.json.**
|
|
207
|
+
|
|
208
|
+
- Make sure not to override "types" (or leave it empty) so TypeScript automatically picks up your types folder:
|
|
209
|
+
|
|
210
|
+
```jsonc
|
|
211
|
+
// tsconfig.json
|
|
212
|
+
{
|
|
213
|
+
"compilerOptions": {
|
|
214
|
+
"typeRoots": ["./types", "./node_modules/@types"],
|
|
215
|
+
// other your config...
|
|
216
|
+
},
|
|
217
|
+
"include": ["src", "types"],
|
|
218
|
+
// other your config...
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
- `typeRoots` tells TS where to look for global type definitions.
|
|
222
|
+
- The `types` folder comes first, so your references override or add to the default `@types` packages
|
|
223
|
+
|
|
224
|
+
- 5️⃣ **Update jsconfig.json (for JavaScript projects).**
|
|
225
|
+
|
|
226
|
+
- If you also work with JS, do the same:
|
|
227
|
+
|
|
228
|
+
```jsonc
|
|
229
|
+
// jsconfig.json
|
|
230
|
+
{
|
|
231
|
+
"compilerOptions": {
|
|
232
|
+
"checkJs": true, // Optional, enables type checking
|
|
233
|
+
"typeRoots": ["./types", "./node_modules/@types"],
|
|
234
|
+
// other your config...
|
|
235
|
+
},
|
|
236
|
+
"include": ["src", "types"],
|
|
237
|
+
// other your config...
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
>ℹ️ ***Tip:*** *For JS projects, consider adding "checkJs": true for better IntelliSense.*
|
|
241
|
+
|
|
242
|
+
**Now, all types from @rzl-zone/utils-js are globally available, and you don’t need "types": ["@rzl-zone/utils-js"] in tsconfig.json.**
|
|
185
243
|
|
|
186
244
|
<!-- - <h4 id="detailed-features--assertions">
|
|
187
245
|
Assertions -
|
|
@@ -219,21 +277,12 @@ console.log(isServer());
|
|
|
219
277
|
// ➔ `true` if running on server-side, `false` if in browser.
|
|
220
278
|
```
|
|
221
279
|
|
|
222
|
-
#### *Example Types Helper Import:*
|
|
223
|
-
|
|
224
|
-
```ts
|
|
225
|
-
import type { OmitStrict } from "@rzl-zone/utils-js/types";
|
|
226
|
-
|
|
227
|
-
type MyType = OmitStrict<OtherType, "omittingProps">;
|
|
228
|
-
// Fully strict TS omit that requires all keys to exist in target
|
|
229
|
-
```
|
|
230
|
-
|
|
231
280
|
---
|
|
232
281
|
|
|
233
282
|
<h2 id="sponsor-this-package">❤️ <strong>Sponsor this package</strong></h2>
|
|
234
283
|
|
|
235
284
|
**Help support development:**
|
|
236
|
-
*[👉 Become a sponsor](https://github.com/sponsors/rzl-app)*
|
|
285
|
+
*[👉 **Become a sponsor**](https://github.com/sponsors/rzl-app)*
|
|
237
286
|
|
|
238
287
|
---
|
|
239
288
|
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkIVL7CKVH_cjs = require('../chunk-IVL7CKVH.cjs');
|
|
4
|
+
var chunkHYRQMTRH_cjs = require('../chunk-HYRQMTRH.cjs');
|
|
5
|
+
var chunk6JFZL7YE_cjs = require('../chunk-6JFZL7YE.cjs');
|
|
6
|
+
require('../chunk-UDA26MCU.cjs');
|
|
7
|
+
var chunkPZQ6I4JJ_cjs = require('../chunk-PZQ6I4JJ.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, "assertIsBigInt", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkIVL7CKVH_cjs.assertIsBigInt; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "assertIsNumber", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkIVL7CKVH_cjs.assertIsNumber; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "assertIsString", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkHYRQMTRH_cjs.assertIsString; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "assertIsArray", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunk6JFZL7YE_cjs.assertIsArray; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "assertIsBoolean", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkPZQ6I4JJ_cjs.assertIsBoolean; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "assertIsPlainObject", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkPZQ6I4JJ_cjs.assertIsPlainObject; }
|
|
34
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Prettify,PickStrict}from'@rzl-zone/ts-types-plus';import{G as GetPreciseTypeOptions,I as IsNumberOptions,a as IsPlainObjectResult}from'../isPlainObject-FWmcJF6k.js';
|
|
2
2
|
/** -------------------------------------------------------
|
|
3
3
|
* * ***Shape of the object passed to custom error message functions.***
|
|
4
4
|
* -------------------------------------------------------
|
|
@@ -431,4 +431,4 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
431
431
|
* console.log(result.toUpperCase()); // ➔ ✅ type-safe
|
|
432
432
|
* ```
|
|
433
433
|
*/
|
|
434
|
-
declare const assertIsString:(value:unknown,options?:OptionsAssertIs)=>asserts value is string;export{assertIsArray,assertIsBigInt,assertIsBoolean,assertIsNumber,assertIsPlainObject,assertIsString};
|
|
434
|
+
declare const assertIsString:(value:unknown,options?:OptionsAssertIs)=>asserts value is string;export{assertIsArray,assertIsBigInt,assertIsBoolean,assertIsNumber,assertIsPlainObject,assertIsString};
|
package/dist/assertions/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export{assertIsBigInt,assertIsNumber}from
|
|
1
|
+
export { assertIsBigInt, assertIsNumber } from '../chunk-3VA554KW.js';
|
|
2
|
+
export { assertIsString } from '../chunk-SBKGWRS5.js';
|
|
3
|
+
export { assertIsArray } from '../chunk-CKTLUNWX.js';
|
|
4
|
+
import '../chunk-QNKGP5DY.js';
|
|
5
|
+
export { assertIsBoolean, assertIsPlainObject } from '../chunk-CMW2TBOQ.js';
|
package/dist/chunk-2CQX5CBG.js
CHANGED
|
@@ -1 +1,247 @@
|
|
|
1
|
-
import{isEmptyArray
|
|
1
|
+
import { isEmptyArray, isEmptyObject } from './chunk-6JFCSH7J.js';
|
|
2
|
+
import { noop } from './chunk-YWHHVDT4.js';
|
|
3
|
+
import { safeStableStringify } from './chunk-PET42Z7W.js';
|
|
4
|
+
import { isNonEmptyString, getPreciseType, isNull, isUndefined, isString, isArray, isObject, isNumber, isNaN as isNaN$1, isError, assertIsPlainObject, hasOwnProp, isBoolean, isFunction } from './chunk-CMW2TBOQ.js';
|
|
5
|
+
var parseCustomDate = (dateString, format) => {
|
|
6
|
+
if (!isNonEmptyString(dateString) || !isNonEmptyString(format)) {
|
|
7
|
+
throw new TypeError(
|
|
8
|
+
`Parameter \`dateString\` and \`format\` must be of type \`string\` and not empty-string, but received: "['dateString': \`${getPreciseType(
|
|
9
|
+
dateString
|
|
10
|
+
)}\` - (current value: \`${safeStableStringify(
|
|
11
|
+
dateString
|
|
12
|
+
)}\`), 'format': \`${getPreciseType(
|
|
13
|
+
format
|
|
14
|
+
)}\` - (current value: \`${safeStableStringify(format)}\`)]".`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
const dateParts = dateString.split(/[-/]/).map(Number);
|
|
18
|
+
if (dateParts.length !== 3 || dateParts.some(isNaN)) return null;
|
|
19
|
+
let day, month, year;
|
|
20
|
+
if (format === "DD/MM/YYYY") {
|
|
21
|
+
[day, month, year] = dateParts;
|
|
22
|
+
} else if (format === "MM/DD/YYYY") {
|
|
23
|
+
[month, day, year] = dateParts;
|
|
24
|
+
} else {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
month -= 1;
|
|
28
|
+
const date = new Date(year, month, day);
|
|
29
|
+
if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return date;
|
|
33
|
+
};
|
|
34
|
+
var validateJsonParsingOptions = (optionsValue = {}) => {
|
|
35
|
+
assertIsPlainObject(optionsValue, {
|
|
36
|
+
message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
37
|
+
});
|
|
38
|
+
const convertBooleans = hasOwnProp(optionsValue, "convertBooleans") ? optionsValue.convertBooleans : false;
|
|
39
|
+
const convertDates = hasOwnProp(optionsValue, "convertDates") ? optionsValue.convertDates : false;
|
|
40
|
+
const convertNumbers = hasOwnProp(optionsValue, "convertNumbers") ? optionsValue.convertNumbers : false;
|
|
41
|
+
const loggingOnFail = hasOwnProp(optionsValue, "loggingOnFail") ? optionsValue.loggingOnFail : false;
|
|
42
|
+
const removeEmptyArrays = hasOwnProp(optionsValue, "removeEmptyArrays") ? optionsValue.removeEmptyArrays : false;
|
|
43
|
+
const removeEmptyObjects = hasOwnProp(optionsValue, "removeEmptyObjects") ? optionsValue.removeEmptyObjects : false;
|
|
44
|
+
const removeNulls = hasOwnProp(optionsValue, "removeNulls") ? optionsValue.removeNulls : false;
|
|
45
|
+
const removeUndefined = hasOwnProp(optionsValue, "removeUndefined") ? optionsValue.removeUndefined : false;
|
|
46
|
+
const strictMode = hasOwnProp(optionsValue, "strictMode") ? optionsValue.strictMode : false;
|
|
47
|
+
const checkSymbols = hasOwnProp(optionsValue, "checkSymbols") ? optionsValue.checkSymbols : false;
|
|
48
|
+
const convertNaN = hasOwnProp(optionsValue, "convertNaN") ? optionsValue.convertNaN : false;
|
|
49
|
+
const customDateFormats = hasOwnProp(optionsValue, "customDateFormats") ? optionsValue.customDateFormats : [];
|
|
50
|
+
const onError = hasOwnProp(optionsValue, "onError") ? optionsValue.onError : noop;
|
|
51
|
+
if (!(isBoolean(convertBooleans) && isBoolean(convertDates) && isBoolean(convertNumbers) && isBoolean(convertNaN) && isBoolean(checkSymbols) && isBoolean(loggingOnFail) && isBoolean(removeEmptyArrays) && isBoolean(removeEmptyObjects) && isBoolean(removeNulls) && isBoolean(removeUndefined) && isBoolean(strictMode) && isArray(customDateFormats) && isFunction(onError))) {
|
|
52
|
+
throw new TypeError(
|
|
53
|
+
`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': \`${getPreciseType(
|
|
54
|
+
convertBooleans
|
|
55
|
+
)}\`, 'convertDates': \`${getPreciseType(
|
|
56
|
+
convertDates
|
|
57
|
+
)}\`, 'convertNumbers': \`${getPreciseType(
|
|
58
|
+
convertNumbers
|
|
59
|
+
)}\`, 'loggingOnFail': \`${getPreciseType(
|
|
60
|
+
loggingOnFail
|
|
61
|
+
)}\`, 'removeEmptyArrays': \`${getPreciseType(
|
|
62
|
+
removeEmptyArrays
|
|
63
|
+
)}\`, 'removeEmptyObjects': \`${getPreciseType(
|
|
64
|
+
removeEmptyObjects
|
|
65
|
+
)}\`, 'removeNulls': \`${getPreciseType(
|
|
66
|
+
removeNulls
|
|
67
|
+
)}\`, 'removeUndefined': \`${getPreciseType(
|
|
68
|
+
removeUndefined
|
|
69
|
+
)}\`, 'strictMode': \`${getPreciseType(
|
|
70
|
+
strictMode
|
|
71
|
+
)}\`, 'customDateFormats': \`${getPreciseType(
|
|
72
|
+
customDateFormats
|
|
73
|
+
)}\`, 'onError': \`${getPreciseType(onError)}\`].`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
convertBooleans,
|
|
78
|
+
convertDates,
|
|
79
|
+
convertNumbers,
|
|
80
|
+
convertNaN,
|
|
81
|
+
loggingOnFail,
|
|
82
|
+
removeEmptyArrays,
|
|
83
|
+
removeEmptyObjects,
|
|
84
|
+
removeNulls,
|
|
85
|
+
removeUndefined,
|
|
86
|
+
strictMode,
|
|
87
|
+
customDateFormats,
|
|
88
|
+
onError,
|
|
89
|
+
checkSymbols
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
var cleanParsedData = (data, options = {}) => {
|
|
93
|
+
const validOptions = validateJsonParsingOptions(options);
|
|
94
|
+
if (isNull(data)) return validOptions.removeNulls ? void 0 : null;
|
|
95
|
+
if (isUndefined(data)) return validOptions.removeUndefined ? void 0 : void 0;
|
|
96
|
+
if (isString(data)) {
|
|
97
|
+
const trimmed = data.trim();
|
|
98
|
+
if (validOptions.convertNaN && trimmed === "NaN") return NaN;
|
|
99
|
+
if (validOptions.convertNumbers && !isNaN(Number(trimmed))) {
|
|
100
|
+
return Number(trimmed);
|
|
101
|
+
}
|
|
102
|
+
if (validOptions.convertBooleans) {
|
|
103
|
+
if (trimmed === "true") return true;
|
|
104
|
+
if (trimmed === "false") return false;
|
|
105
|
+
}
|
|
106
|
+
if (validOptions.convertDates) {
|
|
107
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(trimmed)) {
|
|
108
|
+
return new Date(trimmed);
|
|
109
|
+
}
|
|
110
|
+
if (validOptions.customDateFormats?.length) {
|
|
111
|
+
for (const format of validOptions.customDateFormats) {
|
|
112
|
+
const date = parseCustomDate(trimmed, format);
|
|
113
|
+
if (date) return date;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return validOptions.strictMode ? void 0 : trimmed;
|
|
118
|
+
}
|
|
119
|
+
if (isArray(data)) {
|
|
120
|
+
const cleanedArray = data.map((item) => cleanParsedData(item, validOptions)).filter((item) => !isUndefined(item));
|
|
121
|
+
return validOptions.removeEmptyArrays && isEmptyArray(cleanedArray) ? void 0 : cleanedArray;
|
|
122
|
+
}
|
|
123
|
+
if (isObject(data)) {
|
|
124
|
+
const cleanedObject = {};
|
|
125
|
+
for (const key in data) {
|
|
126
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
127
|
+
const cleanedValue = cleanParsedData(data[key], validOptions);
|
|
128
|
+
if (!isUndefined(cleanedValue)) {
|
|
129
|
+
cleanedObject[key] = cleanedValue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return validOptions.removeEmptyObjects && isEmptyObject(cleanedObject, { checkSymbols: validOptions.checkSymbols }) ? void 0 : cleanedObject;
|
|
134
|
+
}
|
|
135
|
+
return validOptions.strictMode ? void 0 : data;
|
|
136
|
+
};
|
|
137
|
+
var extractDigits = (value) => {
|
|
138
|
+
if (!isString(value) && !isNumber(value)) return 0;
|
|
139
|
+
const cleaned = String(value).trim().replace(/[^0-9]/g, "");
|
|
140
|
+
return Number(cleaned) || 0;
|
|
141
|
+
};
|
|
142
|
+
function fixSingleQuotesEscapeBackslash(input) {
|
|
143
|
+
const validEscapes = /* @__PURE__ */ new Set(["\\", '"', "/", "b", "f", "n", "r", "t", "u"]);
|
|
144
|
+
let output = "";
|
|
145
|
+
let inSingleQuote = false;
|
|
146
|
+
let inDoubleQuote = false;
|
|
147
|
+
let escapeNext = false;
|
|
148
|
+
for (let i = 0; i < input.length; i++) {
|
|
149
|
+
const c = input[i];
|
|
150
|
+
if (escapeNext) {
|
|
151
|
+
if (inSingleQuote) {
|
|
152
|
+
if (c === "'") {
|
|
153
|
+
output += "'";
|
|
154
|
+
} else if (validEscapes.has(c)) {
|
|
155
|
+
if (c === "\\") {
|
|
156
|
+
output += "\\\\";
|
|
157
|
+
} else if (c === '"') {
|
|
158
|
+
output += '\\"';
|
|
159
|
+
} else {
|
|
160
|
+
output += "\\" + c;
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
output += "\\\\" + c;
|
|
164
|
+
}
|
|
165
|
+
} else if (inDoubleQuote) {
|
|
166
|
+
if (c === '"') {
|
|
167
|
+
output += '\\"';
|
|
168
|
+
} else if (validEscapes.has(c)) {
|
|
169
|
+
output += "\\" + c;
|
|
170
|
+
} else {
|
|
171
|
+
output += "\\\\" + c;
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
output += "\\" + c;
|
|
175
|
+
}
|
|
176
|
+
escapeNext = false;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (c === "\\") {
|
|
180
|
+
escapeNext = true;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
184
|
+
if (c === "'") {
|
|
185
|
+
output += '"';
|
|
186
|
+
inSingleQuote = true;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (c === '"') {
|
|
190
|
+
output += '"';
|
|
191
|
+
inDoubleQuote = true;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
} else if (inSingleQuote) {
|
|
195
|
+
if (c === "'") {
|
|
196
|
+
output += '"';
|
|
197
|
+
inSingleQuote = false;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
} else if (inDoubleQuote) {
|
|
201
|
+
if (c === '"') {
|
|
202
|
+
output += '"';
|
|
203
|
+
inDoubleQuote = false;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
output += c;
|
|
208
|
+
}
|
|
209
|
+
return output;
|
|
210
|
+
}
|
|
211
|
+
function safeJsonParse(value, options = {}) {
|
|
212
|
+
if (isNull(value)) return null;
|
|
213
|
+
const validOptions = validateJsonParsingOptions(options);
|
|
214
|
+
if (validOptions.convertNaN && (isNaN$1(value) || isNonEmptyString(value) && value === "NaN")) {
|
|
215
|
+
return NaN;
|
|
216
|
+
}
|
|
217
|
+
if (validOptions.convertNumbers && !isNaN$1(Number(value)) && isNumber(extractDigits(value))) {
|
|
218
|
+
return Number(value);
|
|
219
|
+
}
|
|
220
|
+
if (!isString(value)) return void 0;
|
|
221
|
+
try {
|
|
222
|
+
let normalized = fixSingleQuotesEscapeBackslash(value);
|
|
223
|
+
if (validOptions.removeUndefined) {
|
|
224
|
+
normalized = normalized.replace(/,\s*"[^"]*"\s*:\s*undefined(?=\s*[},])/g, "").replace(/"[^"]*"\s*:\s*undefined\s*(,)?/g, "");
|
|
225
|
+
} else {
|
|
226
|
+
normalized = normalized.replace(/:\s*undefined(?=\s*[,}])/g, ":null");
|
|
227
|
+
}
|
|
228
|
+
if (validOptions.convertNaN) {
|
|
229
|
+
normalized = normalized.replace(/:\s*NaN(?=\s*[,}])/g, ':"NaN"');
|
|
230
|
+
} else {
|
|
231
|
+
normalized = normalized.replace(/:\s*NaN(?=\s*[,}])/g, ':"NaN"').replace(/,\s*"[^"]*"\s*:\s*NaN(?=\s*[},])/g, "").replace(/"[^"]*"\s*:\s*NaN\s*(,)?/g, "");
|
|
232
|
+
}
|
|
233
|
+
normalized = normalized.replace(/,(\s*[}\]])/g, "$1");
|
|
234
|
+
const parsed = JSON.parse(normalized);
|
|
235
|
+
return cleanParsedData(parsed, validOptions);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (validOptions.loggingOnFail) {
|
|
238
|
+
console.error("Failed to parsing at `safeJsonParse`:", error);
|
|
239
|
+
}
|
|
240
|
+
validOptions.onError(
|
|
241
|
+
isError(error) ? new Error(error.message.replace(/^JSON\.parse:/, "Failed to parsing")) : new Error(String(error))
|
|
242
|
+
);
|
|
243
|
+
return void 0;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export { cleanParsedData, extractDigits, parseCustomDate, safeJsonParse };
|
package/dist/chunk-2IOOEY45.cjs
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
4
|
+
var normalizeSpaces = (value, options = {
|
|
5
|
+
withTrim: true,
|
|
6
|
+
trimOnly: false
|
|
7
|
+
}) => {
|
|
8
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(value)) return "";
|
|
9
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(options)) {
|
|
10
|
+
options = {};
|
|
11
|
+
}
|
|
12
|
+
const { trimOnly = false, withTrim = true } = options;
|
|
13
|
+
if (trimOnly) return value.trim();
|
|
14
|
+
if (withTrim) {
|
|
15
|
+
value = value.trim();
|
|
16
|
+
}
|
|
17
|
+
return value.replace(/\s+/g, " ");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.normalizeSpaces = normalizeSpaces;
|