toolbox-x 1.1.0 → 1.1.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/dist/dom.cjs +18 -15
- package/dist/dom.mjs +18 -15
- package/package.json +1 -1
package/dist/dom.cjs
CHANGED
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
18
18
|
const require_primitives = require('./primitives-CBGICrDR.cjs');
|
|
19
19
|
const require_specials = require('./specials-BM6cx43o.cjs');
|
|
20
20
|
const require_guards = require('./guards-FSW16LfU.cjs');
|
|
21
|
+
const require_basics = require('./basics-K8BDSYD6.cjs');
|
|
21
22
|
const require_objectify = require('./objectify-CRUYlTtI.cjs');
|
|
22
23
|
const require_utils = require('./utils-B1BHomba.cjs');
|
|
23
24
|
|
|
@@ -266,19 +267,20 @@ async function copyToClipboard(text) {
|
|
|
266
267
|
* @returns `FormData` instance containing the sanitized and transformed data.
|
|
267
268
|
*/
|
|
268
269
|
const createFormData = (data, configs) => {
|
|
270
|
+
if (typeof FormData === "undefined") throw new Error("FormData is not available! Please make sure your environment supports FormData.");
|
|
269
271
|
const formData = new FormData();
|
|
270
|
-
const { stringifyNested = "*" } = configs || {};
|
|
271
|
-
/** - Helper to
|
|
272
|
-
const
|
|
273
|
-
return key === path || key.startsWith(`${path}.`);
|
|
272
|
+
const { stringifyNested = "*", ignoreKeys = [], breakArray, lowerCaseKeys, dotNotateNested, lowerCaseValues, requiredKeys } = configs || {};
|
|
273
|
+
/** - Helper to check if a key (plain or dot-notated) matches a path */
|
|
274
|
+
const _compareKeyPaths = (key, paths) => {
|
|
275
|
+
return paths.some((path) => key === path || key.startsWith(`${path}.`));
|
|
274
276
|
};
|
|
275
277
|
/** - Helper to check if a key should be lowercase */
|
|
276
278
|
const _shouldLowercaseKeys = (key) => {
|
|
277
|
-
return Array.isArray(
|
|
279
|
+
return Array.isArray(lowerCaseKeys) ? _compareKeyPaths(key, lowerCaseKeys) : lowerCaseKeys === "*";
|
|
278
280
|
};
|
|
279
281
|
/** - Helper to check if a key should be lowercase */
|
|
280
282
|
const _shouldLowercaseValue = (key) => {
|
|
281
|
-
return Array.isArray(
|
|
283
|
+
return Array.isArray(lowerCaseValues) ? _compareKeyPaths(key, lowerCaseValues) : lowerCaseValues === "*";
|
|
282
284
|
};
|
|
283
285
|
/** - Transforms key to lowercase if needed */
|
|
284
286
|
const _transformKey = (key) => {
|
|
@@ -291,29 +293,29 @@ const createFormData = (data, configs) => {
|
|
|
291
293
|
/** - Helper function to check if a key matches a breakArray key. */
|
|
292
294
|
const _isRequiredKey = (key) => {
|
|
293
295
|
const transformedKey = _transformKey(key);
|
|
294
|
-
return Array.isArray(
|
|
296
|
+
return Array.isArray(requiredKeys) ? _compareKeyPaths(transformedKey, requiredKeys) : requiredKeys === "*";
|
|
295
297
|
};
|
|
296
298
|
/** - Helper function to check if a key matches a dotNotation path to preserve. */
|
|
297
299
|
const _shouldDotNotate = (key) => {
|
|
298
300
|
const transformedKey = _transformKey(key);
|
|
299
|
-
return Array.isArray(
|
|
301
|
+
return Array.isArray(dotNotateNested) ? _compareKeyPaths(transformedKey, dotNotateNested) : dotNotateNested === "*";
|
|
300
302
|
};
|
|
301
303
|
/** - Helper function to check if a key matches a stringifyNested key. */
|
|
302
304
|
const _shouldStringify = (key) => {
|
|
303
305
|
const transformedKey = _transformKey(key);
|
|
304
|
-
return Array.isArray(stringifyNested) ?
|
|
306
|
+
return Array.isArray(stringifyNested) ? _compareKeyPaths(transformedKey, stringifyNested) : stringifyNested === "*";
|
|
305
307
|
};
|
|
306
308
|
/** - Helper function to check if a key matches a breakArray key. */
|
|
307
309
|
const _shouldBreakArray = (key) => {
|
|
308
310
|
const transformedKey = _transformKey(key);
|
|
309
|
-
return Array.isArray(
|
|
311
|
+
return Array.isArray(breakArray) ? _compareKeyPaths(transformedKey, breakArray) : breakArray === "*";
|
|
310
312
|
};
|
|
311
313
|
/** - Helper to clean object by removing null/undefined/empty values while respecting required keys */
|
|
312
314
|
const _cleanObject = (obj, parentKey = "") => {
|
|
313
315
|
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
314
316
|
const transformedKey = _transformKey(key);
|
|
315
317
|
const fullKey = parentKey ? `${parentKey}.${transformedKey}` : transformedKey;
|
|
316
|
-
if (
|
|
318
|
+
if (_compareKeyPaths(fullKey, ignoreKeys)) return acc;
|
|
317
319
|
if (value != null && value !== "" || _isRequiredKey(fullKey) || require_primitives.isNonEmptyString(value) || require_specials.isValidArray(value) || require_specials.isNotEmptyObject(value)) if (require_guards.isDateLike(value)) acc[transformedKey] = value;
|
|
318
320
|
else if (require_specials.isNotEmptyObject(value)) if (require_guards.isDateLike(value)) acc[transformedKey] = value;
|
|
319
321
|
else {
|
|
@@ -322,7 +324,7 @@ const createFormData = (data, configs) => {
|
|
|
322
324
|
}
|
|
323
325
|
else if (require_primitives.isString(value)) if (require_primitives.isNonEmptyString(value)) {
|
|
324
326
|
let cleanString = value;
|
|
325
|
-
if (configs?.trimStrings) cleanString = cleanString
|
|
327
|
+
if (configs?.trimStrings) cleanString = require_basics.trimString(cleanString);
|
|
326
328
|
if (_shouldLowercaseValue(fullKey)) cleanString = cleanString?.toLowerCase();
|
|
327
329
|
acc[transformedKey] = cleanString;
|
|
328
330
|
} else acc[transformedKey] = value;
|
|
@@ -337,6 +339,7 @@ const createFormData = (data, configs) => {
|
|
|
337
339
|
/** * Helper function to add values to formData */
|
|
338
340
|
const _addToFormData = (key, value) => {
|
|
339
341
|
const transformedKey = _transformKey(key);
|
|
342
|
+
if (_compareKeyPaths(transformedKey, ignoreKeys)) return;
|
|
340
343
|
if (require_objectify.isCustomFileArray(value)) value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
|
|
341
344
|
else if (require_objectify.isFileUpload(value)) {
|
|
342
345
|
if (value?.fileList) value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
|
|
@@ -365,7 +368,7 @@ const createFormData = (data, configs) => {
|
|
|
365
368
|
});
|
|
366
369
|
else if (value != null && value !== "" || _isRequiredKey(key)) if (require_primitives.isString(value)) {
|
|
367
370
|
let processedValue = value;
|
|
368
|
-
if (configs?.trimStrings) processedValue =
|
|
371
|
+
if (configs?.trimStrings) processedValue = require_basics.trimString(processedValue);
|
|
369
372
|
if (_shouldLowercaseValue(key)) processedValue = processedValue.toLowerCase();
|
|
370
373
|
formData.append(transformedKey, processedValue);
|
|
371
374
|
} else formData.append(transformedKey, value);
|
|
@@ -375,8 +378,8 @@ const createFormData = (data, configs) => {
|
|
|
375
378
|
Object.entries(obj).forEach(([key, value]) => {
|
|
376
379
|
const transformedKey = _transformKey(key);
|
|
377
380
|
const fullKey = parentKey ? `${parentKey}.${transformedKey}` : transformedKey;
|
|
378
|
-
if (
|
|
379
|
-
if (configs?.trimStrings && require_primitives.isNonEmptyString(value)) value =
|
|
381
|
+
if (_compareKeyPaths(fullKey, ignoreKeys)) return;
|
|
382
|
+
if (configs?.trimStrings && require_primitives.isNonEmptyString(value)) value = require_basics.trimString(value);
|
|
380
383
|
if (_shouldDotNotate(fullKey)) _addToFormData(fullKey, value);
|
|
381
384
|
else if (require_specials.isNotEmptyObject(value) && !_shouldStringify(fullKey)) if (require_guards.isDateLike(value)) _addToFormData(key, _parseDateLike(value));
|
|
382
385
|
else _processObject(value, key);
|
package/dist/dom.mjs
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { a as isNonEmptyString, d as isString } from "./primitives-Djsevc69.mjs";
|
|
18
18
|
import { j as isValidArray, v as isEmptyObject, w as isNotEmptyObject } from "./specials-Cye93-uo.mjs";
|
|
19
19
|
import { t as isDateLike } from "./guards-DEcnNbI5.mjs";
|
|
20
|
+
import { n as trimString } from "./basics-1_M7UvCn.mjs";
|
|
20
21
|
import { _ as isOriginFileObj, a as flattenObjectKeyValue, d as isCustomFile, f as isCustomFileArray, g as isFileUpload, h as isFileOrBlob, l as parseObjectValues, m as isFileList, p as isFileArray, v as isValidFormData } from "./objectify-DgkPCH_o.mjs";
|
|
21
22
|
import { a as deepParsePrimitives } from "./utils-BCytS67y.mjs";
|
|
22
23
|
|
|
@@ -265,19 +266,20 @@ async function copyToClipboard(text) {
|
|
|
265
266
|
* @returns `FormData` instance containing the sanitized and transformed data.
|
|
266
267
|
*/
|
|
267
268
|
const createFormData = (data, configs) => {
|
|
269
|
+
if (typeof FormData === "undefined") throw new Error("FormData is not available! Please make sure your environment supports FormData.");
|
|
268
270
|
const formData = new FormData();
|
|
269
|
-
const { stringifyNested = "*" } = configs || {};
|
|
270
|
-
/** - Helper to
|
|
271
|
-
const
|
|
272
|
-
return key === path || key.startsWith(`${path}.`);
|
|
271
|
+
const { stringifyNested = "*", ignoreKeys = [], breakArray, lowerCaseKeys, dotNotateNested, lowerCaseValues, requiredKeys } = configs || {};
|
|
272
|
+
/** - Helper to check if a key (plain or dot-notated) matches a path */
|
|
273
|
+
const _compareKeyPaths = (key, paths) => {
|
|
274
|
+
return paths.some((path) => key === path || key.startsWith(`${path}.`));
|
|
273
275
|
};
|
|
274
276
|
/** - Helper to check if a key should be lowercase */
|
|
275
277
|
const _shouldLowercaseKeys = (key) => {
|
|
276
|
-
return Array.isArray(
|
|
278
|
+
return Array.isArray(lowerCaseKeys) ? _compareKeyPaths(key, lowerCaseKeys) : lowerCaseKeys === "*";
|
|
277
279
|
};
|
|
278
280
|
/** - Helper to check if a key should be lowercase */
|
|
279
281
|
const _shouldLowercaseValue = (key) => {
|
|
280
|
-
return Array.isArray(
|
|
282
|
+
return Array.isArray(lowerCaseValues) ? _compareKeyPaths(key, lowerCaseValues) : lowerCaseValues === "*";
|
|
281
283
|
};
|
|
282
284
|
/** - Transforms key to lowercase if needed */
|
|
283
285
|
const _transformKey = (key) => {
|
|
@@ -290,29 +292,29 @@ const createFormData = (data, configs) => {
|
|
|
290
292
|
/** - Helper function to check if a key matches a breakArray key. */
|
|
291
293
|
const _isRequiredKey = (key) => {
|
|
292
294
|
const transformedKey = _transformKey(key);
|
|
293
|
-
return Array.isArray(
|
|
295
|
+
return Array.isArray(requiredKeys) ? _compareKeyPaths(transformedKey, requiredKeys) : requiredKeys === "*";
|
|
294
296
|
};
|
|
295
297
|
/** - Helper function to check if a key matches a dotNotation path to preserve. */
|
|
296
298
|
const _shouldDotNotate = (key) => {
|
|
297
299
|
const transformedKey = _transformKey(key);
|
|
298
|
-
return Array.isArray(
|
|
300
|
+
return Array.isArray(dotNotateNested) ? _compareKeyPaths(transformedKey, dotNotateNested) : dotNotateNested === "*";
|
|
299
301
|
};
|
|
300
302
|
/** - Helper function to check if a key matches a stringifyNested key. */
|
|
301
303
|
const _shouldStringify = (key) => {
|
|
302
304
|
const transformedKey = _transformKey(key);
|
|
303
|
-
return Array.isArray(stringifyNested) ?
|
|
305
|
+
return Array.isArray(stringifyNested) ? _compareKeyPaths(transformedKey, stringifyNested) : stringifyNested === "*";
|
|
304
306
|
};
|
|
305
307
|
/** - Helper function to check if a key matches a breakArray key. */
|
|
306
308
|
const _shouldBreakArray = (key) => {
|
|
307
309
|
const transformedKey = _transformKey(key);
|
|
308
|
-
return Array.isArray(
|
|
310
|
+
return Array.isArray(breakArray) ? _compareKeyPaths(transformedKey, breakArray) : breakArray === "*";
|
|
309
311
|
};
|
|
310
312
|
/** - Helper to clean object by removing null/undefined/empty values while respecting required keys */
|
|
311
313
|
const _cleanObject = (obj, parentKey = "") => {
|
|
312
314
|
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
313
315
|
const transformedKey = _transformKey(key);
|
|
314
316
|
const fullKey = parentKey ? `${parentKey}.${transformedKey}` : transformedKey;
|
|
315
|
-
if (
|
|
317
|
+
if (_compareKeyPaths(fullKey, ignoreKeys)) return acc;
|
|
316
318
|
if (value != null && value !== "" || _isRequiredKey(fullKey) || isNonEmptyString(value) || isValidArray(value) || isNotEmptyObject(value)) if (isDateLike(value)) acc[transformedKey] = value;
|
|
317
319
|
else if (isNotEmptyObject(value)) if (isDateLike(value)) acc[transformedKey] = value;
|
|
318
320
|
else {
|
|
@@ -321,7 +323,7 @@ const createFormData = (data, configs) => {
|
|
|
321
323
|
}
|
|
322
324
|
else if (isString(value)) if (isNonEmptyString(value)) {
|
|
323
325
|
let cleanString = value;
|
|
324
|
-
if (configs?.trimStrings) cleanString = cleanString
|
|
326
|
+
if (configs?.trimStrings) cleanString = trimString(cleanString);
|
|
325
327
|
if (_shouldLowercaseValue(fullKey)) cleanString = cleanString?.toLowerCase();
|
|
326
328
|
acc[transformedKey] = cleanString;
|
|
327
329
|
} else acc[transformedKey] = value;
|
|
@@ -336,6 +338,7 @@ const createFormData = (data, configs) => {
|
|
|
336
338
|
/** * Helper function to add values to formData */
|
|
337
339
|
const _addToFormData = (key, value) => {
|
|
338
340
|
const transformedKey = _transformKey(key);
|
|
341
|
+
if (_compareKeyPaths(transformedKey, ignoreKeys)) return;
|
|
339
342
|
if (isCustomFileArray(value)) value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
|
|
340
343
|
else if (isFileUpload(value)) {
|
|
341
344
|
if (value?.fileList) value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
|
|
@@ -364,7 +367,7 @@ const createFormData = (data, configs) => {
|
|
|
364
367
|
});
|
|
365
368
|
else if (value != null && value !== "" || _isRequiredKey(key)) if (isString(value)) {
|
|
366
369
|
let processedValue = value;
|
|
367
|
-
if (configs?.trimStrings) processedValue = processedValue
|
|
370
|
+
if (configs?.trimStrings) processedValue = trimString(processedValue);
|
|
368
371
|
if (_shouldLowercaseValue(key)) processedValue = processedValue.toLowerCase();
|
|
369
372
|
formData.append(transformedKey, processedValue);
|
|
370
373
|
} else formData.append(transformedKey, value);
|
|
@@ -374,8 +377,8 @@ const createFormData = (data, configs) => {
|
|
|
374
377
|
Object.entries(obj).forEach(([key, value]) => {
|
|
375
378
|
const transformedKey = _transformKey(key);
|
|
376
379
|
const fullKey = parentKey ? `${parentKey}.${transformedKey}` : transformedKey;
|
|
377
|
-
if (
|
|
378
|
-
if (configs?.trimStrings && isNonEmptyString(value)) value = value
|
|
380
|
+
if (_compareKeyPaths(fullKey, ignoreKeys)) return;
|
|
381
|
+
if (configs?.trimStrings && isNonEmptyString(value)) value = trimString(value);
|
|
379
382
|
if (_shouldDotNotate(fullKey)) _addToFormData(fullKey, value);
|
|
380
383
|
else if (isNotEmptyObject(value) && !_shouldStringify(fullKey)) if (isDateLike(value)) _addToFormData(key, _parseDateLike(value));
|
|
381
384
|
else _processObject(value, key);
|
package/package.json
CHANGED