nhb-toolbox 2.6.7 → 2.6.8

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,QAqGF,CAAC"}
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,QAmHF,CAAC"}
@@ -28,6 +28,13 @@ const createControlledFormData = (data, configs) => {
28
28
  }
29
29
  return stringifyNested === '*';
30
30
  };
31
+ /** - Helper function to check if a key matches a breakArray key. */
32
+ const shouldBreakArray = (fullKey) => {
33
+ if (Array.isArray(configs?.breakArray)) {
34
+ return configs?.breakArray?.some((path) => fullKey === path || fullKey.startsWith(`${path}.`));
35
+ }
36
+ return configs?.breakArray === '*';
37
+ };
31
38
  const addToFormData = (key, value) => {
32
39
  const transformedKey = (configs?.lowerCaseKeys === '*' ||
33
40
  configs?.lowerCaseKeys?.includes(key)) ?
@@ -37,15 +44,20 @@ const createControlledFormData = (data, configs) => {
37
44
  formData.append(transformedKey, value[0].originFileObj);
38
45
  }
39
46
  else if (Array.isArray(value)) {
40
- value.forEach((item, index) => {
41
- addToFormData(`${transformedKey}[${index}]`, item);
42
- }); // fix later
47
+ if (shouldBreakArray(key)) {
48
+ value.forEach((item, index) => {
49
+ addToFormData(`${transformedKey}[${index}]`, item);
50
+ });
51
+ }
52
+ else {
53
+ formData.append(transformedKey, JSON.stringify(value));
54
+ }
43
55
  }
44
56
  else if (typeof value === 'object' &&
45
57
  value !== null &&
46
58
  !(0, basics_2.isEmptyObject)(value)) {
47
59
  if (shouldStringifyNested(key) && !shouldDotNotate(key)) {
48
- formData.append(transformedKey, value); // JSON.stringify if needed
60
+ formData.append(transformedKey, JSON.stringify(value));
49
61
  }
50
62
  else {
51
63
  Object.entries(value).forEach(([nestedKey, nestedValue]) => {
@@ -1,15 +1,17 @@
1
1
  import type { DotNotationKey } from '../object/types';
2
2
  export interface FormDataConfigs<T> {
3
- /** - Keys to exclude from processing. Ignored keys are ignored even if they're in other options */
3
+ /** - Keys to exclude from processing. Ignored keys are ignored even if they're in other options. */
4
4
  ignoreKeys?: DotNotationKey<T>[];
5
- /** - Keys to preserve even if falsy. `*` to include all keys */
5
+ /** - Keys to preserve even if falsy. `*` to include all keys. */
6
6
  requiredKeys?: '*' | DotNotationKey<T>[];
7
- /** - Keys to convert to lowercase. `*` to include all keys */
7
+ /** - Keys to convert to lowercase. `*` to include all keys. */
8
8
  lowerCaseKeys?: '*' | DotNotationKey<T>[];
9
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
10
  dotNotateNested?: '*' | DotNotationKey<T>[];
11
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
12
  stringifyNested?: '*' | DotNotationKey<T>[];
13
+ /** - Break arrays in the format `{key[0]: value, key[0]: value,}` for specific key(s) or for all (`*`). `*` to include all keys. */
14
+ breakArray?: '*' | DotNotationKey<T>[];
13
15
  /** - Whether to trim string values */
14
16
  trimStrings?: boolean;
15
17
  }
@@ -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,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"}
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,oGAAoG;IACpG,UAAU,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACjC,iEAAiE;IACjE,YAAY,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,gEAAgE;IAChE,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,oIAAoI;IACpI,UAAU,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,sCAAsC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "2.6.7",
3
+ "version": "2.6.8",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",