@alextheman/utility 2.8.0 → 2.9.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
@@ -50,6 +50,7 @@ __export(index_exports, {
50
50
  appendSemicolon: () => appendSemicolon_default,
51
51
  camelToKebab: () => camelToKebab_default,
52
52
  convertFileToBase64: () => convertFileToBase64_default,
53
+ createFormData: () => createFormData_default,
53
54
  fillArray: () => fillArray_default,
54
55
  formatDateAndTime: () => formatDateAndTime_default,
55
56
  getRandomNumber: () => getRandomNumber_default,
@@ -119,6 +120,22 @@ function convertFileToBase64(file) {
119
120
  }
120
121
  var convertFileToBase64_default = convertFileToBase64;
121
122
 
123
+ // src/functions/createFormData.ts
124
+ function createFormData(data) {
125
+ const formData = new FormData();
126
+ for (const key in data) {
127
+ if (data[key] instanceof Blob) {
128
+ formData.append(key, data[key]);
129
+ } else if (typeof data[key] === "object") {
130
+ formData.append(key, JSON.stringify(data[key]));
131
+ } else {
132
+ formData.append(key, data[key]);
133
+ }
134
+ }
135
+ return formData;
136
+ }
137
+ var createFormData_default = createFormData;
138
+
122
139
  // src/functions/fillArray.ts
123
140
  function fillArray(callback, length = 1) {
124
141
  const outputArray = new Array(length).fill(null).map((_, index) => {
@@ -406,6 +423,7 @@ var UUID_default = parseUUID;
406
423
  appendSemicolon,
407
424
  camelToKebab,
408
425
  convertFileToBase64,
426
+ createFormData,
409
427
  fillArray,
410
428
  formatDateAndTime,
411
429
  getRandomNumber,
package/dist/index.d.cts CHANGED
@@ -8,6 +8,8 @@ declare function camelToKebab(string: string): string;
8
8
 
9
9
  declare function convertFileToBase64(file: File): Promise<string>;
10
10
 
11
+ declare function createFormData(data: Record<string, string | object | Blob>): FormData;
12
+
11
13
  declare function fillArray<T>(callback: (index: number) => T | Promise<T>, length?: number): T[] | Promise<T[]>;
12
14
 
13
15
  declare function formatDateAndTime(inputDate: Date): string;
@@ -76,4 +78,4 @@ type NonUndefined<T> = T extends undefined ? never : T;
76
78
 
77
79
  type OptionalOnCondition<Condition extends boolean, T> = Condition extends true ? T : T | undefined;
78
80
 
79
- export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
81
+ export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ declare function camelToKebab(string: string): string;
8
8
 
9
9
  declare function convertFileToBase64(file: File): Promise<string>;
10
10
 
11
+ declare function createFormData(data: Record<string, string | object | Blob>): FormData;
12
+
11
13
  declare function fillArray<T>(callback: (index: number) => T | Promise<T>, length?: number): T[] | Promise<T[]>;
12
14
 
13
15
  declare function formatDateAndTime(inputDate: Date): string;
@@ -76,4 +78,4 @@ type NonUndefined<T> = T extends undefined ? never : T;
76
78
 
77
79
  type OptionalOnCondition<Condition extends boolean, T> = Condition extends true ? T : T | undefined;
78
80
 
79
- export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
81
+ export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
package/dist/index.js CHANGED
@@ -62,6 +62,22 @@ function convertFileToBase64(file) {
62
62
  }
63
63
  var convertFileToBase64_default = convertFileToBase64;
64
64
 
65
+ // src/functions/createFormData.ts
66
+ function createFormData(data) {
67
+ const formData = new FormData();
68
+ for (const key in data) {
69
+ if (data[key] instanceof Blob) {
70
+ formData.append(key, data[key]);
71
+ } else if (typeof data[key] === "object") {
72
+ formData.append(key, JSON.stringify(data[key]));
73
+ } else {
74
+ formData.append(key, data[key]);
75
+ }
76
+ }
77
+ return formData;
78
+ }
79
+ var createFormData_default = createFormData;
80
+
65
81
  // src/functions/fillArray.ts
66
82
  function fillArray(callback, length = 1) {
67
83
  const outputArray = new Array(length).fill(null).map((_, index) => {
@@ -348,6 +364,7 @@ export {
348
364
  appendSemicolon_default as appendSemicolon,
349
365
  camelToKebab_default as camelToKebab,
350
366
  convertFileToBase64_default as convertFileToBase64,
367
+ createFormData_default as createFormData,
351
368
  fillArray_default as fillArray,
352
369
  formatDateAndTime_default as formatDateAndTime,
353
370
  getRandomNumber_default as getRandomNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "Helpful utility functions",
5
5
  "license": "ISC",
6
6
  "author": "alextheman",