nhb-toolbox 2.6.2 → 2.6.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/form/transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,aAAa,QACzD,CAAC,YACG,eAAe,CAAC,CAAC,CAAC,KAC1B,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/form/transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,aAAa,QACzD,CAAC,YACG,eAAe,CAAC,CAAC,CAAC,KAC1B,QAqGF,CAAC"}
|
package/dist/form/transform.js
CHANGED
|
@@ -13,6 +13,21 @@ const basics_2 = require("../object/basics");
|
|
|
13
13
|
*/
|
|
14
14
|
const createControlledFormData = (data, configs) => {
|
|
15
15
|
const formData = new FormData();
|
|
16
|
+
const { stringifyNested = '*' } = configs || {};
|
|
17
|
+
/** Helper function to check if a key matches a dotNotation path to preserve. */
|
|
18
|
+
const shouldDotNotate = (fullKey) => {
|
|
19
|
+
if (Array.isArray(configs?.dotNotateNested)) {
|
|
20
|
+
return configs?.dotNotateNested?.some((path) => fullKey === path || fullKey.startsWith(`${path}.`));
|
|
21
|
+
}
|
|
22
|
+
return configs?.dotNotateNested === '*';
|
|
23
|
+
};
|
|
24
|
+
/** - Helper function to check if a key matches a stringifyNested key. */
|
|
25
|
+
const shouldStringifyNested = (fullKey) => {
|
|
26
|
+
if (Array.isArray(stringifyNested)) {
|
|
27
|
+
return stringifyNested?.some((path) => fullKey === path || fullKey.startsWith(`${path}.`));
|
|
28
|
+
}
|
|
29
|
+
return stringifyNested === '*';
|
|
30
|
+
};
|
|
16
31
|
const addToFormData = (key, value) => {
|
|
17
32
|
const transformedKey = (configs?.lowerCaseKeys === '*' ||
|
|
18
33
|
configs?.lowerCaseKeys?.includes(key)) ?
|
|
@@ -29,10 +44,14 @@ const createControlledFormData = (data, configs) => {
|
|
|
29
44
|
else if (typeof value === 'object' &&
|
|
30
45
|
value !== null &&
|
|
31
46
|
!(0, basics_2.isEmptyObject)(value)) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
if (shouldStringifyNested(key) && !shouldDotNotate(key)) {
|
|
48
|
+
formData.append(transformedKey, JSON.stringify(value));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
52
|
+
addToFormData(`${key}.${nestedKey}`, nestedValue);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
36
55
|
}
|
|
37
56
|
else {
|
|
38
57
|
const isRequired = configs?.requiredKeys === '*' ||
|
|
@@ -43,12 +62,6 @@ const createControlledFormData = (data, configs) => {
|
|
|
43
62
|
}
|
|
44
63
|
}
|
|
45
64
|
};
|
|
46
|
-
// Helper function to check if a key matches a preserved path
|
|
47
|
-
const isPathPreserved = (fullKey) => {
|
|
48
|
-
if (Array.isArray(configs?.preservePaths))
|
|
49
|
-
return configs?.preservePaths?.some((path) => fullKey === path || fullKey.startsWith(`${path}.`));
|
|
50
|
-
return configs?.preservePaths === '*';
|
|
51
|
-
};
|
|
52
65
|
const processObject = (obj, parentKey = '') => {
|
|
53
66
|
Object.entries(obj).forEach(([key, value]) => {
|
|
54
67
|
const fullKey = (parentKey ?
|
|
@@ -62,13 +75,14 @@ const createControlledFormData = (data, configs) => {
|
|
|
62
75
|
value = value.trim();
|
|
63
76
|
}
|
|
64
77
|
// Check if this key is preserved
|
|
65
|
-
if (
|
|
78
|
+
if (shouldDotNotate(fullKey)) {
|
|
66
79
|
// If it's a preserved path, we need to append the value directly as the key
|
|
67
80
|
addToFormData(fullKey, value);
|
|
68
81
|
}
|
|
69
82
|
else if (typeof value === 'object' &&
|
|
70
83
|
!Array.isArray(value) &&
|
|
71
|
-
value != null
|
|
84
|
+
value != null &&
|
|
85
|
+
!stringifyNested) {
|
|
72
86
|
// Process nested objects
|
|
73
87
|
processObject(value, key);
|
|
74
88
|
}
|
package/dist/form/types.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export interface FormDataConfigs<T> {
|
|
|
6
6
|
requiredKeys?: '*' | DotNotationKey<T>[];
|
|
7
7
|
/** - Keys to convert to lowercase. `*` to include all keys */
|
|
8
8
|
lowerCaseKeys?: '*' | DotNotationKey<T>[];
|
|
9
|
-
/** - Dot-notation paths to preserve (e.g., 'user.settings
|
|
10
|
-
|
|
9
|
+
/** - Dot-notation paths to preserve (e.g., 'user.settings'). `*` to include all keys. In this case `user` is an object and `settings` should also be an object. If `dotNotateNested` and `stringifyNested` both have the same key(s) or `*` it will prioritize `dotNotateNested`. */
|
|
10
|
+
dotNotateNested?: '*' | DotNotationKey<T>[];
|
|
11
|
+
/** - Dot-notation paths to stringify nested objects instead of flattening or dot-notate them. Defaults to `*`, use `*` to stringify every nested object. In this case the value of the last part of the key should also be an object. If `dotNotateNested` and `stringifyNested` both have the same key(s) or `*` it will prioritize `dotNotateNested`. */
|
|
12
|
+
stringifyNested?: '*' | DotNotationKey<T>[];
|
|
11
13
|
/** - Whether to trim string values */
|
|
12
14
|
trimStrings?: boolean;
|
|
13
15
|
}
|
package/dist/form/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/form/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,mGAAmG;IACnG,UAAU,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACjC,gEAAgE;IAChE,YAAY,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/form/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,mGAAmG;IACnG,UAAU,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACjC,gEAAgE;IAChE,YAAY,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,qRAAqR;IACrR,eAAe,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,2VAA2V;IAC3V,eAAe,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,sCAAsC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -36,7 +36,7 @@ export declare const flattenObjectDotNotation: <T extends GenericObject>(object:
|
|
|
36
36
|
* @param updatedObject The modified object containing potential updates.
|
|
37
37
|
* @returns A new object containing only the changed fields.
|
|
38
38
|
*/
|
|
39
|
-
export declare const extractUpdatedFields: <T extends GenericObject>(baseObject: T
|
|
39
|
+
export declare const extractUpdatedFields: <T extends GenericObject>(baseObject: T, updatedObject: Partial<T>) => Partial<T>;
|
|
40
40
|
/**
|
|
41
41
|
* * Extracts only new fields that exist in updatedObject but not in baseObject.
|
|
42
42
|
*
|
|
@@ -44,7 +44,7 @@ export declare const extractUpdatedFields: <T extends GenericObject>(baseObject:
|
|
|
44
44
|
* @param updatedObject The modified object containing potential new fields.
|
|
45
45
|
* @returns A new object containing only the new fields.
|
|
46
46
|
*/
|
|
47
|
-
export declare const extractNewFields: <T extends GenericObject, U extends GenericObject>(baseObject: T
|
|
47
|
+
export declare const extractNewFields: <T extends GenericObject, U extends GenericObject>(baseObject: T, updatedObject: Partial<T> & Partial<U>) => Partial<U>;
|
|
48
48
|
/**
|
|
49
49
|
* * Extracts changed fields from the updated object while also identifying newly added keys.
|
|
50
50
|
*
|
|
@@ -52,5 +52,5 @@ export declare const extractNewFields: <T extends GenericObject, U extends Gener
|
|
|
52
52
|
* @param updatedObject The modified object containing potential updates.
|
|
53
53
|
* @returns An object containing modified fields and new fields separately.
|
|
54
54
|
*/
|
|
55
|
-
export declare const extractUpdatedAndNewFields: <T extends GenericObject, U extends GenericObject>(baseObject: T
|
|
55
|
+
export declare const extractUpdatedAndNewFields: <T extends GenericObject, U extends GenericObject>(baseObject: T, updatedObject: Partial<T> & Partial<U>) => Partial<T> & Partial<U>;
|
|
56
56
|
//# sourceMappingURL=objectify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectify.d.ts","sourceRoot":"","sources":["../../src/object/objectify.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,cAAc,CAAC,EAAE,KAAG,CAuCvE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,aAAa,cACjD,CAAC,EAAE,KACb,aAyBF,CAAC;AAEF;;;;;GAKG;AACH,eA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,CAAC,iBACE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAwBxB,CAAC"}
|
package/package.json
CHANGED