@alextheman/utility 2.12.0 → 2.13.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/dist/index.cjs CHANGED
@@ -54,6 +54,7 @@ __export(index_exports, {
54
54
  fillArray: () => fillArray_default,
55
55
  formatDateAndTime: () => formatDateAndTime_default,
56
56
  getRandomNumber: () => getRandomNumber_default,
57
+ getRecordKeys: () => getRecordKeys_default,
57
58
  httpErrorCodeLookup: () => httpErrorCodeLookup,
58
59
  interpolateObjects: () => interpolateObjects_default,
59
60
  isLeapYear: () => isLeapYear_default,
@@ -176,14 +177,25 @@ function createFormData(data, options = { arrayResolution: "stringify", nullable
176
177
  } else if (value === void 0 || value === null) {
177
178
  resolveNullables(key, value, options);
178
179
  } else if (typeof value === "object") {
179
- if (Array.isArray(value) && (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple")) {
180
- for (const item of value) {
181
- if ((typeof item === "object" || !item) && !(item instanceof Blob)) {
182
- throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
180
+ if (Array.isArray(value)) {
181
+ if (value.some((item) => {
182
+ return item instanceof Blob;
183
+ }) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) {
184
+ throw new TypeError("CANNOT_STRINGIFY_BLOB");
185
+ }
186
+ if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
187
+ for (const item of value) {
188
+ if ((typeof item === "object" || !item) && !(item instanceof Blob)) {
189
+ throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
190
+ }
191
+ if (item instanceof Blob) {
192
+ formData.append(String(key), item);
193
+ } else {
194
+ formData.append(String(key), String(item));
195
+ }
183
196
  }
184
- formData.append(String(key), String(item));
197
+ continue;
185
198
  }
186
- continue;
187
199
  }
188
200
  formData.append(String(key), JSON.stringify(value));
189
201
  } else {
@@ -265,6 +277,12 @@ function getRandomNumber(lowerBound, upperBound) {
265
277
  }
266
278
  var getRandomNumber_default = getRandomNumber;
267
279
 
280
+ // src/functions/getRecordKeys.ts
281
+ function getRecordKeys(record) {
282
+ return Object.keys(record);
283
+ }
284
+ var getRecordKeys_default = getRecordKeys;
285
+
268
286
  // src/functions/isLeapYear.ts
269
287
  function isLeapYear(year) {
270
288
  const parsedYear = parseIntStrict_default(`${year}`);
@@ -498,6 +516,7 @@ var UUID_default = parseUUID;
498
516
  fillArray,
499
517
  formatDateAndTime,
500
518
  getRandomNumber,
519
+ getRecordKeys,
501
520
  httpErrorCodeLookup,
502
521
  interpolateObjects,
503
522
  isLeapYear,
package/dist/index.d.cts CHANGED
@@ -67,6 +67,8 @@ declare function formatDateAndTime(inputDate: Date): string;
67
67
 
68
68
  declare function getRandomNumber(lowerBound: number, upperBound: number): number;
69
69
 
70
+ declare function getRecordKeys<T extends Record<RecordKey, unknown>>(record: T & object): (keyof T)[];
71
+
70
72
  declare function isLeapYear(year: number): boolean;
71
73
 
72
74
  declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
@@ -99,4 +101,4 @@ declare function wait(seconds: number): Promise<void>;
99
101
 
100
102
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
101
103
 
102
- export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type RecordKey, type StringListToArrayOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
104
+ export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type RecordKey, type StringListToArrayOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,8 @@ declare function formatDateAndTime(inputDate: Date): string;
67
67
 
68
68
  declare function getRandomNumber(lowerBound: number, upperBound: number): number;
69
69
 
70
+ declare function getRecordKeys<T extends Record<RecordKey, unknown>>(record: T & object): (keyof T)[];
71
+
70
72
  declare function isLeapYear(year: number): boolean;
71
73
 
72
74
  declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
@@ -99,4 +101,4 @@ declare function wait(seconds: number): Promise<void>;
99
101
 
100
102
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
101
103
 
102
- export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type RecordKey, type StringListToArrayOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
104
+ export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type RecordKey, type StringListToArrayOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
package/dist/index.js CHANGED
@@ -117,14 +117,25 @@ function createFormData(data, options = { arrayResolution: "stringify", nullable
117
117
  } else if (value === void 0 || value === null) {
118
118
  resolveNullables(key, value, options);
119
119
  } else if (typeof value === "object") {
120
- if (Array.isArray(value) && (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple")) {
121
- for (const item of value) {
122
- if ((typeof item === "object" || !item) && !(item instanceof Blob)) {
123
- throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
120
+ if (Array.isArray(value)) {
121
+ if (value.some((item) => {
122
+ return item instanceof Blob;
123
+ }) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) {
124
+ throw new TypeError("CANNOT_STRINGIFY_BLOB");
125
+ }
126
+ if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
127
+ for (const item of value) {
128
+ if ((typeof item === "object" || !item) && !(item instanceof Blob)) {
129
+ throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
130
+ }
131
+ if (item instanceof Blob) {
132
+ formData.append(String(key), item);
133
+ } else {
134
+ formData.append(String(key), String(item));
135
+ }
124
136
  }
125
- formData.append(String(key), String(item));
137
+ continue;
126
138
  }
127
- continue;
128
139
  }
129
140
  formData.append(String(key), JSON.stringify(value));
130
141
  } else {
@@ -206,6 +217,12 @@ function getRandomNumber(lowerBound, upperBound) {
206
217
  }
207
218
  var getRandomNumber_default = getRandomNumber;
208
219
 
220
+ // src/functions/getRecordKeys.ts
221
+ function getRecordKeys(record) {
222
+ return Object.keys(record);
223
+ }
224
+ var getRecordKeys_default = getRecordKeys;
225
+
209
226
  // src/functions/isLeapYear.ts
210
227
  function isLeapYear(year) {
211
228
  const parsedYear = parseIntStrict_default(`${year}`);
@@ -438,6 +455,7 @@ export {
438
455
  fillArray_default as fillArray,
439
456
  formatDateAndTime_default as formatDateAndTime,
440
457
  getRandomNumber_default as getRandomNumber,
458
+ getRecordKeys_default as getRecordKeys,
441
459
  httpErrorCodeLookup,
442
460
  interpolateObjects_default as interpolateObjects,
443
461
  isLeapYear_default as isLeapYear,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "2.12.0",
3
+ "version": "2.13.0",
4
4
  "description": "Helpful utility functions",
5
5
  "license": "ISC",
6
6
  "author": "alextheman",
@@ -37,19 +37,19 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@alextheman/eslint-plugin": "^2.5.0",
40
- "@eslint/js": "^9.39.0",
41
- "@types/node": "^24.9.2",
42
- "eslint": "^9.39.0",
40
+ "@eslint/js": "^9.39.1",
41
+ "@types/node": "^24.10.0",
42
+ "eslint": "^9.39.1",
43
43
  "eslint-import-resolver-typescript": "^4.4.4",
44
44
  "eslint-plugin-import": "^2.32.0",
45
- "globals": "^16.4.0",
45
+ "globals": "^16.5.0",
46
46
  "husky": "^9.1.7",
47
47
  "jsdom": "^27.1.0",
48
48
  "prettier": "^3.6.2",
49
49
  "tsup": "^8.5.0",
50
50
  "typescript": "^5.9.3",
51
- "typescript-eslint": "^8.46.2",
51
+ "typescript-eslint": "^8.46.3",
52
52
  "vite-tsconfig-paths": "^5.1.4",
53
- "vitest": "^4.0.6"
53
+ "vitest": "^4.0.8"
54
54
  }
55
55
  }