@rzl-zone/utils-js 3.4.0 → 3.5.1

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 (118) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +94 -45
  3. package/dist/assertions/index.cjs +41 -1
  4. package/dist/assertions/index.d.ts +11 -2
  5. package/dist/assertions/index.js +14 -1
  6. package/dist/chunk-2CQX5CBG.js +262 -1
  7. package/dist/chunk-2IOOEY45.cjs +30 -1
  8. package/dist/chunk-2WA36TC5.cjs +189 -0
  9. package/dist/chunk-3IBQ5MOM.js +16 -1
  10. package/dist/chunk-3VA554KW.js +34 -1
  11. package/dist/chunk-5757UBXJ.cjs +157 -1
  12. package/dist/chunk-5IGC6PBH.js +33 -1
  13. package/dist/chunk-5KJFVIQT.cjs +65 -1
  14. package/dist/chunk-6JFCSH7J.js +35 -1
  15. package/dist/chunk-6JFZL7YE.cjs +24 -1
  16. package/dist/chunk-7ODAAXX5.cjs +397 -1
  17. package/dist/chunk-BAV5T2E3.cjs +15 -1
  18. package/dist/chunk-CAH33WOQ.cjs +36 -1
  19. package/dist/chunk-CDCERIZ2.js +177 -0
  20. package/dist/chunk-CKTLUNWX.js +22 -1
  21. package/dist/chunk-CMW2TBOQ.js +567 -1
  22. package/dist/chunk-D3ENH7H6.cjs +101 -1
  23. package/dist/chunk-DEZZUYE2.js +152 -1
  24. package/dist/chunk-DVMHRLKP.cjs +16 -1
  25. package/dist/chunk-DWF2R5GD.cjs +225 -1
  26. package/dist/chunk-E55EQK2U.cjs +18 -1
  27. package/dist/chunk-E74U6CYP.cjs +18 -1
  28. package/dist/chunk-EL6A35UR.cjs +64 -1
  29. package/dist/chunk-F6IPNNSJ.cjs +554 -1
  30. package/dist/chunk-FJZGG54N.cjs +267 -1
  31. package/dist/chunk-FWCKOJZM.js +542 -1
  32. package/dist/chunk-FWHNWL2P.cjs +419 -1
  33. package/dist/chunk-GGEADHZO.js +90 -1
  34. package/dist/chunk-GQR4R5WY.js +31 -1
  35. package/dist/chunk-H66AC7GK.cjs +93 -1
  36. package/dist/chunk-HQWOFR56.cjs +33 -1
  37. package/dist/chunk-HYRQMTRH.cjs +24 -1
  38. package/dist/chunk-IRFL4MAX.js +63 -1
  39. package/dist/chunk-IVL7CKVH.cjs +37 -1
  40. package/dist/chunk-IZPBKKPO.js +16 -1
  41. package/dist/chunk-JBQMXC5I.cjs +106 -1
  42. package/dist/chunk-JEQEF5WD.js +95 -1
  43. package/dist/chunk-JMJQCN74.js +370 -1
  44. package/dist/chunk-KHO2SBNA.cjs +16 -1
  45. package/dist/chunk-KVAL5PAG.cjs +26 -1
  46. package/dist/chunk-L5RDAVVH.js +14 -1
  47. package/dist/chunk-LS6U7FAY.cjs +110 -1
  48. package/dist/chunk-NBZWMBO6.js +101 -1
  49. package/dist/chunk-NRF6LWBC.cjs +56 -1
  50. package/dist/chunk-OI5XKNZO.js +53 -1
  51. package/dist/chunk-ONZFBJVW.js +14 -1
  52. package/dist/chunk-OYTYSY7G.js +106 -1
  53. package/dist/chunk-PET42Z7W.js +119 -1
  54. package/dist/chunk-PZQ6I4JJ.cjs +605 -1
  55. package/dist/chunk-QBKAEVYG.js +113 -1
  56. package/dist/chunk-QNKGP5DY.js +14 -1
  57. package/dist/chunk-RIPKY4RU.js +417 -1
  58. package/dist/chunk-RZW35UN5.cjs +116 -1
  59. package/dist/chunk-SBFNXGTJ.js +220 -1
  60. package/dist/chunk-SBKGWRS5.js +22 -1
  61. package/dist/chunk-SIM77PU4.js +59 -1
  62. package/dist/chunk-T2T7K3KR.js +28 -1
  63. package/dist/chunk-T7PU2V7X.cjs +123 -1
  64. package/dist/chunk-UDA26MCU.cjs +16 -1
  65. package/dist/chunk-V45XJKHW.cjs +18 -1
  66. package/dist/chunk-VJDDGRIK.cjs +16 -1
  67. package/dist/chunk-W2WNBUDE.js +16 -1
  68. package/dist/chunk-WVSPXFTY.js +14 -1
  69. package/dist/chunk-XABCB3Y7.cjs +582 -1
  70. package/dist/chunk-XEDXFSGI.js +24 -1
  71. package/dist/chunk-YKPSRP5G.js +571 -1
  72. package/dist/chunk-YWHHVDT4.js +13 -1
  73. package/dist/chunk-ZETAZZLD.cjs +38 -1
  74. package/dist/conversions/index.cjs +104 -1
  75. package/dist/conversions/index.d.ts +10 -1
  76. package/dist/conversions/index.js +25 -1
  77. package/dist/events/index.cjs +32 -1
  78. package/dist/events/index.d.ts +10 -1
  79. package/dist/events/index.js +13 -1
  80. package/dist/formatters/index.cjs +62 -1
  81. package/dist/formatters/index.d.ts +10 -1
  82. package/dist/formatters/index.js +19 -1
  83. package/dist/generators/index.cjs +38 -1
  84. package/dist/generators/index.d.ts +10 -1
  85. package/dist/generators/index.js +15 -1
  86. package/dist/index.d.ts +39 -12
  87. package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +13 -4
  88. package/dist/next/index.cjs +218 -1
  89. package/dist/next/index.d.ts +10 -1
  90. package/dist/next/index.js +213 -1
  91. package/dist/next/server/index.cjs +43 -1
  92. package/dist/next/server/index.d.ts +10 -1
  93. package/dist/next/server/index.js +41 -1
  94. package/dist/operations/index.cjs +33 -1
  95. package/dist/operations/index.d.ts +10 -1
  96. package/dist/operations/index.js +18 -1
  97. package/dist/parsers/index.cjs +18 -1
  98. package/dist/parsers/index.d.ts +10 -1
  99. package/dist/parsers/index.js +11 -1
  100. package/dist/predicates/index.cjs +299 -1
  101. package/dist/predicates/index.d.ts +13 -4
  102. package/dist/predicates/index.js +24 -1
  103. package/dist/promises/index.cjs +25 -1
  104. package/dist/promises/index.d.ts +10 -1
  105. package/dist/promises/index.js +14 -1
  106. package/dist/rzl-utils.global.js +25 -1
  107. package/dist/strings/index.cjs +82 -1
  108. package/dist/strings/index.d.ts +10 -1
  109. package/dist/strings/index.js +15 -1
  110. package/dist/tailwind/index.cjs +43 -1
  111. package/dist/tailwind/index.d.ts +10 -1
  112. package/dist/tailwind/index.js +12 -1
  113. package/dist/urls/index.cjs +51 -1
  114. package/dist/urls/index.d.ts +10 -1
  115. package/dist/urls/index.js +24 -1
  116. package/package.json +60 -179
  117. package/dist/chunk-JYQTCICM.js +0 -1
  118. package/dist/chunk-YLA3DURS.cjs +0 -1
