@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.
- package/LICENSE.md +1 -1
- package/README.md +94 -45
- package/dist/assertions/index.cjs +41 -1
- package/dist/assertions/index.d.ts +11 -2
- package/dist/assertions/index.js +14 -1
- package/dist/chunk-2CQX5CBG.js +262 -1
- package/dist/chunk-2IOOEY45.cjs +30 -1
- package/dist/chunk-2WA36TC5.cjs +189 -0
- package/dist/chunk-3IBQ5MOM.js +16 -1
- package/dist/chunk-3VA554KW.js +34 -1
- package/dist/chunk-5757UBXJ.cjs +157 -1
- package/dist/chunk-5IGC6PBH.js +33 -1
- package/dist/chunk-5KJFVIQT.cjs +65 -1
- package/dist/chunk-6JFCSH7J.js +35 -1
- package/dist/chunk-6JFZL7YE.cjs +24 -1
- package/dist/chunk-7ODAAXX5.cjs +397 -1
- package/dist/chunk-BAV5T2E3.cjs +15 -1
- package/dist/chunk-CAH33WOQ.cjs +36 -1
- package/dist/chunk-CDCERIZ2.js +177 -0
- package/dist/chunk-CKTLUNWX.js +22 -1
- package/dist/chunk-CMW2TBOQ.js +567 -1
- package/dist/chunk-D3ENH7H6.cjs +101 -1
- package/dist/chunk-DEZZUYE2.js +152 -1
- package/dist/chunk-DVMHRLKP.cjs +16 -1
- package/dist/chunk-DWF2R5GD.cjs +225 -1
- package/dist/chunk-E55EQK2U.cjs +18 -1
- package/dist/chunk-E74U6CYP.cjs +18 -1
- package/dist/chunk-EL6A35UR.cjs +64 -1
- package/dist/chunk-F6IPNNSJ.cjs +554 -1
- package/dist/chunk-FJZGG54N.cjs +267 -1
- package/dist/chunk-FWCKOJZM.js +542 -1
- package/dist/chunk-FWHNWL2P.cjs +419 -1
- package/dist/chunk-GGEADHZO.js +90 -1
- package/dist/chunk-GQR4R5WY.js +31 -1
- package/dist/chunk-H66AC7GK.cjs +93 -1
- package/dist/chunk-HQWOFR56.cjs +33 -1
- package/dist/chunk-HYRQMTRH.cjs +24 -1
- package/dist/chunk-IRFL4MAX.js +63 -1
- package/dist/chunk-IVL7CKVH.cjs +37 -1
- package/dist/chunk-IZPBKKPO.js +16 -1
- package/dist/chunk-JBQMXC5I.cjs +106 -1
- package/dist/chunk-JEQEF5WD.js +95 -1
- package/dist/chunk-JMJQCN74.js +370 -1
- package/dist/chunk-KHO2SBNA.cjs +16 -1
- package/dist/chunk-KVAL5PAG.cjs +26 -1
- package/dist/chunk-L5RDAVVH.js +14 -1
- package/dist/chunk-LS6U7FAY.cjs +110 -1
- package/dist/chunk-NBZWMBO6.js +101 -1
- package/dist/chunk-NRF6LWBC.cjs +56 -1
- package/dist/chunk-OI5XKNZO.js +53 -1
- package/dist/chunk-ONZFBJVW.js +14 -1
- package/dist/chunk-OYTYSY7G.js +106 -1
- package/dist/chunk-PET42Z7W.js +119 -1
- package/dist/chunk-PZQ6I4JJ.cjs +605 -1
- package/dist/chunk-QBKAEVYG.js +113 -1
- package/dist/chunk-QNKGP5DY.js +14 -1
- package/dist/chunk-RIPKY4RU.js +417 -1
- package/dist/chunk-RZW35UN5.cjs +116 -1
- package/dist/chunk-SBFNXGTJ.js +220 -1
- package/dist/chunk-SBKGWRS5.js +22 -1
- package/dist/chunk-SIM77PU4.js +59 -1
- package/dist/chunk-T2T7K3KR.js +28 -1
- package/dist/chunk-T7PU2V7X.cjs +123 -1
- package/dist/chunk-UDA26MCU.cjs +16 -1
- package/dist/chunk-V45XJKHW.cjs +18 -1
- package/dist/chunk-VJDDGRIK.cjs +16 -1
- package/dist/chunk-W2WNBUDE.js +16 -1
- package/dist/chunk-WVSPXFTY.js +14 -1
- package/dist/chunk-XABCB3Y7.cjs +582 -1
- package/dist/chunk-XEDXFSGI.js +24 -1
- package/dist/chunk-YKPSRP5G.js +571 -1
- package/dist/chunk-YWHHVDT4.js +13 -1
- package/dist/chunk-ZETAZZLD.cjs +38 -1
- package/dist/conversions/index.cjs +104 -1
- package/dist/conversions/index.d.ts +10 -1
- package/dist/conversions/index.js +25 -1
- package/dist/events/index.cjs +32 -1
- package/dist/events/index.d.ts +10 -1
- package/dist/events/index.js +13 -1
- package/dist/formatters/index.cjs +62 -1
- package/dist/formatters/index.d.ts +10 -1
- package/dist/formatters/index.js +19 -1
- package/dist/generators/index.cjs +38 -1
- package/dist/generators/index.d.ts +10 -1
- package/dist/generators/index.js +15 -1
- package/dist/index.d.ts +39 -12
- package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +13 -4
- package/dist/next/index.cjs +218 -1
- package/dist/next/index.d.ts +10 -1
- package/dist/next/index.js +213 -1
- package/dist/next/server/index.cjs +43 -1
- package/dist/next/server/index.d.ts +10 -1
- package/dist/next/server/index.js +41 -1
- package/dist/operations/index.cjs +33 -1
- package/dist/operations/index.d.ts +10 -1
- package/dist/operations/index.js +18 -1
- package/dist/parsers/index.cjs +18 -1
- package/dist/parsers/index.d.ts +10 -1
- package/dist/parsers/index.js +11 -1
- package/dist/predicates/index.cjs +299 -1
- package/dist/predicates/index.d.ts +13 -4
- package/dist/predicates/index.js +24 -1
- package/dist/promises/index.cjs +25 -1
- package/dist/promises/index.d.ts +10 -1
- package/dist/promises/index.js +14 -1
- package/dist/rzl-utils.global.js +25 -1
- package/dist/strings/index.cjs +82 -1
- package/dist/strings/index.d.ts +10 -1
- package/dist/strings/index.js +15 -1
- package/dist/tailwind/index.cjs +43 -1
- package/dist/tailwind/index.d.ts +10 -1
- package/dist/tailwind/index.js +12 -1
- package/dist/urls/index.cjs +51 -1
- package/dist/urls/index.d.ts +10 -1
- package/dist/urls/index.js +24 -1
- package/package.json +60 -179
- package/dist/chunk-JYQTCICM.js +0 -1
- package/dist/chunk-YLA3DURS.cjs +0 -1
package/dist/chunk-NRF6LWBC.cjs
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
|
|
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;
|
package/dist/chunk-OI5XKNZO.js
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
|
-
|
|
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 };
|
package/dist/chunk-ONZFBJVW.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
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 };
|
package/dist/chunk-OYTYSY7G.js
CHANGED
|
@@ -1 +1,106 @@
|
|
|
1
|
-
|
|
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 };
|
package/dist/chunk-PET42Z7W.js
CHANGED
|
@@ -1 +1,119 @@
|
|
|
1
|
-
|
|
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 };
|