toolbox-x 1.0.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/LICENSE +201 -0
- package/dist/Color-B3mgF9Dh.d.cts +486 -0
- package/dist/Color-D38Xrw65.d.mts +486 -0
- package/dist/Stylog-Df7eq3-j.d.cts +519 -0
- package/dist/Stylog-jvlLcMQq.d.mts +519 -0
- package/dist/array-DvW0zIu6.d.mts +130 -0
- package/dist/array-rUnEVisO.d.cts +130 -0
- package/dist/basics-D_eSv0cu.cjs +132 -0
- package/dist/basics-Dp_aEK81.mjs +115 -0
- package/dist/basics-WEYWlnRO.d.cts +95 -0
- package/dist/basics-uBSfkBEI.d.mts +95 -0
- package/dist/case-BWIt8Ash.mjs +449 -0
- package/dist/case-C-S-b5YP.d.cts +327 -0
- package/dist/case-CS8Ii3A7.cjs +526 -0
- package/dist/case-CybASFPD.d.mts +327 -0
- package/dist/change-case.cjs +32 -0
- package/dist/change-case.d.cts +18 -0
- package/dist/change-case.d.mts +18 -0
- package/dist/change-case.mjs +19 -0
- package/dist/colors.cjs +574 -0
- package/dist/colors.d.cts +355 -0
- package/dist/colors.d.mts +355 -0
- package/dist/colors.mjs +547 -0
- package/dist/constants-2gAw23_7.mjs +144 -0
- package/dist/constants-B34K0QPi.d.cts +21 -0
- package/dist/constants-BIBDKY1u.cjs +924 -0
- package/dist/constants-BWT-810U.cjs +158 -0
- package/dist/constants-BwbHnXlM.mjs +662 -0
- package/dist/constants-BxN9l5el.cjs +74 -0
- package/dist/constants-CLS_bgKD.d.mts +847 -0
- package/dist/constants-D73iFu8g.mjs +171 -0
- package/dist/constants-DAfRxaa8.mjs +62 -0
- package/dist/constants-DQYeCjlx.cjs +207 -0
- package/dist/constants-Deeie-iH.d.mts +21 -0
- package/dist/constants-DpTG9RP6.d.mts +29 -0
- package/dist/constants-DqwnkJ_d.cjs +740 -0
- package/dist/constants-DvRUY_FY.cjs +150 -0
- package/dist/constants-VcRtQu0K.d.cts +29 -0
- package/dist/constants-X5hm1UtB.mjs +912 -0
- package/dist/constants-eNd-iYsV.mjs +134 -0
- package/dist/constants-qm8FafmD.d.cts +847 -0
- package/dist/constants.cjs +415 -0
- package/dist/constants.d.cts +184 -0
- package/dist/constants.d.mts +184 -0
- package/dist/constants.mjs +378 -0
- package/dist/convert-BOCgUv2D.cjs +252 -0
- package/dist/convert-Bn4jFomQ.mjs +169 -0
- package/dist/convert-BrzlG-m_.cjs +475 -0
- package/dist/convert-DhaUoPVU.mjs +368 -0
- package/dist/converter-1P90_RcP.d.mts +402 -0
- package/dist/converter-CmkcAppi.d.cts +402 -0
- package/dist/converter.cjs +780 -0
- package/dist/converter.d.cts +29 -0
- package/dist/converter.d.mts +29 -0
- package/dist/converter.mjs +771 -0
- package/dist/countries-CIpmtEzV.cjs +1469 -0
- package/dist/countries-Cy0xiqS3.mjs +1463 -0
- package/dist/css-colors-Bx947Ng3.d.cts +179 -0
- package/dist/css-colors-CXCDqQbG.cjs +186 -0
- package/dist/css-colors-CXTp1vvy.d.mts +179 -0
- package/dist/css-colors-DfUW3nTR.mjs +180 -0
- package/dist/date.cjs +332 -0
- package/dist/date.d.cts +213 -0
- package/dist/date.d.mts +213 -0
- package/dist/date.mjs +298 -0
- package/dist/dom.cjs +461 -0
- package/dist/dom.d.cts +228 -0
- package/dist/dom.d.mts +228 -0
- package/dist/dom.mjs +429 -0
- package/dist/form-BMFVGUrN.d.mts +118 -0
- package/dist/form-DRFbryvK.d.cts +118 -0
- package/dist/guards-3kaUX66g.mjs +157 -0
- package/dist/guards-C8gkvIHb.cjs +240 -0
- package/dist/guards-DdyU4h4o.mjs +110 -0
- package/dist/guards-Efhp1mNy.cjs +151 -0
- package/dist/guards.cjs +172 -0
- package/dist/guards.d.cts +399 -0
- package/dist/guards.d.mts +399 -0
- package/dist/guards.mjs +75 -0
- package/dist/hash-B6JPEyAz.d.mts +131 -0
- package/dist/hash-NTpeKYB_.d.cts +131 -0
- package/dist/hash.cjs +2126 -0
- package/dist/hash.d.cts +1239 -0
- package/dist/hash.d.mts +1239 -0
- package/dist/hash.mjs +2095 -0
- package/dist/http-status-BAZdtr7-.d.mts +65 -0
- package/dist/http-status-U_3MtoGb.d.cts +65 -0
- package/dist/http-status.cjs +173 -0
- package/dist/http-status.d.cts +142 -0
- package/dist/http-status.d.mts +142 -0
- package/dist/http-status.mjs +171 -0
- package/dist/index.cjs +2551 -0
- package/dist/index.d.cts +1493 -0
- package/dist/index.d.mts +1493 -0
- package/dist/index.mjs +2357 -0
- package/dist/object-B0TV3eHx.d.mts +8052 -0
- package/dist/object-Blq0Amdv.d.cts +8052 -0
- package/dist/objectify-CDs0Fbr1.mjs +417 -0
- package/dist/objectify-DIJ-OBmo.cjs +524 -0
- package/dist/paginator.cjs +245 -0
- package/dist/paginator.d.cts +144 -0
- package/dist/paginator.d.mts +144 -0
- package/dist/paginator.mjs +243 -0
- package/dist/parse-2ubxXZRp.cjs +211 -0
- package/dist/parse-N7g942uy.mjs +164 -0
- package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
- package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
- package/dist/pluralizer.cjs +678 -0
- package/dist/pluralizer.d.cts +152 -0
- package/dist/pluralizer.d.mts +152 -0
- package/dist/pluralizer.mjs +676 -0
- package/dist/primitives-B26uZolQ.cjs +228 -0
- package/dist/primitives-KsFUp3kQ.mjs +144 -0
- package/dist/specials-D48_IZbd.d.mts +108 -0
- package/dist/specials-DzLr1ZgU.cjs +477 -0
- package/dist/specials-LVONlKbQ.d.cts +108 -0
- package/dist/specials-uhDuRg8H.mjs +292 -0
- package/dist/string-CBAbxaG1.d.mts +258 -0
- package/dist/string-CsNsm_65.d.cts +258 -0
- package/dist/stylog.cjs +621 -0
- package/dist/stylog.d.cts +49 -0
- package/dist/stylog.d.mts +49 -0
- package/dist/stylog.mjs +614 -0
- package/dist/timezone-B2OYK6Fh.mjs +5589 -0
- package/dist/timezone-Beh9IGpw.cjs +5625 -0
- package/dist/types/array.cjs +16 -0
- package/dist/types/array.d.cts +18 -0
- package/dist/types/array.d.mts +18 -0
- package/dist/types/array.mjs +17 -0
- package/dist/types/colors.cjs +16 -0
- package/dist/types/colors.d.cts +18 -0
- package/dist/types/colors.d.mts +18 -0
- package/dist/types/colors.mjs +17 -0
- package/dist/types/converter.cjs +16 -0
- package/dist/types/converter.d.cts +18 -0
- package/dist/types/converter.d.mts +18 -0
- package/dist/types/converter.mjs +17 -0
- package/dist/types/form.cjs +16 -0
- package/dist/types/form.d.cts +18 -0
- package/dist/types/form.d.mts +18 -0
- package/dist/types/form.mjs +17 -0
- package/dist/types/hash.cjs +16 -0
- package/dist/types/hash.d.cts +18 -0
- package/dist/types/hash.d.mts +18 -0
- package/dist/types/hash.mjs +17 -0
- package/dist/types/http-status.cjs +16 -0
- package/dist/types/http-status.d.cts +18 -0
- package/dist/types/http-status.d.mts +18 -0
- package/dist/types/http-status.mjs +17 -0
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +18 -0
- package/dist/types/index.d.mts +18 -0
- package/dist/types/index.mjs +17 -0
- package/dist/types/number.cjs +16 -0
- package/dist/types/number.d.cts +18 -0
- package/dist/types/number.d.mts +18 -0
- package/dist/types/number.mjs +17 -0
- package/dist/types/object.cjs +16 -0
- package/dist/types/object.d.cts +18 -0
- package/dist/types/object.d.mts +18 -0
- package/dist/types/object.mjs +17 -0
- package/dist/types/pluralizer.cjs +16 -0
- package/dist/types/pluralizer.d.cts +18 -0
- package/dist/types/pluralizer.d.mts +18 -0
- package/dist/types/pluralizer.mjs +17 -0
- package/dist/types/string.cjs +16 -0
- package/dist/types/string.d.cts +18 -0
- package/dist/types/string.d.mts +18 -0
- package/dist/types/string.mjs +17 -0
- package/dist/types/stylog.cjs +16 -0
- package/dist/types/stylog.d.cts +18 -0
- package/dist/types/stylog.d.mts +18 -0
- package/dist/types/stylog.mjs +17 -0
- package/dist/types/utils.cjs +16 -0
- package/dist/types/utils.d.cts +18 -0
- package/dist/types/utils.d.mts +18 -0
- package/dist/types/utils.mjs +17 -0
- package/dist/types/verbalizer.cjs +16 -0
- package/dist/types/verbalizer.d.cts +30 -0
- package/dist/types/verbalizer.d.mts +30 -0
- package/dist/types/verbalizer.mjs +17 -0
- package/dist/utilities-CLUmdQeV.cjs +140 -0
- package/dist/utilities-m5yFKqLd.mjs +105 -0
- package/dist/utils-ClW9LA6f.mjs +449 -0
- package/dist/utils-DLFRgXUC.cjs +568 -0
- package/dist/verbalizer.cjs +998 -0
- package/dist/verbalizer.d.cts +148 -0
- package/dist/verbalizer.d.mts +148 -0
- package/dist/verbalizer.mjs +996 -0
- package/package.json +249 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const require_primitives = require('./primitives-B26uZolQ.cjs');
|
|
18
|
+
const require_specials = require('./specials-DzLr1ZgU.cjs');
|
|
19
|
+
const require_guards = require('./guards-Efhp1mNy.cjs');
|
|
20
|
+
const require_utils = require('./utils-DLFRgXUC.cjs');
|
|
21
|
+
const require_basics = require('./basics-D_eSv0cu.cjs');
|
|
22
|
+
|
|
23
|
+
//#region src/form/guards.ts
|
|
24
|
+
/**
|
|
25
|
+
* * Checks if a given value is a valid `FormData` & it's not empty.
|
|
26
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
27
|
+
* @param value - The value to check.
|
|
28
|
+
* @returns `true` if the value is a valid `FormData` and not empty, otherwise `false`.
|
|
29
|
+
*/
|
|
30
|
+
function isValidFormData(value) {
|
|
31
|
+
if (!(value instanceof FormData)) return false;
|
|
32
|
+
if ("entries" in value) {
|
|
33
|
+
if (typeof value.entries !== "function") {
|
|
34
|
+
console.warn("`FormData.entries()` is not supported!");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return Array.from(value.entries())?.length > 0;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* * Checks if a given value is an `OriginFileObj`.
|
|
43
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
44
|
+
* @param value - The value to check.
|
|
45
|
+
* @returns `true` if the value is a valid `OriginFileObj`, otherwise `false`.
|
|
46
|
+
*/
|
|
47
|
+
function isOriginFileObj(value) {
|
|
48
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
49
|
+
return require_primitives.isString(value.uid);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* * Checks if a given value is a `CustomFile`.
|
|
53
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
54
|
+
* @param value - The value to check.
|
|
55
|
+
* @returns `true` if the value is a valid `CustomFile`, otherwise `false`.
|
|
56
|
+
*/
|
|
57
|
+
function isCustomFile(value) {
|
|
58
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
59
|
+
const obj = value;
|
|
60
|
+
return "originFileObj" in obj && isOriginFileObj(obj.originFileObj);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* * Checks if a given value is an array of `CustomFile` objects.
|
|
64
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
65
|
+
* @param value - The value to check.
|
|
66
|
+
* @returns `true` if the value is a valid `CustomFile[]`, otherwise `false`.
|
|
67
|
+
*/
|
|
68
|
+
function isCustomFileArray(value) {
|
|
69
|
+
return Array.isArray(value) && value?.length > 0 && value?.every(isCustomFile);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* * Checks if a given value is an array of `File/Blob` objects.
|
|
73
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
74
|
+
* @param value - The value to check.
|
|
75
|
+
* @returns `true` if the value is a valid `File[]` or `Blob[]`, otherwise `false`.
|
|
76
|
+
*/
|
|
77
|
+
function isFileArray(value) {
|
|
78
|
+
return Array.isArray(value) && value?.length > 0 && value?.every(isFileOrBlob);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* * Checks if a given value is an instance of `FileList`.
|
|
82
|
+
* @param value - The value to check.
|
|
83
|
+
* @returns `true` if the value is a valid `FileList`, otherwise `false`.
|
|
84
|
+
*/
|
|
85
|
+
function isFileList(value) {
|
|
86
|
+
return typeof FileList !== "undefined" && value instanceof FileList;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* * Checks if a given value is an instance of `File` or `Blob`.
|
|
90
|
+
* @param value - The value to check.
|
|
91
|
+
* @returns `true` if the value is an instance of `File` or `Blob`, otherwise `false`.
|
|
92
|
+
*/
|
|
93
|
+
function isFileOrBlob(value) {
|
|
94
|
+
return typeof File !== "undefined" && value instanceof File || typeof Blob !== "undefined" && value instanceof Blob;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* * Checks if a given value is a `FileUpload` object.
|
|
98
|
+
* @param value - The value to check.
|
|
99
|
+
* @returns `true` if the value is a valid `FileUpload`, otherwise `false`.
|
|
100
|
+
*/
|
|
101
|
+
function isFileUpload(value) {
|
|
102
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
103
|
+
const obj = value;
|
|
104
|
+
return "file" in obj && isCustomFile(obj.file) || "fileList" in obj && isCustomFileArray(obj.fileList);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/object/sanitize.ts
|
|
109
|
+
/**
|
|
110
|
+
* * Sanitizes a string, array of strings, an object or array of objects by ignoring specified keys and trimming string values.
|
|
111
|
+
* * Also excludes nullish values (null, undefined) if specified. Always ignores empty nested object(s).
|
|
112
|
+
*
|
|
113
|
+
* @param input - The string, object or array of strings or objects to sanitize.
|
|
114
|
+
* @param options - Options for processing data.
|
|
115
|
+
* @param _return - By default return type is as it is, passing this parameter `partial` makes the return type `$DeepPartial<T>`.
|
|
116
|
+
* @returns A new string, object or array of strings or objects with the specified modifications.
|
|
117
|
+
*/
|
|
118
|
+
function sanitizeData(input, options, _return) {
|
|
119
|
+
const { keysToIgnore = [], requiredKeys = [], trimStrings = true, ignoreNullish = false, ignoreFalsy = false, ignoreEmpty = false } = options || {};
|
|
120
|
+
const ignoreKeySet = new Set(keysToIgnore);
|
|
121
|
+
/**
|
|
122
|
+
* * Determines if a key is required
|
|
123
|
+
* @param key The key to check.
|
|
124
|
+
* @returns `true` if the key is required, otherwise `false`.
|
|
125
|
+
*/
|
|
126
|
+
const _isRequiredKey = (key) => {
|
|
127
|
+
return Array.isArray(requiredKeys) ? requiredKeys?.some((path) => key === path || key.startsWith(`${path}.`)) : requiredKeys === "*";
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* * Check if a value is an object and determines whether it should skip based on `ignoreEmpty` flag.
|
|
131
|
+
* @param obj Object value to check.
|
|
132
|
+
* @returns `true` if the object is skippable, otherwise `false`.
|
|
133
|
+
*/
|
|
134
|
+
const _skipObject = (obj) => {
|
|
135
|
+
return ignoreEmpty && require_specials.isObject(obj) && !require_specials.isNotEmptyObject(obj);
|
|
136
|
+
};
|
|
137
|
+
/** Determines if a value is file-like or date-like object */
|
|
138
|
+
const _shouldNotProcess = (value) => {
|
|
139
|
+
return isCustomFile(value) || isFileList(value) || isFileOrBlob(value) || isFileUpload(value) || require_guards.isDateLike(value);
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* * Recursively process an array and its nested content(s).
|
|
143
|
+
* @param arr Array to process.
|
|
144
|
+
* @param path Full path as dot notation if needed.
|
|
145
|
+
* @returns Processed array.
|
|
146
|
+
*/
|
|
147
|
+
const _processArray = (arr, path) => {
|
|
148
|
+
return arr?.map((item) => {
|
|
149
|
+
if (require_primitives.isString(item) && trimStrings) return require_basics.trimString(item);
|
|
150
|
+
if (Array.isArray(item)) return _processArray(item, path);
|
|
151
|
+
if (require_specials.isObject(item)) return _processObject(item, path);
|
|
152
|
+
return item;
|
|
153
|
+
})?.filter((v) => {
|
|
154
|
+
if (ignoreNullish && v == null) return false;
|
|
155
|
+
if (ignoreFalsy && !v) return false;
|
|
156
|
+
if (_skipObject(v) && !_isRequiredKey(path)) return false;
|
|
157
|
+
return true;
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* * Helper function to process a single object.
|
|
162
|
+
*
|
|
163
|
+
* @param object The object to process.
|
|
164
|
+
* @param parentPath The parent path of a key.
|
|
165
|
+
* */
|
|
166
|
+
const _processObject = (object, parentPath = "") => Object.entries(object).reduce((acc, [key, value]) => {
|
|
167
|
+
const fullKeyPath = parentPath ? `${parentPath}.${key}` : key;
|
|
168
|
+
if (ignoreKeySet.has(fullKeyPath)) return acc;
|
|
169
|
+
if (ignoreNullish && !_isRequiredKey(fullKeyPath) && value == null) return acc;
|
|
170
|
+
if (ignoreFalsy && !value && !_isRequiredKey(fullKeyPath)) return acc;
|
|
171
|
+
if (require_primitives.isString(value) && trimStrings) acc[key] = require_basics.trimString(value);
|
|
172
|
+
else if (_shouldNotProcess(value)) acc[key] = value;
|
|
173
|
+
else if (value && require_specials.isObject(value)) if (_shouldNotProcess(value)) acc[key] = value;
|
|
174
|
+
else {
|
|
175
|
+
const processedValue = _processObject(value, fullKeyPath);
|
|
176
|
+
if (!ignoreEmpty || _isRequiredKey(fullKeyPath) || require_specials.isNotEmptyObject(processedValue)) acc[key] = processedValue;
|
|
177
|
+
}
|
|
178
|
+
else if (value && Array.isArray(value)) {
|
|
179
|
+
const processedArray = _processArray(value, fullKeyPath);
|
|
180
|
+
if (!ignoreEmpty || _isRequiredKey(fullKeyPath) || processedArray?.length > 0) acc[key] = processedArray;
|
|
181
|
+
} else acc[key] = value;
|
|
182
|
+
return acc;
|
|
183
|
+
}, {});
|
|
184
|
+
if (require_primitives.isString(input)) return require_basics.trimString(input);
|
|
185
|
+
if (Array.isArray(input)) {
|
|
186
|
+
if (require_specials.isArrayOfType(input, require_primitives.isString)) return require_basics.trimString(input);
|
|
187
|
+
return input?.map((item) => sanitizeData(item, options, _return))?.filter((val) => {
|
|
188
|
+
if (ignoreNullish && val == null) return false;
|
|
189
|
+
if (ignoreFalsy && !val) return false;
|
|
190
|
+
if (_skipObject(val)) return false;
|
|
191
|
+
return true;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (require_specials.isObject(input)) return _processObject(input);
|
|
195
|
+
return input;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* * Parse an object of stringified values into their appropriate primitive types.
|
|
199
|
+
*
|
|
200
|
+
* @description
|
|
201
|
+
* - Attempts to convert string values into `boolean`, `number`, or JSON-parsed objects/arrays.
|
|
202
|
+
* - Non-string values except arrays/objects are left unchanged. Nested arrays/objects are parsed recursively.
|
|
203
|
+
*
|
|
204
|
+
* @param object - The object with potentially stringified primitive values.
|
|
205
|
+
* @param parseNested - Whether to convert stringified primitives in nested arrays/objects. (default: `true`).
|
|
206
|
+
* @returns A new object with parsed values converted to their original types.
|
|
207
|
+
*/
|
|
208
|
+
function parseObjectValues(object, parseNested = true) {
|
|
209
|
+
function _deepParseValues(data) {
|
|
210
|
+
if (Array.isArray(data)) return data?.map(_deepParseValues);
|
|
211
|
+
else if (require_specials.isNotEmptyObject(data)) {
|
|
212
|
+
const result = {};
|
|
213
|
+
for (const [key, value] of Object.entries(data)) result[key] = parseNested ? _deepParseValues(value) : value;
|
|
214
|
+
return result;
|
|
215
|
+
} else if (require_primitives.isString(data)) try {
|
|
216
|
+
return _deepParseValues(JSON.parse(data));
|
|
217
|
+
} catch {
|
|
218
|
+
if (data === "true") return true;
|
|
219
|
+
else if (data === "false") return false;
|
|
220
|
+
else if (data === "null") return null;
|
|
221
|
+
else if (data === "undefined") return;
|
|
222
|
+
else if (!isNaN(Number(data))) return Number(data);
|
|
223
|
+
else return data;
|
|
224
|
+
}
|
|
225
|
+
return data;
|
|
226
|
+
}
|
|
227
|
+
const parsedBody = {};
|
|
228
|
+
if (require_specials.isNotEmptyObject(object)) Object.entries(object)?.forEach(([key, value]) => {
|
|
229
|
+
parsedBody[key] = _deepParseValues(value);
|
|
230
|
+
});
|
|
231
|
+
return parsedBody;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/object/objectify.ts
|
|
236
|
+
/**
|
|
237
|
+
* Deeply merges two or more objects.
|
|
238
|
+
* Objects are merged recursively. Later values override earlier ones unless both are plain objects.
|
|
239
|
+
*
|
|
240
|
+
* @param objects - List of objects to be merged.
|
|
241
|
+
* @returns A new object with deeply merged properties from all input objects.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* const obj1 = { a: 1, b: { x: 10 } };
|
|
245
|
+
* const obj2 = { b: { y: 20 }, c: 3 };
|
|
246
|
+
* const merged = mergeObjects(obj1, obj2);
|
|
247
|
+
* // merged = { a: 1, b: { x: 10, y: 20 }, c: 3 }
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* mergeObjects(
|
|
251
|
+
* { a: 1, b: 2 },
|
|
252
|
+
* { p: { c: 3 }, d: 4 },
|
|
253
|
+
* { p: { e: 5 }, f: 6 }
|
|
254
|
+
* );
|
|
255
|
+
* // => { a: 1, b: 2, p: { c: 3, e: 5 }, d: 4, f: 6 }
|
|
256
|
+
*/
|
|
257
|
+
const mergeObjects = (...objects) => {
|
|
258
|
+
const map = /* @__PURE__ */ new Map();
|
|
259
|
+
for (const obj of objects) for (const key in obj) {
|
|
260
|
+
const existingValue = map.get(key);
|
|
261
|
+
if (require_specials.isNotEmptyObject(obj[key])) if (require_specials.isNotEmptyObject(existingValue)) if (require_guards.isDateLike(obj[key]) || isFileOrBlob(obj[key])) map.set(key, obj[key]);
|
|
262
|
+
else map.set(key, mergeObjects(existingValue, obj[key]));
|
|
263
|
+
else map.set(key, obj[key]);
|
|
264
|
+
else map.set(key, obj[key]);
|
|
265
|
+
}
|
|
266
|
+
const result = {};
|
|
267
|
+
map?.forEach((value, key) => {
|
|
268
|
+
result[key] = value;
|
|
269
|
+
});
|
|
270
|
+
return result;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* * Deeply merge objects and flatten nested objects.
|
|
274
|
+
* * Useful for flattening a single object or merging multiple objects with duplicate key(s).
|
|
275
|
+
* * If keys are duplicated, the last object's value will be used.
|
|
276
|
+
*
|
|
277
|
+
* @param objects Objects to merge.
|
|
278
|
+
* @returns Merged object with flattened structure.
|
|
279
|
+
*/
|
|
280
|
+
const mergeAndFlattenObjects = (...objects) => {
|
|
281
|
+
const map = /* @__PURE__ */ new Map();
|
|
282
|
+
const _flattenObject = (obj, parentKey = "") => {
|
|
283
|
+
for (const key in obj) {
|
|
284
|
+
const newKey = parentKey ? `${String(parentKey)}.${key}` : key;
|
|
285
|
+
if (require_specials.isNotEmptyObject(obj[key])) if (require_guards.isDateLike(obj[key]) || isFileOrBlob(obj[key])) map.set(newKey, obj[key]);
|
|
286
|
+
else _flattenObject(obj[key], newKey);
|
|
287
|
+
else map.set(newKey, obj[key]);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
for (const obj of objects) _flattenObject(obj);
|
|
291
|
+
const result = {};
|
|
292
|
+
map?.forEach((value, key) => {
|
|
293
|
+
result[key] = value;
|
|
294
|
+
});
|
|
295
|
+
return result;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* * Flattens a nested object into key-value format.
|
|
299
|
+
*
|
|
300
|
+
* @param object - The `object` to flatten.
|
|
301
|
+
* @returns A `flattened object` in key-value format.
|
|
302
|
+
*/
|
|
303
|
+
const flattenObjectKeyValue = (object) => {
|
|
304
|
+
const flattened = {};
|
|
305
|
+
for (const [key, value] of Object.entries(object)) if (require_specials.isNotEmptyObject(value)) {
|
|
306
|
+
const nestedFlattened = flattenObjectKeyValue(value);
|
|
307
|
+
if (require_guards.isDateLike(value) || isFileOrBlob(value)) flattened[key] = value;
|
|
308
|
+
else Object.assign(flattened, nestedFlattened);
|
|
309
|
+
} else flattened[key] = value;
|
|
310
|
+
return flattened;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* * Flattens a nested object into a dot notation format.
|
|
314
|
+
*
|
|
315
|
+
* @param object - The `object` to flatten.
|
|
316
|
+
* @returns A `flattened object` with dot notation keys.
|
|
317
|
+
*/
|
|
318
|
+
const flattenObjectDotNotation = (object) => {
|
|
319
|
+
/**
|
|
320
|
+
* * Recursively flattens an object, transforming nested structures into dot-notation keys.
|
|
321
|
+
*
|
|
322
|
+
* @param source - The `object` to be flattened.
|
|
323
|
+
* @param prefix - The prefix to prepend to each key. Used for nested objects.
|
|
324
|
+
* @returns A flattened version of the input object.
|
|
325
|
+
*/
|
|
326
|
+
const _flattenObject = (source, prefix = "") => {
|
|
327
|
+
const flattened = {};
|
|
328
|
+
for (const [key, value] of Object.entries(source)) {
|
|
329
|
+
const newKey = prefix ? `${String(prefix)}.${key}` : key;
|
|
330
|
+
if (require_specials.isNotEmptyObject(value) || isFileOrBlob(value)) if (require_guards.isDateLike(value)) flattened[newKey] = value;
|
|
331
|
+
else Object.assign(flattened, _flattenObject(value, newKey));
|
|
332
|
+
else flattened[newKey] = value;
|
|
333
|
+
}
|
|
334
|
+
return flattened;
|
|
335
|
+
};
|
|
336
|
+
return _flattenObject(object);
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* * Extracts only the fields that have changed between the original and updated object.
|
|
340
|
+
*
|
|
341
|
+
* @param baseObject The original object to compare against.
|
|
342
|
+
* @param updatedObject The modified object containing potential updates.
|
|
343
|
+
* @returns A new object containing only the changed fields.
|
|
344
|
+
*/
|
|
345
|
+
const extractUpdatedFields = (baseObject, updatedObject) => {
|
|
346
|
+
const updatedFields = {};
|
|
347
|
+
for (const key in updatedObject) if (key in baseObject && !require_utils.isDeepEqual(updatedObject[key], baseObject[key])) if (updatedObject[key] && require_specials.isNotEmptyObject(updatedObject[key])) {
|
|
348
|
+
updatedFields[key] = extractUpdatedFields(baseObject[key], updatedObject[key]);
|
|
349
|
+
if (updatedFields[key] && require_specials.isEmptyObject(updatedFields[key])) delete updatedFields[key];
|
|
350
|
+
} else updatedFields[key] = updatedObject[key];
|
|
351
|
+
return updatedFields;
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* * Extracts only new fields that exist in updatedObject but not in baseObject.
|
|
355
|
+
*
|
|
356
|
+
* @param baseObject The original object to compare against.
|
|
357
|
+
* @param updatedObject The modified object containing potential new fields.
|
|
358
|
+
* @returns A new object containing only the new fields.
|
|
359
|
+
*/
|
|
360
|
+
const extractNewFields = (baseObject, updatedObject) => {
|
|
361
|
+
const newFields = {};
|
|
362
|
+
for (const key in updatedObject) if (!(key in baseObject)) newFields[key] = updatedObject[key];
|
|
363
|
+
else if (require_specials.isNotEmptyObject(updatedObject[key]) && require_specials.isNotEmptyObject(baseObject[key])) {
|
|
364
|
+
const nestedNewFields = extractNewFields(baseObject[key], updatedObject[key]);
|
|
365
|
+
if (require_specials.isNotEmptyObject(nestedNewFields)) newFields[key] = nestedNewFields;
|
|
366
|
+
}
|
|
367
|
+
return newFields;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* * Extracts changed fields from the updated object while also identifying newly added keys.
|
|
371
|
+
*
|
|
372
|
+
* @param baseObject The original object to compare against.
|
|
373
|
+
* @param updatedObject The modified object containing potential updates.
|
|
374
|
+
* @returns An object containing modified fields and new fields separately.
|
|
375
|
+
*/
|
|
376
|
+
const extractUpdatedAndNewFields = (baseObject, updatedObject) => {
|
|
377
|
+
const updatedFields = {};
|
|
378
|
+
const newFields = {};
|
|
379
|
+
for (const key in updatedObject) if (!(key in baseObject)) newFields[key] = updatedObject[key];
|
|
380
|
+
else if (!require_utils.isDeepEqual(updatedObject[key], baseObject[key])) if (updatedObject[key] && require_specials.isNotEmptyObject(updatedObject[key])) {
|
|
381
|
+
updatedFields[key] = extractUpdatedAndNewFields(baseObject[key], updatedObject[key]);
|
|
382
|
+
if (updatedFields[key] && require_specials.isEmptyObject(updatedFields[key])) delete updatedFields[key];
|
|
383
|
+
} else updatedFields[key] = updatedObject[key];
|
|
384
|
+
return {
|
|
385
|
+
...updatedFields,
|
|
386
|
+
...newFields
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* * Safely parses a JSON string into an object.
|
|
391
|
+
* * Optionally converts stringified primitive values inside the object (e.g., `"0"` → `0`, `"true"` → `true`, `"null"` → `null`).
|
|
392
|
+
*
|
|
393
|
+
* @param value - The JSON string to parse.
|
|
394
|
+
* @param parsePrimitives - Whether to convert stringified primitives into real values (default: `true`).
|
|
395
|
+
* @returns A parsed object with primitive conversions, or an empty object on failure or if the root is not a valid object.
|
|
396
|
+
* - Returns `{}` if parsing fails, such as when the input is malformed or invalid JSON or passing single quoted string.
|
|
397
|
+
*
|
|
398
|
+
* - **N.B.** This function will return an empty object if the JSON string is invalid or if the root element is not an object.
|
|
399
|
+
*
|
|
400
|
+
* - *Unlike `parseJSON`, which returns any valid JSON structure (including arrays, strings, numbers, etc.),
|
|
401
|
+
* this function strictly ensures that the result is an object and optionally transforms stringified primitives.*
|
|
402
|
+
*
|
|
403
|
+
* @see parseJSON - For parsing generic JSON values (arrays, numbers, etc.) with optional primitive transformation.
|
|
404
|
+
*
|
|
405
|
+
*/
|
|
406
|
+
const parseJsonToObject = (value, parsePrimitives = true) => {
|
|
407
|
+
try {
|
|
408
|
+
const data = JSON.parse(value);
|
|
409
|
+
if (!require_specials.isObject(data)) return {};
|
|
410
|
+
return parsePrimitives ? parseObjectValues(data) : data;
|
|
411
|
+
} catch {
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
//#endregion
|
|
417
|
+
Object.defineProperty(exports, 'extractNewFields', {
|
|
418
|
+
enumerable: true,
|
|
419
|
+
get: function () {
|
|
420
|
+
return extractNewFields;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
Object.defineProperty(exports, 'extractUpdatedAndNewFields', {
|
|
424
|
+
enumerable: true,
|
|
425
|
+
get: function () {
|
|
426
|
+
return extractUpdatedAndNewFields;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
Object.defineProperty(exports, 'extractUpdatedFields', {
|
|
430
|
+
enumerable: true,
|
|
431
|
+
get: function () {
|
|
432
|
+
return extractUpdatedFields;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
Object.defineProperty(exports, 'flattenObjectDotNotation', {
|
|
436
|
+
enumerable: true,
|
|
437
|
+
get: function () {
|
|
438
|
+
return flattenObjectDotNotation;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
Object.defineProperty(exports, 'flattenObjectKeyValue', {
|
|
442
|
+
enumerable: true,
|
|
443
|
+
get: function () {
|
|
444
|
+
return flattenObjectKeyValue;
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
Object.defineProperty(exports, 'isCustomFile', {
|
|
448
|
+
enumerable: true,
|
|
449
|
+
get: function () {
|
|
450
|
+
return isCustomFile;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
Object.defineProperty(exports, 'isCustomFileArray', {
|
|
454
|
+
enumerable: true,
|
|
455
|
+
get: function () {
|
|
456
|
+
return isCustomFileArray;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
Object.defineProperty(exports, 'isFileArray', {
|
|
460
|
+
enumerable: true,
|
|
461
|
+
get: function () {
|
|
462
|
+
return isFileArray;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
Object.defineProperty(exports, 'isFileList', {
|
|
466
|
+
enumerable: true,
|
|
467
|
+
get: function () {
|
|
468
|
+
return isFileList;
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
Object.defineProperty(exports, 'isFileOrBlob', {
|
|
472
|
+
enumerable: true,
|
|
473
|
+
get: function () {
|
|
474
|
+
return isFileOrBlob;
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
Object.defineProperty(exports, 'isFileUpload', {
|
|
478
|
+
enumerable: true,
|
|
479
|
+
get: function () {
|
|
480
|
+
return isFileUpload;
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
Object.defineProperty(exports, 'isOriginFileObj', {
|
|
484
|
+
enumerable: true,
|
|
485
|
+
get: function () {
|
|
486
|
+
return isOriginFileObj;
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
Object.defineProperty(exports, 'isValidFormData', {
|
|
490
|
+
enumerable: true,
|
|
491
|
+
get: function () {
|
|
492
|
+
return isValidFormData;
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
Object.defineProperty(exports, 'mergeAndFlattenObjects', {
|
|
496
|
+
enumerable: true,
|
|
497
|
+
get: function () {
|
|
498
|
+
return mergeAndFlattenObjects;
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
Object.defineProperty(exports, 'mergeObjects', {
|
|
502
|
+
enumerable: true,
|
|
503
|
+
get: function () {
|
|
504
|
+
return mergeObjects;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
Object.defineProperty(exports, 'parseJsonToObject', {
|
|
508
|
+
enumerable: true,
|
|
509
|
+
get: function () {
|
|
510
|
+
return parseJsonToObject;
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
Object.defineProperty(exports, 'parseObjectValues', {
|
|
514
|
+
enumerable: true,
|
|
515
|
+
get: function () {
|
|
516
|
+
return parseObjectValues;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
Object.defineProperty(exports, 'sanitizeData', {
|
|
520
|
+
enumerable: true,
|
|
521
|
+
get: function () {
|
|
522
|
+
return sanitizeData;
|
|
523
|
+
}
|
|
524
|
+
});
|