@@ -1 +1,56 @@
1
- "use strict";var e=require("./chunk-V45XJKHW.cjs"),r=require("./chunk-ZETAZZLD.cjs"),i=require("./chunk-UDA26MCU.cjs"),s=require("./chunk-PZQ6I4JJ.cjs");function t(e){if(s.isNil(e))return;if(!s.isArray(e))return[];return e.reduce((e,i)=>{if(!s.isNil(i))if(s.isArray(i)){const s=t(i);s&&!r.isEmptyArray(s)&&e.push(s)}else e.push(i);return e},[])}exports.filterNilArray=t,exports.toStringArrayUnRecursive=function(r,n={}){s.assertIsPlainObject(n,{message:({currentType:e,validType:r})=>`Second parameter (\`options\`) must be of type \`${r}\`, but received: \`${e}\`.`});const u=!s.hasOwnProp(n,"removeInvalidValue")||n.removeInvalidValue;if(s.assertIsBoolean(u,{message:({currentType:e,validType:r})=>`Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${r}\`, but received: \`${e}\`.`}),s.isArray(r)){const n=Array.from(r,r=>s.isString(r)||e.isFinite(r)||s.isBoolean(r)||i.isBigInt(r)?String(r):s.isNull(r)?null:void 0);return u?t(n):n}};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ 'use strict';
11
+
12
+ var chunkV45XJKHW_cjs = require('./chunk-V45XJKHW.cjs');
13
+ var chunkZETAZZLD_cjs = require('./chunk-ZETAZZLD.cjs');
14
+ var chunkUDA26MCU_cjs = require('./chunk-UDA26MCU.cjs');
15
+ var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
16
+
17
+ function filterNilArray(input) {
18
+ if (chunkPZQ6I4JJ_cjs.isNil(input)) return void 0;
19
+ if (!chunkPZQ6I4JJ_cjs.isArray(input)) return [];
20
+ const filtered = input.reduce((output, element) => {
21
+ if (!chunkPZQ6I4JJ_cjs.isNil(element)) {
22
+ if (chunkPZQ6I4JJ_cjs.isArray(element)) {
23
+ const cleanedNested = filterNilArray(element);
24
+ if (cleanedNested && !chunkZETAZZLD_cjs.isEmptyArray(cleanedNested)) {
25
+ output.push(cleanedNested);
26
+ }
27
+ } else {
28
+ output.push(element);
29
+ }
30
+ }
31
+ return output;
32
+ }, []);
33
+ return filtered;
34
+ }
35
+
36
+ function toStringArrayUnRecursive(array, options = {}) {
37
+ chunkPZQ6I4JJ_cjs.assertIsPlainObject(options, {
38
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
39
+ });
40
+ const riv = chunkPZQ6I4JJ_cjs.hasOwnProp(options, "removeInvalidValue") ? options.removeInvalidValue : true;
41
+ chunkPZQ6I4JJ_cjs.assertIsBoolean(riv, {
42
+ message: ({ currentType, validType }) => `Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
43
+ });
44
+ if (chunkPZQ6I4JJ_cjs.isArray(array)) {
45
+ const result = Array.from(array, (x) => {
46
+ if (chunkPZQ6I4JJ_cjs.isString(x) || chunkV45XJKHW_cjs.isFinite(x) || chunkPZQ6I4JJ_cjs.isBoolean(x) || chunkUDA26MCU_cjs.isBigInt(x)) return String(x);
47
+ return chunkPZQ6I4JJ_cjs.isNull(x) ? null : void 0;
48
+ });
49
+ if (riv) return filterNilArray(result);
50
+ return result;
51
+ }
52
+ return void 0;
53
+ }
54
+
55
+ exports.filterNilArray = filterNilArray;
56
+ exports.toStringArrayUnRecursive = toStringArrayUnRecursive;
@@ -1 +1,53 @@
1
- import{isFinite as e}from"./chunk-3IBQ5MOM.js";import{isEmptyArray as r}from"./chunk-6JFCSH7J.js";import{isBigInt as t}from"./chunk-QNKGP5DY.js";import{isNil as o,isArray as n,assertIsPlainObject as u,hasOwnProp as i,assertIsBoolean as m,isString as p,isBoolean as s,isNull as a}from"./chunk-CMW2TBOQ.js";function c(e){if(o(e))return;if(!n(e))return[];return e.reduce((e,t)=>{if(!o(t))if(n(t)){const o=c(t);o&&!r(o)&&e.push(o)}else e.push(t);return e},[])}function f(r,o={}){u(o,{message:({currentType:e,validType:r})=>`Second parameter (\`options\`) must be of type \`${r}\`, but received: \`${e}\`.`});const f=!i(o,"removeInvalidValue")||o.removeInvalidValue;if(m(f,{message:({currentType:e,validType:r})=>`Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${r}\`, but received: \`${e}\`.`}),n(r)){const o=Array.from(r,r=>p(r)||e(r)||s(r)||t(r)?String(r):a(r)?null:void 0);return f?c(o):o}}export{c as filterNilArray,f as toStringArrayUnRecursive};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ import { isFinite } from './chunk-3IBQ5MOM.js';
11
+ import { isEmptyArray } from './chunk-6JFCSH7J.js';
12
+ import { isBigInt } from './chunk-QNKGP5DY.js';
13
+ import { isNil, isArray, assertIsPlainObject, hasOwnProp, assertIsBoolean, isString, isBoolean, isNull } from './chunk-CMW2TBOQ.js';
14
+
15
+ function filterNilArray(input) {
16
+ if (isNil(input)) return void 0;
17
+ if (!isArray(input)) return [];
18
+ const filtered = input.reduce((output, element) => {
19
+ if (!isNil(element)) {
20
+ if (isArray(element)) {
21
+ const cleanedNested = filterNilArray(element);
22
+ if (cleanedNested && !isEmptyArray(cleanedNested)) {
23
+ output.push(cleanedNested);
24
+ }
25
+ } else {
26
+ output.push(element);
27
+ }
28
+ }
29
+ return output;
30
+ }, []);
31
+ return filtered;
32
+ }
33
+
34
+ function toStringArrayUnRecursive(array, options = {}) {
35
+ assertIsPlainObject(options, {
36
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
37
+ });
38
+ const riv = hasOwnProp(options, "removeInvalidValue") ? options.removeInvalidValue : true;
39
+ assertIsBoolean(riv, {
40
+ message: ({ currentType, validType }) => `Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
41
+ });
42
+ if (isArray(array)) {
43
+ const result = Array.from(array, (x) => {
44
+ if (isString(x) || isFinite(x) || isBoolean(x) || isBigInt(x)) return String(x);
45
+ return isNull(x) ? null : void 0;
46
+ });
47
+ if (riv) return filterNilArray(result);
48
+ return result;
49
+ }
50
+ return void 0;
51
+ }
52
+
53
+ export { filterNilArray, toStringArrayUnRecursive };
@@ -1 +1,14 @@
1
- var a=a=>a instanceof URL;export{a as isURL};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ var isURL = (value) => {
11
+ return value instanceof URL;
12
+ };
13
+
14
+ export { isURL };
@@ -1 +1,106 @@
1
- import{safeJsonParse as e}from"./chunk-2CQX5CBG.js";import{isEqual as r}from"./chunk-NBZWMBO6.js";import{isEmptyArray as t}from"./chunk-6JFCSH7J.js";import{assertIsArray as n}from"./chunk-CKTLUNWX.js";import{safeStableStringify as o}from"./chunk-PET42Z7W.js";import{isPlainObject as s,isNonEmptyArray as i,isObjectOrArray as c,isArray as a,isNaN as u,isUndefined as m}from"./chunk-CMW2TBOQ.js";var f=e=>{n(e,{message:({currentType:e,validType:r})=>`First parameter (\`values\`) must be of type \`${r}\` (array literal or instance), but received: \`${e}\`.`});const t=[];return e.forEach((n,o)=>{for(let s=o+1;s<e.length;s++)if(r(n,e[s])){t.some(e=>r(e,n))||t.push(n);break}}),t},p=(e,r)=>{if(!s(e))return{};n(r,{message:({currentType:e,validType:r})=>`Second parameter (\`keysToOmit\`) must be of type \`${r}\` (array literal or instance), but received: \`${e}\`.`});const t=f(r);if(t.length>0)throw new Error(`Function "omitKeys" Error: Duplicate keys detected - \`${t}\``);return Object.fromEntries(Object.entries(e).filter(([e])=>!r.includes(e)))},l=(r,p)=>{if(!s(r))return{};n(p,{message:({currentType:e,validType:r})=>`Second parameter (\`keysToOmit\`) must be of type \`${r}\` (array literal or instance), but received: \`${e}\`.`});const l=f(p);if(i(l))throw new Error(`Function "omitKeysDeep" Error: Duplicate keys detected - \`${o(l)}\`.`);const y=(e,r)=>{if(!c(e))return e;const[n,...o]=r;if(t(o))if(a(e)){const r=parseInt(n);!u(r)&&r in e&&e.splice(r,1)}else delete e[n];else{const r=e[n];c(r)&&(e[n]=y(r,o))}return e},d=e=>{if(a(e))return e.map(d).filter(e=>!(c(e)&&0===Object.keys(e).length));if(c(e)){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,d(r)]).filter(([,e])=>!(m(e)||c(e)&&0===Object.keys(e).length)))}return e},h=e(o(r));for(const e of p){const r=e.split(".");y(h,r)}return d(h)};export{f as findDuplicates,p as omitKeys,l as omitKeysDeep};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ import { safeJsonParse } from './chunk-2CQX5CBG.js';
11
+ import { isEqual } from './chunk-NBZWMBO6.js';
12
+ import { isEmptyArray } from './chunk-6JFCSH7J.js';
13
+ import { assertIsArray } from './chunk-CKTLUNWX.js';
14
+ import { safeStableStringify } from './chunk-PET42Z7W.js';
15
+ import { isPlainObject, isNonEmptyArray, isObjectOrArray, isArray, isNaN, isUndefined } from './chunk-CMW2TBOQ.js';
16
+
17
+ var findDuplicates = (values) => {
18
+ assertIsArray(values, {
19
+ message: ({ currentType, validType }) => `First parameter (\`values\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
20
+ });
21
+ const duplicates = [];
22
+ values.forEach((item, index) => {
23
+ for (let i = index + 1; i < values.length; i++) {
24
+ if (isEqual(item, values[i])) {
25
+ if (!duplicates.some((dup) => isEqual(dup, item))) {
26
+ duplicates.push(item);
27
+ }
28
+ break;
29
+ }
30
+ }
31
+ });
32
+ return duplicates;
33
+ };
34
+
35
+ var omitKeys = (object, keysToOmit) => {
36
+ if (!isPlainObject(object)) return {};
37
+ assertIsArray(keysToOmit, {
38
+ message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
39
+ });
40
+ const duplicates = findDuplicates(keysToOmit);
41
+ if (duplicates.length > 0) {
42
+ throw new Error(
43
+ `Function "omitKeys" Error: Duplicate keys detected - \`${duplicates}\``
44
+ );
45
+ }
46
+ return Object.fromEntries(
47
+ Object.entries(object).filter(([key]) => !keysToOmit.includes(key))
48
+ );
49
+ };
50
+
51
+ var omitKeysDeep = (object, keysToOmit) => {
52
+ if (!isPlainObject(object)) return {};
53
+ assertIsArray(keysToOmit, {
54
+ message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
55
+ });
56
+ const duplicates = findDuplicates(keysToOmit);
57
+ if (isNonEmptyArray(duplicates)) {
58
+ throw new Error(
59
+ `Function "omitKeysDeep" Error: Duplicate keys detected - \`${safeStableStringify(
60
+ duplicates
61
+ )}\`.`
62
+ );
63
+ }
64
+ const omitAtPath = (obj, pathParts) => {
65
+ if (!isObjectOrArray(obj)) return obj;
66
+ const [current, ...rest] = pathParts;
67
+ if (isEmptyArray(rest)) {
68
+ if (isArray(obj)) {
69
+ const index = parseInt(current);
70
+ if (!isNaN(index) && index in obj) {
71
+ obj.splice(index, 1);
72
+ }
73
+ } else {
74
+ delete obj[current];
75
+ }
76
+ } else {
77
+ const next = obj[current];
78
+ if (isObjectOrArray(next)) {
79
+ obj[current] = omitAtPath(next, rest);
80
+ }
81
+ }
82
+ return obj;
83
+ };
84
+ const deepRemoveEmptyObjects = (obj) => {
85
+ if (isArray(obj)) {
86
+ return obj.map(deepRemoveEmptyObjects).filter((item) => !(isObjectOrArray(item) && Object.keys(item).length === 0));
87
+ }
88
+ if (isObjectOrArray(obj)) {
89
+ const cleaned = Object.fromEntries(
90
+ Object.entries(obj).map(([k, v]) => [k, deepRemoveEmptyObjects(v)]).filter(
91
+ ([, v]) => !isUndefined(v) && !(isObjectOrArray(v) && Object.keys(v).length === 0)
92
+ )
93
+ );
94
+ return cleaned;
95
+ }
96
+ return obj;
97
+ };
98
+ const result = safeJsonParse(safeStableStringify(object));
99
+ for (const key of keysToOmit) {
100
+ const parts = key.split(".");
101
+ omitAtPath(result, parts);
102
+ }
103
+ return deepRemoveEmptyObjects(result);
104
+ };
105
+
106
+ export { findDuplicates, omitKeys, omitKeysDeep };
@@ -1 +1,119 @@
1
- import{isBigInt as e}from"./chunk-QNKGP5DY.js";import{assertIsPlainObject as r,isPlainObject as t,isBoolean as n,isNaN as o,hasOwnProp as s,getPreciseType as i,isUndefined as a,isNumberObject as u,isInfinityNumber as f,isStringObject as p,isBooleanObject as c,isFunction as l,isSymbol as y,isObjectOrArray as d,isSet as m,isArray as b,isNull as v,isNumber as S,isObject as g}from"./chunk-CMW2TBOQ.js";function k(e){return"[object Map]"===Object.prototype.toString.call(e)||e instanceof Map}var h=(e,s={})=>{r(s,{message:({currentType:e,validType:r})=>`Second parameter (\`options\`) must be of type \`${r}\`, but received: \`${e}\`.`});const i=!(!t(s)||!n(s.skipInvalidDate))&&s.skipInvalidDate,a=e instanceof Date;return i?a:a&&!o(e.getTime())},O=(t,O={})=>{r(O,{message:({currentType:e,validType:r})=>`Second parameter (\`options\`) must be of type \`${r}\`, but received: \`${e}\`.`});const $=!!s(O,"pretty")&&O.pretty,T=!s(O,"sortKeys")||O.sortKeys,A=!!s(O,"sortArray")&&O.sortArray,j=!!s(O,"keepUndefined")&&O.keepUndefined;if(!(n(T)&&n(A)&&n($)&&n(j)))throw new TypeError(`Parameters \`sortKeys\`, \`sortArray\`, \`keepUndefined\` and \`pretty\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: "['sortKeys': \`${i(T)}\`, 'sortArray': \`${i(A)}\`, 'keepUndefined': \`${i(j)}\`, 'pretty': \`${i($)}\`]".`);if(a(t))return j?"undefined":"null";const K=new WeakSet,w=e=>v(e)||!d(e)&&!l(e),C=r=>{if(u(r)){const e=r.valueOf();return o(e)||f(e)?null:e}if(p(r))return r.valueOf();if(c(r))return r.valueOf();if(!l(r)&&!y(r)){if(e(r))return r.toString();if(o(r)||f(r))return null;if(a(r))return j?void 0:null;if(d(r)){if(K.has(r))return"[Circular]";if(K.add(r),h(r))return r.toISOString();if(k(r))return{map:Array.from(r.entries()).map(([e,r])=>[e,C(r)])};if(m(r))return{set:Array.from(r.values()).map(C)};if(b(r)){const e=r.map(C);if(A){const r=[],t=[];for(const n of e)w(n)?r.push(n):t.push(n);return r.sort((e,r)=>S(e)&&S(r)?e-r:String(e).localeCompare(String(r))),[...r,...t]}return e}const e=Object.keys(r);T&&e.sort((e,r)=>{const t=Number(e),n=Number(r);return o(t)||o(n)?e.localeCompare(r):t-n});const t={};if(g(r))for(const n of e){const e=C(r[n]);a(e)||(t[n]=e)}return t}return r}};try{return JSON.stringify(C(t),null,$?2:0)}catch(e){return console.warn("Error in safeStableStringify:",e),"{}"}};export{h as isDate,k as isMap,O as safeStableStringify};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ import { isBigInt } from './chunk-QNKGP5DY.js';
11
+ import { assertIsPlainObject, isPlainObject, isBoolean, isNaN, hasOwnProp, getPreciseType, isUndefined, isNumberObject, isInfinityNumber, isStringObject, isBooleanObject, isFunction, isSymbol, isObjectOrArray, isSet, isArray, isNull, isNumber, isObject } from './chunk-CMW2TBOQ.js';
12
+
13
+ function isMap(value) {
14
+ return Object.prototype.toString.call(value) === "[object Map]" || value instanceof Map;
15
+ }
16
+
17
+ var isDate = (value, options = {}) => {
18
+ assertIsPlainObject(options, {
19
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
20
+ });
21
+ const skipInvalidDate = isPlainObject(options) && isBoolean(options.skipInvalidDate) ? options.skipInvalidDate : false;
22
+ const instanceDate = value instanceof Date;
23
+ if (skipInvalidDate) return instanceDate;
24
+ return instanceDate && !isNaN(value.getTime());
25
+ };
26
+
27
+ var safeStableStringify = (value, options = {}) => {
28
+ assertIsPlainObject(options, {
29
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
30
+ });
31
+ const pretty = hasOwnProp(options, "pretty") ? options.pretty : false;
32
+ const sortKeys = hasOwnProp(options, "sortKeys") ? options.sortKeys : true;
33
+ const sortArray = hasOwnProp(options, "sortArray") ? options.sortArray : false;
34
+ const keepUndefined = hasOwnProp(options, "keepUndefined") ? options.keepUndefined : false;
35
+ if (!isBoolean(sortKeys) || !isBoolean(sortArray) || !isBoolean(pretty) || !isBoolean(keepUndefined)) {
36
+ throw new TypeError(
37
+ `Parameters \`sortKeys\`, \`sortArray\`, \`keepUndefined\` and \`pretty\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: "['sortKeys': \`${getPreciseType(
38
+ sortKeys
39
+ )}\`, 'sortArray': \`${getPreciseType(
40
+ sortArray
41
+ )}\`, 'keepUndefined': \`${getPreciseType(
42
+ keepUndefined
43
+ )}\`, 'pretty': \`${getPreciseType(pretty)}\`]".`
44
+ );
45
+ }
46
+ if (isUndefined(value)) {
47
+ return keepUndefined ? "undefined" : "null";
48
+ }
49
+ const seen = /* @__PURE__ */ new WeakSet();
50
+ const isPrimitive = (val) => isNull(val) || !isObjectOrArray(val) && !isFunction(val);
51
+ const deepProcess = (val) => {
52
+ if (isNumberObject(val)) {
53
+ const valOf = val.valueOf();
54
+ return isNaN(valOf) || isInfinityNumber(valOf) ? null : valOf;
55
+ }
56
+ if (isStringObject(val)) return val.valueOf();
57
+ if (isBooleanObject(val)) return val.valueOf();
58
+ if (isFunction(val) || isSymbol(val)) return void 0;
59
+ if (isBigInt(val)) return val.toString();
60
+ if (isNaN(val) || isInfinityNumber(val)) return null;
61
+ if (isUndefined(val)) {
62
+ return keepUndefined ? void 0 : null;
63
+ }
64
+ if (isObjectOrArray(val)) {
65
+ if (seen.has(val)) return "[Circular]";
66
+ seen.add(val);
67
+ if (isDate(val)) return val.toISOString();
68
+ if (isMap(val)) {
69
+ return {
70
+ map: Array.from(val.entries()).map(([k, v]) => [k, deepProcess(v)])
71
+ };
72
+ }
73
+ if (isSet(val)) return { set: Array.from(val.values()).map(deepProcess) };
74
+ if (isArray(val)) {
75
+ const processedArr = val.map(deepProcess);
76
+ if (sortArray) {
77
+ const primitives = [];
78
+ const nonPrimitives = [];
79
+ for (const item of processedArr) {
80
+ if (isPrimitive(item)) primitives.push(item);
81
+ else nonPrimitives.push(item);
82
+ }
83
+ primitives.sort((a, b) => {
84
+ if (isNumber(a) && isNumber(b)) return a - b;
85
+ return String(a).localeCompare(String(b));
86
+ });
87
+ return [...primitives, ...nonPrimitives];
88
+ }
89
+ return processedArr;
90
+ }
91
+ const keys = Object.keys(val);
92
+ if (sortKeys) {
93
+ keys.sort((a, b) => {
94
+ const na = Number(a);
95
+ const nb = Number(b);
96
+ if (!isNaN(na) && !isNaN(nb)) return na - nb;
97
+ return a.localeCompare(b);
98
+ });
99
+ }
100
+ const result = {};
101
+ if (isObject(val)) {
102
+ for (const k of keys) {
103
+ const v = deepProcess(val[k]);
104
+ if (!isUndefined(v)) result[k] = v;
105
+ }
106
+ }
107
+ return result;
108
+ }
109
+ return val;
110
+ };
111
+ try {
112
+ return JSON.stringify(deepProcess(value), null, pretty ? 2 : 0);
113
+ } catch (err) {
114
+ console.warn("Error in safeStableStringify:", err);
115
+ return "{}";
116
+ }
117
+ };
118
+
119
+ export { isDate, isMap, safeStableStringify };