Skip to content

Commit

Permalink
fix: objectToFormData (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahinvardar authored Nov 6, 2023
1 parent 4989a16 commit cf28d23
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zod-form-validation-html-example",
"version": "0.1.10",
"version": "0.1.11",
"description": "",
"main": "index.html",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react",
"version": "0.1.10",
"version": "0.1.11",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vardario/zod-form-validation",
"version": "0.1.10",
"version": "0.1.11",
"description": "",
"main": "dist/index.js",
"type": "module",
Expand Down
6 changes: 6 additions & 0 deletions library/src/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('utils', () => {
const formData = getFormData();
const object = formDataToObject(formData);
expect(formDataToObject(objectToFormData(object))).toStrictEqual(object);

const undefinedFormData = objectToFormData({
unused: undefined,
});

expect(undefinedFormData.get('unused')).toBe(null);
});

test('flattenObject', () => {
Expand Down
2 changes: 1 addition & 1 deletion library/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function objectToFormData(obj: any) {
const value = flatObject[key];
if (Array.isArray(value)) {
value.forEach((v) => formData.append(key, v.toString()));
} else {
} else if (value) {
formData.append(key, value.toString());
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "root",
"version": "0.1.10",
"version": "0.1.11",
"license": "MIT",
"repository": {
"type": "git",
Expand Down

0 comments on commit cf28d23

Please sign in to comment.