@hybridly/utils 0.0.1-alpha.21 → 0.0.1-alpha.23
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 +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +7 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,7 @@ function hasFiles(data) {
|
|
|
21
21
|
function objectToFormData(source, form, parentKey) {
|
|
22
22
|
source ?? (source = {});
|
|
23
23
|
form ?? (form = new FormData());
|
|
24
|
-
if (typeof source !== "object" || Array.isArray(source) || source instanceof Blob || source instanceof Date || source instanceof FormData) {
|
|
24
|
+
if (typeof source !== "object" || source instanceof Set || Array.isArray(source) || source instanceof Blob || source instanceof Date || source instanceof FormData) {
|
|
25
25
|
throw new TypeError("Source must be an object literal to be converted to a FormData object.");
|
|
26
26
|
}
|
|
27
27
|
for (const key in source) {
|
|
@@ -35,7 +35,12 @@ function composeKey(key, parentKey) {
|
|
|
35
35
|
return parentKey ? `${parentKey}[${key}]` : key;
|
|
36
36
|
}
|
|
37
37
|
function append(form, key, value) {
|
|
38
|
-
if (
|
|
38
|
+
if (value instanceof Set) {
|
|
39
|
+
return [...value].forEach((_value, index) => append(form, composeKey(index.toString(), key), _value));
|
|
40
|
+
} else if (Array.isArray(value)) {
|
|
41
|
+
if (!value.length) {
|
|
42
|
+
return form.append(key, "");
|
|
43
|
+
}
|
|
39
44
|
return Array.from(value.keys()).forEach((index) => append(form, composeKey(index.toString(), key), value[index]));
|
|
40
45
|
} else if (value instanceof Date) {
|
|
41
46
|
return form.append(key, value.toISOString());
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { default as clone } from 'lodash.clonedeep';
|
|
|
4
4
|
type RequestData = Record<string, FormDataConvertible> | FormDataConvertible | FormData;
|
|
5
5
|
type FormDataConvertible = {
|
|
6
6
|
[key: string]: FormDataConvertible;
|
|
7
|
-
} | Array<FormDataConvertible> | Blob | File | FormDataEntryValue | Date | boolean | number | null | undefined | string;
|
|
7
|
+
} | Array<FormDataConvertible> | Set<FormDataConvertible> | Blob | File | FormDataEntryValue | Date | boolean | number | null | undefined | string;
|
|
8
8
|
/**
|
|
9
9
|
* Checks if the given object has a file.
|
|
10
10
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ function hasFiles(data) {
|
|
|
11
11
|
function objectToFormData(source, form, parentKey) {
|
|
12
12
|
source ?? (source = {});
|
|
13
13
|
form ?? (form = new FormData());
|
|
14
|
-
if (typeof source !== "object" || Array.isArray(source) || source instanceof Blob || source instanceof Date || source instanceof FormData) {
|
|
14
|
+
if (typeof source !== "object" || source instanceof Set || Array.isArray(source) || source instanceof Blob || source instanceof Date || source instanceof FormData) {
|
|
15
15
|
throw new TypeError("Source must be an object literal to be converted to a FormData object.");
|
|
16
16
|
}
|
|
17
17
|
for (const key in source) {
|
|
@@ -25,7 +25,12 @@ function composeKey(key, parentKey) {
|
|
|
25
25
|
return parentKey ? `${parentKey}[${key}]` : key;
|
|
26
26
|
}
|
|
27
27
|
function append(form, key, value) {
|
|
28
|
-
if (
|
|
28
|
+
if (value instanceof Set) {
|
|
29
|
+
return [...value].forEach((_value, index) => append(form, composeKey(index.toString(), key), _value));
|
|
30
|
+
} else if (Array.isArray(value)) {
|
|
31
|
+
if (!value.length) {
|
|
32
|
+
return form.append(key, "");
|
|
33
|
+
}
|
|
29
34
|
return Array.from(value.keys()).forEach((index) => append(form, composeKey(index.toString(), key), value[index]));
|
|
30
35
|
} else if (value instanceof Date) {
|
|
31
36
|
return form.append(key, value.toISOString());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/utils",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.23",
|
|
4
4
|
"description": "A solution to develop server-driven, client-rendered applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hybridly",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
|
-
"deepmerge": "^4.
|
|
37
|
+
"deepmerge": "^4.3.0",
|
|
38
38
|
"lodash.clonedeep": "^4.5.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|