@rzl-zone/utils-js 3.4.0 → 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.
Files changed (117) hide show
  1. package/README.md +94 -45
  2. package/dist/assertions/index.cjs +34 -1
  3. package/dist/assertions/index.d.ts +2 -2
  4. package/dist/assertions/index.js +5 -1
  5. package/dist/chunk-2CQX5CBG.js +247 -1
  6. package/dist/chunk-2IOOEY45.cjs +20 -1
  7. package/dist/chunk-2WA36TC5.cjs +176 -0
  8. package/dist/chunk-3IBQ5MOM.js +6 -1
  9. package/dist/chunk-3VA554KW.js +23 -1
  10. package/dist/chunk-5757UBXJ.cjs +144 -1
  11. package/dist/chunk-5IGC6PBH.js +22 -1
  12. package/dist/chunk-5KJFVIQT.cjs +55 -1
  13. package/dist/chunk-6JFCSH7J.js +24 -1
  14. package/dist/chunk-6JFZL7YE.cjs +14 -1
  15. package/dist/chunk-7ODAAXX5.cjs +361 -1
  16. package/dist/chunk-BAV5T2E3.cjs +5 -1
  17. package/dist/chunk-CAH33WOQ.cjs +25 -1
  18. package/dist/chunk-CDCERIZ2.js +164 -0
  19. package/dist/chunk-CKTLUNWX.js +12 -1
  20. package/dist/chunk-CMW2TBOQ.js +522 -1
  21. package/dist/chunk-D3ENH7H6.cjs +87 -1
  22. package/dist/chunk-DEZZUYE2.js +139 -1
  23. package/dist/chunk-DVMHRLKP.cjs +6 -1
  24. package/dist/chunk-DWF2R5GD.cjs +212 -1
  25. package/dist/chunk-E55EQK2U.cjs +8 -1
  26. package/dist/chunk-E74U6CYP.cjs +8 -1
  27. package/dist/chunk-EL6A35UR.cjs +51 -1
  28. package/dist/chunk-F6IPNNSJ.cjs +531 -1
  29. package/dist/chunk-FJZGG54N.cjs +252 -1
  30. package/dist/chunk-FWCKOJZM.js +519 -1
  31. package/dist/chunk-FWHNWL2P.cjs +409 -1
  32. package/dist/chunk-GGEADHZO.js +78 -1
  33. package/dist/chunk-GQR4R5WY.js +21 -1
  34. package/dist/chunk-H66AC7GK.cjs +81 -1
  35. package/dist/chunk-HQWOFR56.cjs +23 -1
  36. package/dist/chunk-HYRQMTRH.cjs +14 -1
  37. package/dist/chunk-IRFL4MAX.js +53 -1
  38. package/dist/chunk-IVL7CKVH.cjs +26 -1
  39. package/dist/chunk-IZPBKKPO.js +6 -1
  40. package/dist/chunk-JBQMXC5I.cjs +93 -1
  41. package/dist/chunk-JEQEF5WD.js +81 -1
  42. package/dist/chunk-JMJQCN74.js +334 -1
  43. package/dist/chunk-KHO2SBNA.cjs +6 -1
  44. package/dist/chunk-KVAL5PAG.cjs +16 -1
  45. package/dist/chunk-L5RDAVVH.js +5 -1
  46. package/dist/chunk-LS6U7FAY.cjs +98 -1
  47. package/dist/chunk-NBZWMBO6.js +88 -1
  48. package/dist/chunk-NRF6LWBC.cjs +45 -1
  49. package/dist/chunk-OI5XKNZO.js +42 -1
  50. package/dist/chunk-ONZFBJVW.js +5 -1
  51. package/dist/chunk-OYTYSY7G.js +94 -1
  52. package/dist/chunk-PET42Z7W.js +107 -1
  53. package/dist/chunk-PZQ6I4JJ.cjs +559 -1
  54. package/dist/chunk-QBKAEVYG.js +102 -1
  55. package/dist/chunk-QNKGP5DY.js +5 -1
  56. package/dist/chunk-RIPKY4RU.js +407 -1
  57. package/dist/chunk-RZW35UN5.cjs +105 -1
  58. package/dist/chunk-SBFNXGTJ.js +207 -1
  59. package/dist/chunk-SBKGWRS5.js +12 -1
  60. package/dist/chunk-SIM77PU4.js +46 -1
  61. package/dist/chunk-T2T7K3KR.js +18 -1
  62. package/dist/chunk-T7PU2V7X.cjs +111 -1
  63. package/dist/chunk-UDA26MCU.cjs +6 -1
  64. package/dist/chunk-V45XJKHW.cjs +8 -1
  65. package/dist/chunk-VJDDGRIK.cjs +6 -1
  66. package/dist/chunk-W2WNBUDE.js +6 -1
  67. package/dist/chunk-WVSPXFTY.js +5 -1
  68. package/dist/chunk-XABCB3Y7.cjs +563 -1
  69. package/dist/chunk-XEDXFSGI.js +14 -1
  70. package/dist/chunk-YKPSRP5G.js +552 -1
  71. package/dist/chunk-YWHHVDT4.js +4 -1
  72. package/dist/chunk-ZETAZZLD.cjs +27 -1
  73. package/dist/conversions/index.cjs +97 -1
  74. package/dist/conversions/index.d.ts +1 -1
  75. package/dist/conversions/index.js +16 -1
  76. package/dist/events/index.cjs +25 -1
  77. package/dist/events/index.d.ts +1 -1
  78. package/dist/events/index.js +4 -1
  79. package/dist/formatters/index.cjs +55 -1
  80. package/dist/formatters/index.d.ts +1 -1
  81. package/dist/formatters/index.js +10 -1
  82. package/dist/generators/index.cjs +31 -1
  83. package/dist/generators/index.d.ts +1 -1
  84. package/dist/generators/index.js +6 -1
  85. package/dist/index.d.ts +1 -0
  86. package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +4 -4
  87. package/dist/next/index.cjs +205 -1
  88. package/dist/next/index.d.ts +1 -1
  89. package/dist/next/index.js +200 -1
  90. package/dist/next/server/index.cjs +34 -1
  91. package/dist/next/server/index.d.ts +1 -1
  92. package/dist/next/server/index.js +32 -1
  93. package/dist/operations/index.cjs +26 -1
  94. package/dist/operations/index.d.ts +1 -1
  95. package/dist/operations/index.js +9 -1
  96. package/dist/parsers/index.cjs +11 -1
  97. package/dist/parsers/index.d.ts +1 -1
  98. package/dist/parsers/index.js +2 -1
  99. package/dist/predicates/index.cjs +292 -1
  100. package/dist/predicates/index.d.ts +4 -4
  101. package/dist/predicates/index.js +15 -1
  102. package/dist/promises/index.cjs +18 -1
  103. package/dist/promises/index.d.ts +1 -1
  104. package/dist/promises/index.js +5 -1
  105. package/dist/rzl-utils.global.js +16 -1
  106. package/dist/strings/index.cjs +75 -1
  107. package/dist/strings/index.d.ts +1 -1
  108. package/dist/strings/index.js +6 -1
  109. package/dist/tailwind/index.cjs +36 -1
  110. package/dist/tailwind/index.d.ts +1 -1
  111. package/dist/tailwind/index.js +3 -1
  112. package/dist/urls/index.cjs +44 -1
  113. package/dist/urls/index.d.ts +1 -1
  114. package/dist/urls/index.js +15 -1
  115. package/package.json +16 -19
  116. package/dist/chunk-JYQTCICM.js +0 -1
  117. package/dist/chunk-YLA3DURS.cjs +0 -1
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 including TypeScript package **`@rzl-zone/ts-types-plus`** 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/ts-types-plus";
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
- #### # **_JavaScript_:**
173
- Add this to your `jsconfig.json`:
174
- ```jsonc
175
- // jsconfig.json
176
- {
177
- "compilerOptions": {
178
- "types": [
179
- "@rzl-zone/utils-js"
180
- ]
181
- }
182
- }
183
- ```
184
- >ℹ️ ***Tip:*** *For JS projects, consider adding "checkJs": true for better IntelliSense.*
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/ts-types-plus";
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
- "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
+ '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{Prettify,PickStrict}from'@rzl-zone/ts-types-plus';import{G as GetPreciseTypeOptions,I as IsNumberOptions,a as IsPlainObjectResult}from'../isPlainObject-CEPWPiXh.js';
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};
@@ -1 +1,5 @@
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";
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';
@@ -1 +1,247 @@
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};
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 };
@@ -1 +1,20 @@
1
- "use strict";var r=require("./chunk-PZQ6I4JJ.cjs");exports.normalizeSpaces=(i,t={withTrim:!0,trimOnly:!1})=>{if(!r.isNonEmptyString(i))return"";r.isPlainObject(t)||(t={});const{trimOnly:e=!1,withTrim:n=!0}=t;return e?i.trim():(n&&(i=i.trim()),i.replace(/\s+/g," "))};
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;