nhb-toolbox 4.10.51 → 4.10.52

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.
Files changed (69) hide show
  1. package/dist/cjs/array/Finder.js +4 -4
  2. package/dist/cjs/array/basics.js +6 -6
  3. package/dist/cjs/array/transform.js +2 -2
  4. package/dist/cjs/array/utils.js +8 -8
  5. package/dist/cjs/colors/convert.js +11 -11
  6. package/dist/cjs/colors/helpers.js +2 -2
  7. package/dist/cjs/colors/initials.js +2 -2
  8. package/dist/cjs/colors/random.js +2 -2
  9. package/dist/cjs/colors/utils.js +2 -2
  10. package/dist/cjs/date/Chronos.js +15 -15
  11. package/dist/cjs/dom/query.js +7 -7
  12. package/dist/cjs/dom/utils.js +1 -1
  13. package/dist/cjs/form/convert.js +18 -18
  14. package/dist/cjs/form/guards.js +3 -3
  15. package/dist/cjs/form/transform.js +3 -3
  16. package/dist/cjs/guards/non-primitives.js +7 -16
  17. package/dist/cjs/guards/primitives.js +9 -0
  18. package/dist/cjs/guards/specials.js +1 -1
  19. package/dist/cjs/index.js +3 -3
  20. package/dist/cjs/number/basics.js +8 -8
  21. package/dist/cjs/number/guards.js +1 -1
  22. package/dist/cjs/number/helpers.js +1 -1
  23. package/dist/cjs/object/basics.js +1 -1
  24. package/dist/cjs/object/convert.js +6 -6
  25. package/dist/cjs/object/objectify.js +4 -4
  26. package/dist/cjs/object/sanitize.js +7 -7
  27. package/dist/cjs/string/anagram.js +5 -5
  28. package/dist/cjs/string/basics.js +11 -11
  29. package/dist/cjs/string/convert.js +19 -19
  30. package/dist/cjs/string/utilities.js +4 -4
  31. package/dist/cjs/utils/index.js +11 -11
  32. package/dist/dts/guards/non-primitives.d.ts +0 -6
  33. package/dist/dts/guards/non-primitives.d.ts.map +1 -1
  34. package/dist/dts/guards/primitives.d.ts +6 -0
  35. package/dist/dts/guards/primitives.d.ts.map +1 -1
  36. package/dist/dts/index.d.ts +2 -2
  37. package/dist/dts/index.d.ts.map +1 -1
  38. package/dist/esm/array/Finder.js +4 -4
  39. package/dist/esm/array/basics.js +6 -6
  40. package/dist/esm/array/transform.js +2 -2
  41. package/dist/esm/array/utils.js +8 -8
  42. package/dist/esm/colors/convert.js +11 -11
  43. package/dist/esm/colors/helpers.js +2 -2
  44. package/dist/esm/colors/initials.js +2 -2
  45. package/dist/esm/colors/random.js +2 -2
  46. package/dist/esm/colors/utils.js +2 -2
  47. package/dist/esm/date/Chronos.js +15 -15
  48. package/dist/esm/dom/query.js +7 -7
  49. package/dist/esm/dom/utils.js +1 -1
  50. package/dist/esm/form/convert.js +18 -18
  51. package/dist/esm/form/guards.js +3 -3
  52. package/dist/esm/form/transform.js +3 -3
  53. package/dist/esm/guards/non-primitives.js +7 -15
  54. package/dist/esm/guards/primitives.js +8 -0
  55. package/dist/esm/guards/specials.js +1 -1
  56. package/dist/esm/index.js +2 -2
  57. package/dist/esm/number/basics.js +8 -8
  58. package/dist/esm/number/guards.js +1 -1
  59. package/dist/esm/number/helpers.js +1 -1
  60. package/dist/esm/object/basics.js +1 -1
  61. package/dist/esm/object/convert.js +6 -6
  62. package/dist/esm/object/objectify.js +4 -4
  63. package/dist/esm/object/sanitize.js +7 -7
  64. package/dist/esm/string/anagram.js +5 -5
  65. package/dist/esm/string/basics.js +11 -11
  66. package/dist/esm/string/convert.js +19 -19
  67. package/dist/esm/string/utilities.js +4 -4
  68. package/dist/esm/utils/index.js +11 -11
  69. package/package.json +1 -1
@@ -130,8 +130,8 @@ class Finder {
130
130
  }
131
131
  }
132
132
  let result;
