@gjsify/formdata 0.4.28 → 0.4.29
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/globals.mjs +16 -14
- package/package.json +3 -3
package/globals.mjs
CHANGED
|
@@ -5,19 +5,21 @@
|
|
|
5
5
|
export const FormData = globalThis.FormData;
|
|
6
6
|
export const File = globalThis.File;
|
|
7
7
|
export function formDataToBlob(formData) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
// Use native FormData — formDataToBlob is a @gjsify/formdata utility,
|
|
9
|
+
// not a Web standard. Return a Blob from the native FormData entries.
|
|
10
|
+
const boundary = '----FormDataBoundary' + Math.random().toString(36).slice(2);
|
|
11
|
+
const parts = [];
|
|
12
|
+
for (const [key, value] of formData.entries()) {
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
parts.push(`--${boundary}\r\nContent-Disposition: form-data; name="${key}"\r\n\r\n${value}\r\n`);
|
|
15
|
+
} else {
|
|
16
|
+
parts.push(
|
|
17
|
+
`--${boundary}\r\nContent-Disposition: form-data; name="${key}"; filename="${value.name}"\r\nContent-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`,
|
|
18
|
+
);
|
|
19
|
+
parts.push(value);
|
|
20
|
+
parts.push('\r\n');
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return new Blob(parts, { type: `multipart/form-data; boundary=${boundary}` });
|
|
23
|
+
parts.push(`--${boundary}--\r\n`);
|
|
24
|
+
return new Blob(parts, { type: `multipart/form-data; boundary=${boundary}` });
|
|
23
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/formdata",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.29",
|
|
4
4
|
"description": "Web FormData implementation for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"web"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@gjsify/cli": "^0.4.
|
|
41
|
-
"@gjsify/unit": "^0.4.
|
|
40
|
+
"@gjsify/cli": "^0.4.29",
|
|
41
|
+
"@gjsify/unit": "^0.4.29",
|
|
42
42
|
"@types/node": "^25.9.1",
|
|
43
43
|
"typescript": "^6.0.3"
|
|
44
44
|
}
|