@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.
- 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 +1 -1
- 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 +1 -1
- package/dist/formatters/index.js +10 -1
- package/dist/generators/index.cjs +31 -1
- package/dist/generators/index.d.ts +1 -1
- package/dist/generators/index.js +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +4 -4
- package/dist/next/index.cjs +205 -1
- package/dist/next/index.d.ts +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 -19
- package/dist/chunk-JYQTCICM.js +0 -1
- package/dist/chunk-YLA3DURS.cjs +0 -1
package/dist/chunk-LS6U7FAY.cjs
CHANGED
|
@@ -1 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFJZGG54N_cjs = require('./chunk-FJZGG54N.cjs');
|
|
4
|
+
var chunkJBQMXC5I_cjs = require('./chunk-JBQMXC5I.cjs');
|
|
5
|
+
var chunkZETAZZLD_cjs = require('./chunk-ZETAZZLD.cjs');
|
|
6
|
+
var chunk6JFZL7YE_cjs = require('./chunk-6JFZL7YE.cjs');
|
|
7
|
+
var chunkT7PU2V7X_cjs = require('./chunk-T7PU2V7X.cjs');
|
|
8
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
9
|
+
var findDuplicates = (values) => {
|
|
10
|
+
chunk6JFZL7YE_cjs.assertIsArray(values, {
|
|
11
|
+
message: ({ currentType, validType }) => `First parameter (\`values\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
|
|
12
|
+
});
|
|
13
|
+
const duplicates = [];
|
|
14
|
+
values.forEach((item, index) => {
|
|
15
|
+
for (let i = index + 1; i < values.length; i++) {
|
|
16
|
+
if (chunkJBQMXC5I_cjs.isEqual(item, values[i])) {
|
|
17
|
+
if (!duplicates.some((dup) => chunkJBQMXC5I_cjs.isEqual(dup, item))) {
|
|
18
|
+
duplicates.push(item);
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return duplicates;
|
|
25
|
+
};
|
|
26
|
+
var omitKeys = (object, keysToOmit) => {
|
|
27
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(object)) return {};
|
|
28
|
+
chunk6JFZL7YE_cjs.assertIsArray(keysToOmit, {
|
|
29
|
+
message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
|
|
30
|
+
});
|
|
31
|
+
const duplicates = findDuplicates(keysToOmit);
|
|
32
|
+
if (duplicates.length > 0) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Function "omitKeys" Error: Duplicate keys detected - \`${duplicates}\``
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return Object.fromEntries(
|
|
38
|
+
Object.entries(object).filter(([key]) => !keysToOmit.includes(key))
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
var omitKeysDeep = (object, keysToOmit) => {
|
|
42
|
+
if (!chunkPZQ6I4JJ_cjs.isPlainObject(object)) return {};
|
|
43
|
+
chunk6JFZL7YE_cjs.assertIsArray(keysToOmit, {
|
|
44
|
+
message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
|
|
45
|
+
});
|
|
46
|
+
const duplicates = findDuplicates(keysToOmit);
|
|
47
|
+
if (chunkPZQ6I4JJ_cjs.isNonEmptyArray(duplicates)) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Function "omitKeysDeep" Error: Duplicate keys detected - \`${chunkT7PU2V7X_cjs.safeStableStringify(
|
|
50
|
+
duplicates
|
|
51
|
+
)}\`.`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const omitAtPath = (obj, pathParts) => {
|
|
55
|
+
if (!chunkPZQ6I4JJ_cjs.isObjectOrArray(obj)) return obj;
|
|
56
|
+
const [current, ...rest] = pathParts;
|
|
57
|
+
if (chunkZETAZZLD_cjs.isEmptyArray(rest)) {
|
|
58
|
+
if (chunkPZQ6I4JJ_cjs.isArray(obj)) {
|
|
59
|
+
const index = parseInt(current);
|
|
60
|
+
if (!chunkPZQ6I4JJ_cjs.isNaN(index) && index in obj) {
|
|
61
|
+
obj.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
delete obj[current];
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const next = obj[current];
|
|
68
|
+
if (chunkPZQ6I4JJ_cjs.isObjectOrArray(next)) {
|
|
69
|
+
obj[current] = omitAtPath(next, rest);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return obj;
|
|
73
|
+
};
|
|
74
|
+
const deepRemoveEmptyObjects = (obj) => {
|
|
75
|
+
if (chunkPZQ6I4JJ_cjs.isArray(obj)) {
|
|
76
|
+
return obj.map(deepRemoveEmptyObjects).filter((item) => !(chunkPZQ6I4JJ_cjs.isObjectOrArray(item) && Object.keys(item).length === 0));
|
|
77
|
+
}
|
|
78
|
+
if (chunkPZQ6I4JJ_cjs.isObjectOrArray(obj)) {
|
|
79
|
+
const cleaned = Object.fromEntries(
|
|
80
|
+
Object.entries(obj).map(([k, v]) => [k, deepRemoveEmptyObjects(v)]).filter(
|
|
81
|
+
([, v]) => !chunkPZQ6I4JJ_cjs.isUndefined(v) && !(chunkPZQ6I4JJ_cjs.isObjectOrArray(v) && Object.keys(v).length === 0)
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
return cleaned;
|
|
85
|
+
}
|
|
86
|
+
return obj;
|
|
87
|
+
};
|
|
88
|
+
const result = chunkFJZGG54N_cjs.safeJsonParse(chunkT7PU2V7X_cjs.safeStableStringify(object));
|
|
89
|
+
for (const key of keysToOmit) {
|
|
90
|
+
const parts = key.split(".");
|
|
91
|
+
omitAtPath(result, parts);
|
|
92
|
+
}
|
|
93
|
+
return deepRemoveEmptyObjects(result);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.findDuplicates = findDuplicates;
|
|
97
|
+
exports.omitKeys = omitKeys;
|
|
98
|
+
exports.omitKeysDeep = omitKeysDeep;
|
package/dist/chunk-NBZWMBO6.js
CHANGED
|
@@ -1 +1,88 @@
|
|
|
1
|
-
import{isDate
|
|
1
|
+
import { isDate, isMap } from './chunk-PET42Z7W.js';
|
|
2
|
+
import { isObjectOrArray, isError, isSet, isArray, isUndefined } from './chunk-CMW2TBOQ.js';
|
|
3
|
+
var isRegExp = (value) => {
|
|
4
|
+
return value instanceof RegExp;
|
|
5
|
+
};
|
|
6
|
+
function isArrayBuffer(value) {
|
|
7
|
+
return value instanceof ArrayBuffer;
|
|
8
|
+
}
|
|
9
|
+
function baseDeepEqual(value, other, customizer, seen = /* @__PURE__ */ new WeakMap()) {
|
|
10
|
+
if (value === other) return true;
|
|
11
|
+
if (value !== value && other !== other) return true;
|
|
12
|
+
if (!isObjectOrArray(value) || !isObjectOrArray(other)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (seen.get(value) === other) return true;
|
|
16
|
+
seen.set(value, other);
|
|
17
|
+
const callCustomizer = (v, o, key, valObj, othObj) => {
|
|
18
|
+
if (customizer) {
|
|
19
|
+
const result = customizer(v, o, key, valObj, othObj, seen);
|
|
20
|
+
if (!isUndefined(result)) return result;
|
|
21
|
+
}
|
|
22
|
+
return baseDeepEqual(v, o, customizer, seen);
|
|
23
|
+
};
|
|
24
|
+
if (isDate(value) && isDate(other)) return value.getTime() === other.getTime();
|
|
25
|
+
if (isRegExp(value) && isRegExp(other))
|
|
26
|
+
return value.source === other.source && value.flags === other.flags;
|
|
27
|
+
if (isError(value) && isError(other))
|
|
28
|
+
return value.name === other.name && value.message === other.message;
|
|
29
|
+
if (ArrayBuffer.isView(value) && ArrayBuffer.isView(other)) {
|
|
30
|
+
const v = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
31
|
+
const o = new Uint8Array(other.buffer, other.byteOffset, other.byteLength);
|
|
32
|
+
if (v.length !== o.length) return false;
|
|
33
|
+
for (let i = 0; i < v.length; i++) if (v[i] !== o[i]) return false;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (isArrayBuffer(value) && isArrayBuffer(other)) {
|
|
37
|
+
if (value.byteLength !== other.byteLength) return false;
|
|
38
|
+
const v = new Uint8Array(value), o = new Uint8Array(other);
|
|
39
|
+
for (let i = 0; i < v.length; i++) if (v[i] !== o[i]) return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (isMap(value) && isMap(other)) {
|
|
43
|
+
if (value.size !== other.size) return false;
|
|
44
|
+
for (const [k, v] of value) {
|
|
45
|
+
if (!other.has(k)) return false;
|
|
46
|
+
if (!baseDeepEqual(v, other.get(k), customizer, seen)) return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (isSet(value) && isSet(other)) {
|
|
51
|
+
if (value.size !== other.size) return false;
|
|
52
|
+
for (const v of value) {
|
|
53
|
+
let matched = false;
|
|
54
|
+
for (const o of other) {
|
|
55
|
+
if (baseDeepEqual(v, o, customizer, seen)) {
|
|
56
|
+
matched = true;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!matched) return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (isArray(value) && isArray(other)) {
|
|
65
|
+
if (value.length !== other.length) return false;
|
|
66
|
+
for (let i = 0; i < value.length; i++) {
|
|
67
|
+
if (!callCustomizer(value[i], other[i], i, value, other)) return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (Object.getPrototypeOf(value) !== Object.getPrototypeOf(other)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const vKeys = Reflect.ownKeys(value);
|
|
75
|
+
const oKeys = Reflect.ownKeys(other);
|
|
76
|
+
if (vKeys.length !== oKeys.length) return false;
|
|
77
|
+
for (const key of vKeys) {
|
|
78
|
+
const vVal = value[key];
|
|
79
|
+
const oVal = other[key];
|
|
80
|
+
if (!callCustomizer(vVal, oVal, key, value, other)) return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
function isEqual(value, other) {
|
|
85
|
+
return baseDeepEqual(value, other, void 0, /* @__PURE__ */ new WeakMap());
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { baseDeepEqual, isArrayBuffer, isEqual, isRegExp };
|
package/dist/chunk-NRF6LWBC.cjs
CHANGED
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkV45XJKHW_cjs = require('./chunk-V45XJKHW.cjs');
|
|
4
|
+
var chunkZETAZZLD_cjs = require('./chunk-ZETAZZLD.cjs');
|
|
5
|
+
var chunkUDA26MCU_cjs = require('./chunk-UDA26MCU.cjs');
|
|
6
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
7
|
+
function filterNilArray(input) {
|
|
8
|
+
if (chunkPZQ6I4JJ_cjs.isNil(input)) return void 0;
|
|
9
|
+
if (!chunkPZQ6I4JJ_cjs.isArray(input)) return [];
|
|
10
|
+
const filtered = input.reduce((output, element) => {
|
|
11
|
+
if (!chunkPZQ6I4JJ_cjs.isNil(element)) {
|
|
12
|
+
if (chunkPZQ6I4JJ_cjs.isArray(element)) {
|
|
13
|
+
const cleanedNested = filterNilArray(element);
|
|
14
|
+
if (cleanedNested && !chunkZETAZZLD_cjs.isEmptyArray(cleanedNested)) {
|
|
15
|
+
output.push(cleanedNested);
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
output.push(element);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return output;
|
|
22
|
+
}, []);
|
|
23
|
+
return filtered;
|
|
24
|
+
}
|
|
25
|
+
function toStringArrayUnRecursive(array, options = {}) {
|
|
26
|
+
chunkPZQ6I4JJ_cjs.assertIsPlainObject(options, {
|
|
27
|
+
message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
28
|
+
});
|
|
29
|
+
const riv = chunkPZQ6I4JJ_cjs.hasOwnProp(options, "removeInvalidValue") ? options.removeInvalidValue : true;
|
|
30
|
+
chunkPZQ6I4JJ_cjs.assertIsBoolean(riv, {
|
|
31
|
+
message: ({ currentType, validType }) => `Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
32
|
+
});
|
|
33
|
+
if (chunkPZQ6I4JJ_cjs.isArray(array)) {
|
|
34
|
+
const result = Array.from(array, (x) => {
|
|
35
|
+
if (chunkPZQ6I4JJ_cjs.isString(x) || chunkV45XJKHW_cjs.isFinite(x) || chunkPZQ6I4JJ_cjs.isBoolean(x) || chunkUDA26MCU_cjs.isBigInt(x)) return String(x);
|
|
36
|
+
return chunkPZQ6I4JJ_cjs.isNull(x) ? null : void 0;
|
|
37
|
+
});
|
|
38
|
+
if (riv) return filterNilArray(result);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.filterNilArray = filterNilArray;
|
|
45
|
+
exports.toStringArrayUnRecursive = toStringArrayUnRecursive;
|
package/dist/chunk-OI5XKNZO.js
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isFinite } from './chunk-3IBQ5MOM.js';
|
|
2
|
+
import { isEmptyArray } from './chunk-6JFCSH7J.js';
|
|
3
|
+
import { isBigInt } from './chunk-QNKGP5DY.js';
|
|
4
|
+
import { isNil, isArray, assertIsPlainObject, hasOwnProp, assertIsBoolean, isString, isBoolean, isNull } from './chunk-CMW2TBOQ.js';
|
|
5
|
+
function filterNilArray(input) {
|
|
6
|
+
if (isNil(input)) return void 0;
|
|
7
|
+
if (!isArray(input)) return [];
|
|
8
|
+
const filtered = input.reduce((output, element) => {
|
|
9
|
+
if (!isNil(element)) {
|
|
10
|
+
if (isArray(element)) {
|
|
11
|
+
const cleanedNested = filterNilArray(element);
|
|
12
|
+
if (cleanedNested && !isEmptyArray(cleanedNested)) {
|
|
13
|
+
output.push(cleanedNested);
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
output.push(element);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return output;
|
|
20
|
+
}, []);
|
|
21
|
+
return filtered;
|
|
22
|
+
}
|
|
23
|
+
function toStringArrayUnRecursive(array, options = {}) {
|
|
24
|
+
assertIsPlainObject(options, {
|
|
25
|
+
message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
26
|
+
});
|
|
27
|
+
const riv = hasOwnProp(options, "removeInvalidValue") ? options.removeInvalidValue : true;
|
|
28
|
+
assertIsBoolean(riv, {
|
|
29
|
+
message: ({ currentType, validType }) => `Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
30
|
+
});
|
|
31
|
+
if (isArray(array)) {
|
|
32
|
+
const result = Array.from(array, (x) => {
|
|
33
|
+
if (isString(x) || isFinite(x) || isBoolean(x) || isBigInt(x)) return String(x);
|
|
34
|
+
return isNull(x) ? null : void 0;
|
|
35
|
+
});
|
|
36
|
+
if (riv) return filterNilArray(result);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { filterNilArray, toStringArrayUnRecursive };
|
package/dist/chunk-ONZFBJVW.js
CHANGED
package/dist/chunk-OYTYSY7G.js
CHANGED
|
@@ -1 +1,94 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { safeJsonParse } from './chunk-2CQX5CBG.js';
|
|
2
|
+
import { isEqual } from './chunk-NBZWMBO6.js';
|
|
3
|
+
import { isEmptyArray } from './chunk-6JFCSH7J.js';
|
|
4
|
+
import { assertIsArray } from './chunk-CKTLUNWX.js';
|
|
5
|
+
import { safeStableStringify } from './chunk-PET42Z7W.js';
|
|
6
|
+
import { isPlainObject, isNonEmptyArray, isObjectOrArray, isArray, isNaN, isUndefined } from './chunk-CMW2TBOQ.js';
|
|
7
|
+
var findDuplicates = (values) => {
|
|
8
|
+
assertIsArray(values, {
|
|
9
|
+
message: ({ currentType, validType }) => `First parameter (\`values\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
|
|
10
|
+
});
|
|
11
|
+
const duplicates = [];
|
|
12
|
+
values.forEach((item, index) => {
|
|
13
|
+
for (let i = index + 1; i < values.length; i++) {
|
|
14
|
+
if (isEqual(item, values[i])) {
|
|
15
|
+
if (!duplicates.some((dup) => isEqual(dup, item))) {
|
|
16
|
+
duplicates.push(item);
|
|
17
|
+
}
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return duplicates;
|
|
23
|
+
};
|
|
24
|
+
var omitKeys = (object, keysToOmit) => {
|
|
25
|
+
if (!isPlainObject(object)) return {};
|
|
26
|
+
assertIsArray(keysToOmit, {
|
|
27
|
+
message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
|
|
28
|
+
});
|
|
29
|
+
const duplicates = findDuplicates(keysToOmit);
|
|
30
|
+
if (duplicates.length > 0) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Function "omitKeys" Error: Duplicate keys detected - \`${duplicates}\``
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return Object.fromEntries(
|
|
36
|
+
Object.entries(object).filter(([key]) => !keysToOmit.includes(key))
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
var omitKeysDeep = (object, keysToOmit) => {
|
|
40
|
+
if (!isPlainObject(object)) return {};
|
|
41
|
+
assertIsArray(keysToOmit, {
|
|
42
|
+
message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.`
|
|
43
|
+
});
|
|
44
|
+
const duplicates = findDuplicates(keysToOmit);
|
|
45
|
+
if (isNonEmptyArray(duplicates)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Function "omitKeysDeep" Error: Duplicate keys detected - \`${safeStableStringify(
|
|
48
|
+
duplicates
|
|
49
|
+
)}\`.`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const omitAtPath = (obj, pathParts) => {
|
|
53
|
+
if (!isObjectOrArray(obj)) return obj;
|
|
54
|
+
const [current, ...rest] = pathParts;
|
|
55
|
+
if (isEmptyArray(rest)) {
|
|
56
|
+
if (isArray(obj)) {
|
|
57
|
+
const index = parseInt(current);
|
|
58
|
+
if (!isNaN(index) && index in obj) {
|
|
59
|
+
obj.splice(index, 1);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
delete obj[current];
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
const next = obj[current];
|
|
66
|
+
if (isObjectOrArray(next)) {
|
|
67
|
+
obj[current] = omitAtPath(next, rest);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return obj;
|
|
71
|
+
};
|
|
72
|
+
const deepRemoveEmptyObjects = (obj) => {
|
|
73
|
+
if (isArray(obj)) {
|
|
74
|
+
return obj.map(deepRemoveEmptyObjects).filter((item) => !(isObjectOrArray(item) && Object.keys(item).length === 0));
|
|
75
|
+
}
|
|
76
|
+
if (isObjectOrArray(obj)) {
|
|
77
|
+
const cleaned = Object.fromEntries(
|
|
78
|
+
Object.entries(obj).map(([k, v]) => [k, deepRemoveEmptyObjects(v)]).filter(
|
|
79
|
+
([, v]) => !isUndefined(v) && !(isObjectOrArray(v) && Object.keys(v).length === 0)
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
return cleaned;
|
|
83
|
+
}
|
|
84
|
+
return obj;
|
|
85
|
+
};
|
|
86
|
+
const result = safeJsonParse(safeStableStringify(object));
|
|
87
|
+
for (const key of keysToOmit) {
|
|
88
|
+
const parts = key.split(".");
|
|
89
|
+
omitAtPath(result, parts);
|
|
90
|
+
}
|
|
91
|
+
return deepRemoveEmptyObjects(result);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { findDuplicates, omitKeys, omitKeysDeep };
|
package/dist/chunk-PET42Z7W.js
CHANGED
|
@@ -1 +1,107 @@
|
|
|
1
|
-
import{isBigInt
|
|
1
|
+
import { isBigInt } from './chunk-QNKGP5DY.js';
|
|
2
|
+
import { assertIsPlainObject, isPlainObject, isBoolean, isNaN, hasOwnProp, getPreciseType, isUndefined, isNumberObject, isInfinityNumber, isStringObject, isBooleanObject, isFunction, isSymbol, isObjectOrArray, isSet, isArray, isNull, isNumber, isObject } from './chunk-CMW2TBOQ.js';
|
|
3
|
+
function isMap(value) {
|
|
4
|
+
return Object.prototype.toString.call(value) === "[object Map]" || value instanceof Map;
|
|
5
|
+
}
|
|
6
|
+
var isDate = (value, options = {}) => {
|
|
7
|
+
assertIsPlainObject(options, {
|
|
8
|
+
message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
9
|
+
});
|
|
10
|
+
const skipInvalidDate = isPlainObject(options) && isBoolean(options.skipInvalidDate) ? options.skipInvalidDate : false;
|
|
11
|
+
const instanceDate = value instanceof Date;
|
|
12
|
+
if (skipInvalidDate) return instanceDate;
|
|
13
|
+
return instanceDate && !isNaN(value.getTime());
|
|
14
|
+
};
|
|
15
|
+
var safeStableStringify = (value, options = {}) => {
|
|
16
|
+
assertIsPlainObject(options, {
|
|
17
|
+
message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
18
|
+
});
|
|
19
|
+
const pretty = hasOwnProp(options, "pretty") ? options.pretty : false;
|
|
20
|
+
const sortKeys = hasOwnProp(options, "sortKeys") ? options.sortKeys : true;
|
|
21
|
+
const sortArray = hasOwnProp(options, "sortArray") ? options.sortArray : false;
|
|
22
|
+
const keepUndefined = hasOwnProp(options, "keepUndefined") ? options.keepUndefined : false;
|
|
23
|
+
if (!isBoolean(sortKeys) || !isBoolean(sortArray) || !isBoolean(pretty) || !isBoolean(keepUndefined)) {
|
|
24
|
+
throw new TypeError(
|
|
25
|
+
`Parameters \`sortKeys\`, \`sortArray\`, \`keepUndefined\` and \`pretty\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: "['sortKeys': \`${getPreciseType(
|
|
26
|
+
sortKeys
|
|
27
|
+
)}\`, 'sortArray': \`${getPreciseType(
|
|
28
|
+
sortArray
|
|
29
|
+
)}\`, 'keepUndefined': \`${getPreciseType(
|
|
30
|
+
keepUndefined
|
|
31
|
+
)}\`, 'pretty': \`${getPreciseType(pretty)}\`]".`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (isUndefined(value)) {
|
|
35
|
+
return keepUndefined ? "undefined" : "null";
|
|
36
|
+
}
|
|
37
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
38
|
+
const isPrimitive = (val) => isNull(val) || !isObjectOrArray(val) && !isFunction(val);
|
|
39
|
+
const deepProcess = (val) => {
|
|
40
|
+
if (isNumberObject(val)) {
|
|
41
|
+
const valOf = val.valueOf();
|
|
42
|
+
return isNaN(valOf) || isInfinityNumber(valOf) ? null : valOf;
|
|
43
|
+
}
|
|
44
|
+
if (isStringObject(val)) return val.valueOf();
|
|
45
|
+
if (isBooleanObject(val)) return val.valueOf();
|
|
46
|
+
if (isFunction(val) || isSymbol(val)) return void 0;
|
|
47
|
+
if (isBigInt(val)) return val.toString();
|
|
48
|
+
if (isNaN(val) || isInfinityNumber(val)) return null;
|
|
49
|
+
if (isUndefined(val)) {
|
|
50
|
+
return keepUndefined ? void 0 : null;
|
|
51
|
+
}
|
|
52
|
+
if (isObjectOrArray(val)) {
|
|
53
|
+
if (seen.has(val)) return "[Circular]";
|
|
54
|
+
seen.add(val);
|
|
55
|
+
if (isDate(val)) return val.toISOString();
|
|
56
|
+
if (isMap(val)) {
|
|
57
|
+
return {
|
|
58
|
+
map: Array.from(val.entries()).map(([k, v]) => [k, deepProcess(v)])
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (isSet(val)) return { set: Array.from(val.values()).map(deepProcess) };
|
|
62
|
+
if (isArray(val)) {
|
|
63
|
+
const processedArr = val.map(deepProcess);
|
|
64
|
+
if (sortArray) {
|
|
65
|
+
const primitives = [];
|
|
66
|
+
const nonPrimitives = [];
|
|
67
|
+
for (const item of processedArr) {
|
|
68
|
+
if (isPrimitive(item)) primitives.push(item);
|
|
69
|
+
else nonPrimitives.push(item);
|
|
70
|
+
}
|
|
71
|
+
primitives.sort((a, b) => {
|
|
72
|
+
if (isNumber(a) && isNumber(b)) return a - b;
|
|
73
|
+
return String(a).localeCompare(String(b));
|
|
74
|
+
});
|
|
75
|
+
return [...primitives, ...nonPrimitives];
|
|
76
|
+
}
|
|
77
|
+
return processedArr;
|
|
78
|
+
}
|
|
79
|
+
const keys = Object.keys(val);
|
|
80
|
+
if (sortKeys) {
|
|
81
|
+
keys.sort((a, b) => {
|
|
82
|
+
const na = Number(a);
|
|
83
|
+
const nb = Number(b);
|
|
84
|
+
if (!isNaN(na) && !isNaN(nb)) return na - nb;
|
|
85
|
+
return a.localeCompare(b);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const result = {};
|
|
89
|
+
if (isObject(val)) {
|
|
90
|
+
for (const k of keys) {
|
|
91
|
+
const v = deepProcess(val[k]);
|
|
92
|
+
if (!isUndefined(v)) result[k] = v;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
return val;
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
return JSON.stringify(deepProcess(value), null, pretty ? 2 : 0);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.warn("Error in safeStableStringify:", err);
|
|
103
|
+
return "{}";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { isDate, isMap, safeStableStringify };
|