133
- if (source.length < 100 && !forceBinary) {
134
- result = source.find((item) => {
133
+ if (source?.length < 100 && !forceBinary) {
134
+ result = source?.find((item) => {
135
135
  const key = getKey(item);
136
136
  const value = caseInsensitive && typeof key === 'string' ?
137
137
  key.toLowerCase()
@@ -187,7 +187,7 @@ class Finder {
187
187
  * @returns The first matching item if found; otherwise, undefined.
188
188
  */
189
189
  binarySearch(sorted, matcher, keySelector, caseInsensitive) {
190
- let min = 0, max = sorted.length - 1;
190
+ let min = 0, max = sorted?.length - 1;
191
191
  while (min <= max) {
192
192
  const mid = Math.floor((min + max) / 2);
193
193
  const midKey = keySelector(sorted[mid]);
@@ -232,7 +232,7 @@ class Finder {
232
232
  #match(source, target) {
233
233
  let i = 0;
234
234
  for (const char of target) {
235
- i = source.indexOf(char, i);
235
+ i = source?.indexOf(char, i);
236
236
  if (i === -1)
237
237
  return false;
238
238
  i++;
@@ -30,7 +30,7 @@ const filterArrayOfObjects = (array, conditions) => {
30
30
  if (!Array.isArray(array)) {
31
31
  throw new Error('The provided input is not a valid array!');
32
32
  }
33
- return array.filter((item) => Object.entries(conditions).every(([key, conditionFn]) => {
33
+ return array?.filter((item) => Object.entries(conditions)?.every(([key, conditionFn]) => {
34
34
  if (typeof conditionFn === 'function') {
35
35
  return conditionFn(item[key]);
36
36
  }
@@ -47,11 +47,11 @@ exports.filterArrayOfObjects = filterArrayOfObjects;
47
47
  const isInvalidOrEmptyArray = (value) => {
48
48
  if (!Array.isArray(value))
49
49
  return true;
50
- if (value.length === 0)
50
+ if (value?.length === 0)
51
51
  return true;
52
- return value.every((item) => item == null ||
53
- (Array.isArray(item) && item.length === 0) ||
54
- (typeof item === 'object' && Object.keys(item || {}).length === 0));
52
+ return value?.every((item) => item == null ||
53
+ (Array.isArray(item) && item?.length === 0) ||
54
+ (typeof item === 'object' && Object.keys(item || {})?.length === 0));
55
55
  };
56
56
  exports.isInvalidOrEmptyArray = isInvalidOrEmptyArray;
57
57
  /**
@@ -64,7 +64,7 @@ const shuffleArray = (array) => {
64
64
  if ((0, exports.isInvalidOrEmptyArray)(array))
65
65
  return array;
66
66
  const shuffled = structuredClone(array);
67
- for (let i = shuffled.length - 1; i > 0; i--) {
67
+ for (let i = shuffled?.length - 1; i > 0; i--) {
68
68
  const j = Math.floor(Math.random() * (i + 1));
69
69
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
70
70
  }
@@ -56,10 +56,10 @@ function getDuplicates(array) {
56
56
  const hasSeen = seen?.find((el) => (0, utils_1.isDeepEqual)(el, item));
57
57
  const hasDuplicate = duplicates?.find((el) => (0, utils_1.isDeepEqual)(el, item));
58
58
  if (hasSeen && !hasDuplicate) {
59
- duplicates.push(item);
59
+ duplicates?.push(item);
60
60
  }
61
61
  else if (!hasSeen) {
62
- seen.push(item);
62
+ seen?.push(item);
63
63
  }
64
64
  }
65
65
  return duplicates;
@@ -25,7 +25,7 @@ function naturalSort(a, b, options) {
25
25
  let isNumeric = false;
26
26
  for (const char of str) {
27
27
  const charIsNum = !Number.isNaN(Number(char));
28
- if (current.length === 0) {
28
+ if (current?.length === 0) {
29
29
  current = char;
30
30
  isNumeric = charIsNum;
31
31
  continue;
@@ -34,27 +34,27 @@ function naturalSort(a, b, options) {
34
34
  current += char;
35
35
  }
36
36
  else {
37
- chunks.push(isNumeric ? Number(current) : current);
37
+ chunks?.push(isNumeric ? Number(current) : current);
38
38
  current = char;
39
39
  isNumeric = charIsNum;
40
40
  }
41
41
  }
42
- if (current.length > 0) {
43
- chunks.push(isNumeric ? Number(current) : current);
42
+ if (current?.length > 0) {
43
+ chunks?.push(isNumeric ? Number(current) : current);
44
44
  }
45
45
  return chunks;
46
46
  };
47
47
  const aChunks = _createChunks(a);
48
48
  const bChunks = _createChunks(b);
49
- for (let i = 0; i < Math.min(aChunks.length, bChunks.length); i++) {
49
+ for (let i = 0; i < Math.min(aChunks?.length, bChunks?.length); i++) {
50
50
  let aChunk = aChunks[i];
51
51
  let bChunk = bChunks[i];
52
52
  // Normalize string chunks if case-insensitive
53
53
  if (caseInsensitive &&
54
54
  typeof aChunk === 'string' &&
55
55
  typeof bChunk === 'string') {
56
- aChunk = aChunk.toLowerCase();
57
- bChunk = bChunk.toLowerCase();
56
+ aChunk = aChunk?.toLowerCase();
57
+ bChunk = bChunk?.toLowerCase();
58
58
  }
59
59
  // Compare types: number vs string
60
60
  if (typeof aChunk !== typeof bChunk) {
@@ -77,5 +77,5 @@ function naturalSort(a, b, options) {
77
77
  }
78
78
  }
79
79
  }
80
- return aChunks.length - bChunks.length;
80
+ return aChunks?.length - bChunks?.length;
81
81
  }
@@ -94,11 +94,11 @@ exports.convertHslToHex = convertHslToHex;
94
94
  */
95
95
  const convertHexToHsl = (hex) => {
96
96
  let newHex = hex.replace('#', '');
97
- if (newHex.length === 3) {
97
+ if (newHex?.length === 3) {
98
98
  newHex = newHex
99
- .split('')
100
- .map((char) => char + char)
101
- .join('');
99
+ ?.split('')
100
+ ?.map((char) => char + char)
101
+ ?.join('');
102
102
  }
103
103
  const r = parseInt(newHex.slice(0, 2), 16);
104
104
  const g = parseInt(newHex.slice(2, 4), 16);
@@ -116,9 +116,9 @@ exports.convertHexToHsl = convertHexToHsl;
116
116
  */
117
117
  const convertRgbToHex = (r, g, b) => {
118
118
  const hex = [r, g, b]
119
- .map((v) => v.toString(16).padStart(2, '0'))
120
- .join('')
121
- .toUpperCase();
119
+ ?.map((v) => v.toString(16).padStart(2, '0'))
120
+ ?.join('')
121
+ ?.toUpperCase();
122
122
  return `#${hex}`;
123
123
  };
124
124
  exports.convertRgbToHex = convertRgbToHex;
@@ -131,11 +131,11 @@ exports.convertRgbToHex = convertRgbToHex;
131
131
  const convertHexToRgb = (hex) => {
132
132
  // Remove the # if present
133
133
  let newHex = hex.replace('#', '');
134
- if (newHex.length === 3) {
134
+ if (newHex?.length === 3) {
135
135
  newHex = newHex
136
- .split('')
137
- .map((char) => char + char)
138
- .join('');
136
+ ?.split('')
137
+ ?.map((char) => char + char)
138
+ ?.join('');
139
139
  }
140
140
  const r = parseInt(newHex.slice(0, 2), 16);
141
141
  const g = parseInt(newHex.slice(2, 4), 16);
@@ -57,10 +57,10 @@ exports._generateRandomHSL = _generateRandomHSL;
57
57
  * @returns `Boolean` : `true` if the new color is similar to the previous one.
58
58
  */
59
59
  const _isSimilarToLast = (recentColors, newColor) => {
60
- if (recentColors.length === 0)
60
+ if (recentColors?.length === 0)
61
61
  return false;
62
62
  const newHSL = newColor.match(/hsl\((\d+), (\d+)%, (\d+)%\)/);
63
- const lastHSL = recentColors[recentColors.length - 1].match(/hsl\((\d+), (\d+)%, (\d+)%\)/);
63
+ const lastHSL = recentColors[recentColors?.length - 1].match(/hsl\((\d+), (\d+)%, (\d+)%\)/);
64
64
  if (!newHSL || !lastHSL)
65
65
  return false;
66
66
  const newHue = parseInt(newHSL[1], 10);
@@ -31,7 +31,7 @@ function getColorForInitial(input = '', opacity = 100) {
31
31
  const upperInitial = initial.toUpperCase();
32
32
  const index = upperInitial.charCodeAt(0) - 'A'.charCodeAt(0);
33
33
  // Validate alphabet
34
- if (index >= 0 && index < constants_1.alphabetColorPalette.length) {
34
+ if (index >= 0 && index < constants_1.alphabetColorPalette?.length) {
35
35
  return (0, helpers_1._applyOpacity)(constants_1.alphabetColorPalette[index], hexOpacity);
36
36
  }
37
37
  return (0, helpers_1._applyOpacity)('#010514', hexOpacity);
@@ -46,7 +46,7 @@ function getColorForInitial(input = '', opacity = 100) {
46
46
  // Handle array of strings/numbers
47
47
  }
48
48
  else if (Array.isArray(input)) {
49
- if (input.length < 1)
49
+ if (input?.length < 1)
50
50
  return [...constants_1.alphabetColorPalette, ...constants_1.numberColorPalette].map((color) => (0, helpers_1._applyOpacity)(color, hexOpacity));
51
51
  return input
52
52
  .map((el) => {
@@ -24,8 +24,8 @@ const generateRandomHSLColor = (maxColors = 16) => {
24
24
  generatedColors.add(color);
25
25
  recentColors.push(color);
26
26
  // Limit the recent colors to the last `maxColors` to avoid excessive memory usage
27
- if (recentColors.length > maxColors) {
28
- recentColors.shift();
27
+ if (recentColors?.length > maxColors) {
28
+ recentColors?.shift();
29
29
  }
30
30
  return color;
31
31
  };
@@ -13,7 +13,7 @@ const helpers_1 = require("./helpers");
13
13
  */
14
14
  const extractSolidColorValues = (color) => {
15
15
  if ((0, helpers_1._isHSL)(color) || (0, helpers_1._isRGB)(color)) {
16
- return (color.match(/[\d.]+%?/g) || []).map((value) => parseFloat(value));
16
+ return (color.match(/[\d.]+%?/g) || [])?.map((value) => parseFloat(value));
17
17
  }
18
18
  return [0, 0, 0];
19
19
  };
@@ -29,7 +29,7 @@ exports.extractSolidColorValues = extractSolidColorValues;
29
29
  */
30
30
  const extractAlphaColorValues = (color) => {
31
31
  if ((0, helpers_1._isHSLA)(color) || (0, helpers_1._isRGBA)(color)) {
32
- return (color.match(/[\d.]+%?/g) || []).map((value) => parseFloat(value));
32
+ return (color.match(/[\d.]+%?/g) || [])?.map((value) => parseFloat(value));
33
33
  }
34
34
  return [0, 0, 0, 0];
35
35
  };
@@ -204,19 +204,19 @@ class Chronos {
204
204
  };
205
205
  let result = '';
206
206
  let i = 0;
207
- while (i < format.length) {
207
+ while (i < format?.length) {
208
208
  let matched = false;
209
209
  for (const token of constants_1.sortedFormats) {
210
- const ahead = format.slice(i, i + token.length);
210
+ const ahead = format?.slice(i, i + token?.length);
211
211
  const prev = i === 0 ? '' : format[i - 1];
212
- const next = format[i + token.length] ?? '';
212
+ const next = format[i + token?.length] ?? '';
213
213
  // Check non-alphanumeric boundaries
214
214
  const prevOk = i === 0 || /[^a-zA-Z0-9]/.test(prev);
215
- const nextOk = i + token.length >= format.length ||
215
+ const nextOk = i + token?.length >= format?.length ||
216
216
  /[^a-zA-Z0-9]/.test(next);
217
217
  if (ahead === token && prevOk && nextOk) {
218
218
  result += dateComponents[token];
219
- i += token.length;
219
+ i += token?.length;
220
220
  matched = true;
221
221
  break;
222
222
  }
@@ -832,26 +832,26 @@ class Chronos {
832
832
  const lvlIdx = unitOrder.indexOf(level);
833
833
  const parts = [];
834
834
  if (lvlIdx >= 0 && years > 0 && lvlIdx >= unitOrder.indexOf('year')) {
835
- parts.push((0, convert_1.formatUnitWithPlural)(years, 'year'));
835
+ parts?.push((0, convert_1.formatUnitWithPlural)(years, 'year'));
836
836
  }
837
837
  if (lvlIdx >= unitOrder.indexOf('month') && months > 0) {
838
- parts.push((0, convert_1.formatUnitWithPlural)(months, 'month'));
838
+ parts?.push((0, convert_1.formatUnitWithPlural)(months, 'month'));
839
839
  }
840
840
  if (lvlIdx >= unitOrder.indexOf('week') && weeks > 0) {
841
- parts.push((0, convert_1.formatUnitWithPlural)(weeks, 'week'));
841
+ parts?.push((0, convert_1.formatUnitWithPlural)(weeks, 'week'));
842
842
  }
843
843
  if (lvlIdx >= unitOrder.indexOf('day') && days > 0) {
844
- parts.push((0, convert_1.formatUnitWithPlural)(days, 'day'));
844
+ parts?.push((0, convert_1.formatUnitWithPlural)(days, 'day'));
845
845
  }
846
846
  if (lvlIdx >= unitOrder.indexOf('hour') && hours > 0) {
847
- parts.push((0, convert_1.formatUnitWithPlural)(hours, 'hour'));
847
+ parts?.push((0, convert_1.formatUnitWithPlural)(hours, 'hour'));
848
848
  }
849
849
  if (lvlIdx >= unitOrder.indexOf('minute') && minutes > 0) {
850
- parts.push((0, convert_1.formatUnitWithPlural)(minutes, 'minute'));
850
+ parts?.push((0, convert_1.formatUnitWithPlural)(minutes, 'minute'));
851
851
  }
852
852
  if (lvlIdx >= unitOrder.indexOf('second') &&
853
- (seconds > 0 || parts.length === 0)) {
854
- parts.push((0, convert_1.formatUnitWithPlural)(seconds, 'second'));
853
+ (seconds > 0 || parts?.length === 0)) {
854
+ parts?.push((0, convert_1.formatUnitWithPlural)(seconds, 'second'));
855
855
  }
856
856
  let prefix = '';
857
857
  let suffix = '';
@@ -863,7 +863,7 @@ class Chronos {
863
863
  suffix = ' ago';
864
864
  }
865
865
  }
866
- return `${prefix}${parts.join(' ')}${suffix}`;
866
+ return `${prefix}${parts?.join(' ')}${suffix}`;
867
867
  }
868
868
  /**
869
869
  * * Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
@@ -1526,7 +1526,7 @@ class Chronos {
1526
1526
  parts[key] = num;
1527
1527
  }
1528
1528
  }
1529
- return new Chronos(new Date(parts.year ?? 1970, (parts.month ?? 1) - 1, parts.date ?? 1, parts.hour ?? 0, parts.minute ?? 0, parts.second ?? 0)).#withOrigin('parse');
1529
+ return new Chronos(new Date(parts?.year ?? 1970, (parts?.month ?? 1) - 1, parts?.date ?? 1, parts?.hour ?? 0, parts?.minute ?? 0, parts?.second ?? 0)).#withOrigin('parse');
1530
1530
  }
1531
1531
  /**
1532
1532
  * * Rounds the current date-time to the nearest specified unit and interval.
@@ -24,15 +24,15 @@ const generateQueryParams = (params = {}) => {
24
24
  const flattenedParams = (0, objectify_1.flattenObjectKeyValue)(params);
25
25
  // Generate the query string
26
26
  const queryParams = Object.entries(flattenedParams)
27
- .filter(([_, value]) => value !== undefined &&
27
+ ?.filter(([_, value]) => value !== undefined &&
28
28
  value !== null &&
29
- !(typeof value === 'string' && value.trim() === ''))
30
- .flatMap(([key, value]) => Array.isArray(value) ?
29
+ !(typeof value === 'string' && value?.trim() === ''))
30
+ ?.flatMap(([key, value]) => Array.isArray(value) ?
31
31
  value
32
- .filter((v) => v !== undefined &&
32
+ ?.filter((v) => v !== undefined &&
33
33
  v !== null &&
34
34
  !(typeof v === 'string' && v.trim() === ''))
35
- .map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(typeof v === 'boolean' ? String(v) : String(v))}`)
35
+ ?.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(typeof v === 'boolean' ? String(v) : String(v))}`)
36
36
  : `${encodeURIComponent(key)}=${encodeURIComponent(typeof value === 'boolean' ? String(value) : String(value))}`)
37
37
  .join('&');
38
38
  return queryParams ? `?${queryParams}` : '';
@@ -46,7 +46,7 @@ exports.generateQueryParams = generateQueryParams;
46
46
  * @returns Query string as key-value paired object. `Record<string, string>`.
47
47
  */
48
48
  function getQueryParams() {
49
- return Object.fromEntries(new URLSearchParams(window.location.search));
49
+ return Object.fromEntries(new URLSearchParams(window?.location?.search));
50
50
  }
51
51
  /**
52
52
  * * Update query params in the browser URL with given key and value.
@@ -56,7 +56,7 @@ function getQueryParams() {
56
56
  function updateQueryParam(key, value) {
57
57
  const url = new URL(window.location.href);
58
58
  url.searchParams.set(key, value);
59
- window.history.replaceState({}, '', url.toString());
59
+ window.history.replaceState({}, '', url?.toString());
60
60
  }
61
61
  /**
62
62
  * Parses a query string (with optional `?` prefix) into an object.
@@ -57,7 +57,7 @@ async function copyToClipboard(text) {
57
57
  textArea.style.opacity = '0';
58
58
  document.body.appendChild(textArea);
59
59
  textArea.select();
60
- textArea.setSelectionRange(0, textArea.value.length);
60
+ textArea.setSelectionRange(0, textArea.value?.length);
61
61
  const success = document.execCommand('copy');
62
62
  document.body.removeChild(textArea);
63
63
  if (!success) {
@@ -19,13 +19,13 @@ const createControlledFormData = (data, configs) => {
19
19
  /** - Helper to check if a key should be lowercase */
20
20
  const shouldLowercaseKeys = (key) => {
21
21
  return Array.isArray(configs?.lowerCaseKeys) ?
22
- configs.lowerCaseKeys.some((path) => key === path || key.startsWith(`${path}.`))
22
+ configs?.lowerCaseKeys?.some((path) => key === path || key.startsWith(`${path}.`))
23
23
  : configs?.lowerCaseKeys === '*';
24
24
  };
25
25
  /** - Helper to check if a key should be lowercase */
26
26
  const shouldLowercaseValue = (key) => {
27
27
  return Array.isArray(configs?.lowerCaseValues) ?
28
- configs.lowerCaseValues.some((path) => key === path || key.startsWith(`${path}.`))
28
+ configs.lowerCaseValues?.some((path) => key === path || key?.startsWith(`${path}.`))
29
29
  : configs?.lowerCaseValues === '*';
30
30
  };
31
31
  /** - Transforms key to lowercase if needed */
@@ -36,8 +36,8 @@ const createControlledFormData = (data, configs) => {
36
36
  const isRequiredKey = (key) => {
37
37
  const transformedKey = _transformKey(key);
38
38
  return Array.isArray(configs?.requiredKeys) ?
39
- configs.requiredKeys.some((path) => transformedKey === path ||
40
- transformedKey.startsWith(`${path}.`))
39
+ configs?.requiredKeys?.some((path) => transformedKey === path ||
40
+ transformedKey?.startsWith(`${path}.`))
41
41
  : configs?.requiredKeys === '*';
42
42
  };
43
43
  /** - Helper function to check if a key matches a dotNotation path to preserve. */
@@ -89,7 +89,7 @@ const createControlledFormData = (data, configs) => {
89
89
  }
90
90
  else {
91
91
  if (typeof value === 'string') {
92
- acc[transformedKey] = value.toLowerCase();
92
+ acc[transformedKey] = value?.toLowerCase();
93
93
  }
94
94
  else if (Array.isArray(value)) {
95
95
  if (isRequiredKey(fullKey) || (0, non_primitives_1.isValidArray)(value)) {
@@ -113,18 +113,18 @@ const createControlledFormData = (data, configs) => {
113
113
  const _addToFormData = (key, value) => {
114
114
  const transformedKey = _transformKey(key);
115
115
  if ((0, guards_2.isCustomFileArray)(value)) {
116
- value.forEach((file) => formData.append(transformedKey, file.originFileObj));
116
+ value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
117
117
  }
118
118
  else if ((0, guards_2.isFileUpload)(value)) {
119
- if (value.fileList) {
120
- value.fileList.forEach((file) => formData.append(transformedKey, file.originFileObj));
119
+ if (value?.fileList) {
120
+ value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
121
121
  }
122
- else if (value.file) {
123
- if ((0, guards_2.isCustomFile)(value.file)) {
124
- formData.append(transformedKey, value.file.originFileObj);
122
+ else if (value?.file) {
123
+ if ((0, guards_2.isCustomFile)(value?.file)) {
124
+ formData.append(transformedKey, value?.file?.originFileObj);
125
125
  }
126
126
  else {
127
- formData.append(transformedKey, value.file);
127
+ formData.append(transformedKey, value?.file);
128
128
  }
129
129
  }
130
130
  }
@@ -132,26 +132,26 @@ const createControlledFormData = (data, configs) => {
132
132
  formData.append(transformedKey, value);
133
133
  }
134
134
  else if ((0, guards_2.isFileList)(value)) {
135
- for (let i = 0; i < value.length; i++) {
135
+ for (let i = 0; i < value?.length; i++) {
136
136
  formData.append(transformedKey, value.item(i));
137
137
  }
138
138
  }
139
139
  else if (Array.isArray(value)) {
140
140
  if ((0, guards_2.isFileArray)(value)) {
141
141
  if (shouldBreakArray(key)) {
142
- value.forEach((item, index) => {
142
+ value?.forEach((item, index) => {
143
143
  _addToFormData(`${transformedKey}[${index}]`, item);
144
144
  });
145
145
  }
146
146
  else {
147
- value.forEach((item) => {
147
+ value?.forEach((item) => {
148
148
  formData.append(transformedKey, item);
149
149
  });
150
150
  }
151
151
  }
152
152
  else if ((0, non_primitives_1.isValidArray)(value)) {
153
153
  if (shouldBreakArray(key)) {
154
- value.forEach((item, index) => {
154
+ value?.forEach((item, index) => {
155
155
  _addToFormData(`${transformedKey}[${index}]`, item);
156
156
  });
157
157
  }
@@ -184,7 +184,7 @@ const createControlledFormData = (data, configs) => {
184
184
  const isNotNullish = value != null && value !== '';
185
185
  if (isNotNullish || isRequiredKey(key)) {
186
186
  if (typeof value === 'string' && shouldLowercaseValue(key)) {
187
- formData.append(transformedKey, value.toLowerCase());
187
+ formData.append(transformedKey, value?.toLowerCase());
188
188
  }
189
189
  else {
190
190
  // ! CONFUSED UNGA-BUNGA
@@ -204,7 +204,7 @@ const createControlledFormData = (data, configs) => {
204
204
  }
205
205
  // * Trim string values if trimStrings is enabled
206
206
  if (configs?.trimStrings && typeof value === 'string') {
207
- value = value.trim();
207
+ value = value?.trim();
208
208
  }
209
209
  // * Check if this key is preserved as dot-notation
210
210
  if (shouldDotNotate(fullKey)) {
@@ -22,7 +22,7 @@ function isValidFormData(value) {
22
22
  console.warn('`FormData.entries()` is not supported!');
23
23
  return false;
24
24
  }
25
- return Array.from(value.entries()).length > 0;
25
+ return Array.from(value.entries())?.length > 0;
26
26
  }
27
27
  return false;
28
28
  }
@@ -59,7 +59,7 @@ function isCustomFile(value) {
59
59
  * @returns `true` if the value is a valid `CustomFile[]`, otherwise `false`.
60
60
  */
61
61
  function isCustomFileArray(value) {
62
- return (Array.isArray(value) && value.length > 0 && value.every(isCustomFile));
62
+ return (Array.isArray(value) && value?.length > 0 && value?.every(isCustomFile));
63
63
  }
64
64
  /**
65
65
  * * Checks if a given value is an array of `File` objects.
@@ -68,7 +68,7 @@ function isCustomFileArray(value) {
68
68
  * @returns `true` if the value is a valid `File[]`, otherwise `false`.
69
69
  */
70
70
  function isFileArray(value) {
71
- return (Array.isArray(value) && value.length > 0 && value.every(isFileOrBlob));
71
+ return (Array.isArray(value) && value?.length > 0 && value?.every(isFileOrBlob));
72
72
  }
73
73
  /**
74
74
  * * Checks if a given value is an instance of `FileList`.
@@ -15,7 +15,7 @@ const sanitize_1 = require("../object/sanitize");
15
15
  function serializeForm(form, toQueryString = false) {
16
16
  const formData = new FormData(form);
17
17
  const data = {};
18
- formData.forEach((value, key) => {
18
+ formData?.forEach((value, key) => {
19
19
  // If the key already exists, we make it an array to handle multiple selections
20
20
  if (data[key]) {
21
21
  data[key] =
@@ -44,7 +44,7 @@ function parseFormData(data, parsePrimitives = true) {
44
44
  const parsed = {};
45
45
  if (typeof data === 'string') {
46
46
  const params = new URLSearchParams(data);
47
- params.forEach((value, key) => {
47
+ params?.forEach((value, key) => {
48
48
  const existing = parsed[key];
49
49
  if (typeof existing === 'string') {
50
50
  parsed[key] = [existing, value];
@@ -58,7 +58,7 @@ function parseFormData(data, parsePrimitives = true) {
58
58
  });
59
59
  }
60
60
  else {
61
- data.forEach((value, key) => {
61
+ data?.forEach((value, key) => {
62
62
  const existing = parsed[key];
63
63
  if (value instanceof File) {
64
64
  if (Array.isArray(existing)) {
@@ -15,7 +15,6 @@ exports.isSet = isSet;
15
15
  exports.isMap = isMap;
16
16
  exports.isRegExp = isRegExp;
17
17
  exports.isError = isError;
18
- exports.isBigInt = isBigInt;
19
18
  exports.isJSON = isJSON;
20
19
  exports.isReturningPromise = isReturningPromise;
21
20
  const primitives_1 = require("./primitives");
@@ -33,7 +32,7 @@ function isArray(value) {
33
32
  * @returns `true` if the value is an array with length, otherwise `false`.
34
33
  */
35
34
  function isValidArray(value) {
36
- return Array.isArray(value) && value.length > 0;
35
+ return Array.isArray(value) && value?.length > 0;
37
36
  }
38
37
  /**
39
38
  * * Type guard to check if a value is an object (excluding null).
@@ -49,7 +48,7 @@ function isObject(value) {
49
48
  * @returns `true` if the value is an object with valid keys, otherwise `false`.
50
49
  */
51
50
  function isNotEmptyObject(value) {
52
- return isObject(value) && Object.keys(value).length > 0;
51
+ return isObject(value) && Object.keys(value)?.length > 0;
53
52
  }
54
53
  /**
55
54
  * * Type guard to check if a value is an object with specific keys.
@@ -58,7 +57,7 @@ function isNotEmptyObject(value) {
58
57
  * @returns `true` if the value is an object with the specified keys, otherwise `false`.
59
58
  */
60
59
  function isObjectWithKeys(value, keys) {
61
- return isObject(value) && keys.every((key) => key in value);
60
+ return isObject(value) && keys?.every((key) => key in value);
62
61
  }
63
62
  /**
64
63
  * * Type guard to check if a value is an empty object.
@@ -66,7 +65,7 @@ function isObjectWithKeys(value, keys) {
66
65
  * @returns `true` if the value is an empty object, otherwise `false`.
67
66
  */
68
67
  function isEmptyObject(value) {
69
- return isObject(value) && Object.keys(value).length === 0;
68
+ return isObject(value) && Object.keys(value)?.length === 0;
70
69
  }
71
70
  /**
72
71
  * * Type guard to check if a value is a function.
@@ -83,7 +82,7 @@ function isFunction(value) {
83
82
  * @returns `true` if the descriptor is defined and its value is a function; otherwise, `false`.
84
83
  */
85
84
  const isMethodDescriptor = (descriptor) => {
86
- return !!descriptor && typeof descriptor.value === 'function';
85
+ return !!descriptor && typeof descriptor?.value === 'function';
87
86
  };
88
87
  exports.isMethodDescriptor = isMethodDescriptor;
89
88
  /**
@@ -101,7 +100,7 @@ function isDate(value) {
101
100
  * @returns `true` if the value is an array of the specified type, otherwise `false`.
102
101
  */
103
102
  function isArrayOfType(value, typeCheck) {
104
- return isArray(value) && value.every(typeCheck);
103
+ return isArray(value) && value?.every(typeCheck);
105
104
  }
106
105
  /**
107
106
  * * Type guard to check if a value is a Promise.
@@ -143,14 +142,6 @@ function isRegExp(value) {
143
142
  function isError(value) {
144
143
  return value instanceof Error;
145
144
  }
146
- /**
147
- * * Type guard to check if a value is a BigInt.
148
- * @param value - The value to check.
149
- * @returns `true` if the value is a BigInt, otherwise `false`.
150
- */
151
- function isBigInt(value) {
152
- return typeof value === 'bigint';
153
- }
154
145
  /**
155
146
  * * Type guard to check if a string is valid JSON.
156
147
  * @param value - The value to check.
@@ -173,5 +164,5 @@ function isJSON(value) {
173
164
  * @returns `true` if the function returns a Promise, otherwise `false`.
174
165
  */
175
166
  function isReturningPromise(fn) {
176
- return isFunction(fn) && fn.constructor.name === 'AsyncFunction';
167
+ return isFunction(fn) && fn.constructor?.name === 'AsyncFunction';
177
168
  }
@@ -8,6 +8,7 @@ exports.isBoolean = isBoolean;
8
8
  exports.isNull = isNull;
9
9
  exports.isUndefined = isUndefined;
10
10
  exports.isSymbol = isSymbol;
11
+ exports.isBigInt = isBigInt;
11
12
  exports.isPrimitive = isPrimitive;
12
13
  exports.isNormalPrimitive = isNormalPrimitive;
13
14
  exports.isNonEmptyString = isNonEmptyString;
@@ -77,6 +78,14 @@ function isUndefined(value) {
77
78
  function isSymbol(value) {
78
79
  return typeof value === 'symbol';
79
80
  }
81
+ /**
82
+ * * Type guard to check if a value is a BigInt.
83
+ * @param value - The value to check.
84
+ * @returns `true` if the value is a BigInt, otherwise `false`.
85
+ */
86
+ function isBigInt(value) {
87
+ return typeof value === 'bigint';
88
+ }
80
89
  /**
81
90
  * * Type guard to check if a value is a primitive (i.e. `string | number | boolean | symbol | bigint | null | undefined`).
82
91
  * @param value - The value to check.
@@ -29,7 +29,7 @@ function isEmail(value) {
29
29
  * @returns `true` if the value is an array of valid email strings, otherwise `false`.
30
30
  */
31
31
  function isEmailArray(value) {
32
- return (0, non_primitives_1.isArray)(value) && value.every(isEmail);
32
+ return (0, non_primitives_1.isArray)(value) && value?.every(isEmail);
33
33
  }
34
34
  /**
35
35
  * * Type guard to check if a value is a valid date string.