@conform-to/dom 0.7.3 → 0.7.4
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/formdata.d.ts +4 -1
- package/formdata.js +17 -7
- package/formdata.mjs +17 -7
- package/package.json +1 -1
- package/parse.d.ts +3 -0
- package/parse.js +4 -1
- package/parse.mjs +5 -2
package/formdata.d.ts
CHANGED
|
@@ -28,7 +28,10 @@ export declare function setValue(target: any, name: string, valueFn: (prev?: unk
|
|
|
28
28
|
/**
|
|
29
29
|
* Resolves the payload into a plain object based on the JS syntax convention
|
|
30
30
|
*/
|
|
31
|
-
export declare function resolve(payload: FormData | URLSearchParams,
|
|
31
|
+
export declare function resolve(payload: FormData | URLSearchParams, options?: {
|
|
32
|
+
ignoreKeys?: string[];
|
|
33
|
+
stripEmptyValue?: boolean;
|
|
34
|
+
}): {};
|
|
32
35
|
/**
|
|
33
36
|
* Format the error messages into a validation message
|
|
34
37
|
*/
|
package/formdata.js
CHANGED
|
@@ -82,24 +82,34 @@ function setValue(target, name, valueFn) {
|
|
|
82
82
|
/**
|
|
83
83
|
* Resolves the payload into a plain object based on the JS syntax convention
|
|
84
84
|
*/
|
|
85
|
-
function resolve(payload
|
|
85
|
+
function resolve(payload) {
|
|
86
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
87
|
var data = {};
|
|
87
|
-
var _loop = function _loop(
|
|
88
|
-
|
|
88
|
+
var _loop = function _loop() {
|
|
89
|
+
var _options$ignoreKeys;
|
|
90
|
+
if ((_options$ignoreKeys = options.ignoreKeys) !== null && _options$ignoreKeys !== void 0 && _options$ignoreKeys.includes(key)) {
|
|
89
91
|
return "continue";
|
|
90
92
|
}
|
|
93
|
+
var next = value;
|
|
94
|
+
if (options.stripEmptyValue && (typeof next === 'string' ? next === '' : next.name === '' && next.size === 0)) {
|
|
95
|
+
// Set the value to undefined instead of skipping it
|
|
96
|
+
// to maintain the data structure
|
|
97
|
+
next = undefined;
|
|
98
|
+
}
|
|
91
99
|
setValue(data, key, prev => {
|
|
92
100
|
if (!prev) {
|
|
93
|
-
return
|
|
101
|
+
return next;
|
|
102
|
+
} else if (!next) {
|
|
103
|
+
return prev;
|
|
94
104
|
} else if (Array.isArray(prev)) {
|
|
95
|
-
return prev.concat(
|
|
105
|
+
return prev.concat(next);
|
|
96
106
|
} else {
|
|
97
|
-
return [prev,
|
|
107
|
+
return [prev, next];
|
|
98
108
|
}
|
|
99
109
|
});
|
|
100
110
|
};
|
|
101
111
|
for (var [key, value] of payload.entries()) {
|
|
102
|
-
var _ret = _loop(
|
|
112
|
+
var _ret = _loop();
|
|
103
113
|
if (_ret === "continue") continue;
|
|
104
114
|
}
|
|
105
115
|
return data;
|
package/formdata.mjs
CHANGED
|
@@ -78,24 +78,34 @@ function setValue(target, name, valueFn) {
|
|
|
78
78
|
/**
|
|
79
79
|
* Resolves the payload into a plain object based on the JS syntax convention
|
|
80
80
|
*/
|
|
81
|
-
function resolve(payload
|
|
81
|
+
function resolve(payload) {
|
|
82
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
82
83
|
var data = {};
|
|
83
|
-
var _loop = function _loop(
|
|
84
|
-
|
|
84
|
+
var _loop = function _loop() {
|
|
85
|
+
var _options$ignoreKeys;
|
|
86
|
+
if ((_options$ignoreKeys = options.ignoreKeys) !== null && _options$ignoreKeys !== void 0 && _options$ignoreKeys.includes(key)) {
|
|
85
87
|
return "continue";
|
|
86
88
|
}
|
|
89
|
+
var next = value;
|
|
90
|
+
if (options.stripEmptyValue && (typeof next === 'string' ? next === '' : next.name === '' && next.size === 0)) {
|
|
91
|
+
// Set the value to undefined instead of skipping it
|
|
92
|
+
// to maintain the data structure
|
|
93
|
+
next = undefined;
|
|
94
|
+
}
|
|
87
95
|
setValue(data, key, prev => {
|
|
88
96
|
if (!prev) {
|
|
89
|
-
return
|
|
97
|
+
return next;
|
|
98
|
+
} else if (!next) {
|
|
99
|
+
return prev;
|
|
90
100
|
} else if (Array.isArray(prev)) {
|
|
91
|
-
return prev.concat(
|
|
101
|
+
return prev.concat(next);
|
|
92
102
|
} else {
|
|
93
|
-
return [prev,
|
|
103
|
+
return [prev, next];
|
|
94
104
|
}
|
|
95
105
|
});
|
|
96
106
|
};
|
|
97
107
|
for (var [key, value] of payload.entries()) {
|
|
98
|
-
var _ret = _loop(
|
|
108
|
+
var _ret = _loop();
|
|
99
109
|
if (_ret === "continue") continue;
|
|
100
110
|
}
|
|
101
111
|
return data;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A set of opinionated helpers built on top of the Constraint Validation API",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.7.
|
|
6
|
+
"version": "0.7.4",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
package/parse.d.ts
CHANGED
|
@@ -12,12 +12,14 @@ export declare function parse<Schema>(payload: FormData | URLSearchParams, optio
|
|
|
12
12
|
value?: Schema;
|
|
13
13
|
error?: Record<string, string | string[]>;
|
|
14
14
|
};
|
|
15
|
+
stripEmptyValue?: boolean;
|
|
15
16
|
}): Submission<Schema>;
|
|
16
17
|
export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
|
|
17
18
|
resolve?: (payload: Record<string, any>, intent: string) => Promise<{
|
|
18
19
|
value?: Schema;
|
|
19
20
|
error?: Record<string, string | string[]>;
|
|
20
21
|
}>;
|
|
22
|
+
stripEmptyValue?: boolean;
|
|
21
23
|
}): Promise<Submission<Schema>>;
|
|
22
24
|
export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
|
|
23
25
|
resolve?: (payload: Record<string, any>, intent: string) => {
|
|
@@ -27,4 +29,5 @@ export declare function parse<Schema>(payload: FormData | URLSearchParams, optio
|
|
|
27
29
|
value?: Schema;
|
|
28
30
|
error?: Record<string, string | string[]>;
|
|
29
31
|
}>;
|
|
32
|
+
stripEmptyValue?: boolean;
|
|
30
33
|
}): Submission<Schema> | Promise<Submission<Schema>>;
|
package/parse.js
CHANGED
|
@@ -11,7 +11,10 @@ var VALIDATION_SKIPPED = '__skipped__';
|
|
|
11
11
|
function parse(payload, options) {
|
|
12
12
|
var submission = {
|
|
13
13
|
intent: intent.getIntent(payload),
|
|
14
|
-
payload: formdata.resolve(payload,
|
|
14
|
+
payload: formdata.resolve(payload, {
|
|
15
|
+
ignoreKeys: [intent.INTENT],
|
|
16
|
+
stripEmptyValue: options === null || options === void 0 ? void 0 : options.stripEmptyValue
|
|
17
|
+
}),
|
|
15
18
|
error: {}
|
|
16
19
|
};
|
|
17
20
|
var intent$1 = intent.parseIntent(submission.intent);
|
package/parse.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { resolve, setValue } from './formdata.mjs';
|
|
3
|
-
import { getIntent, parseIntent, updateList
|
|
3
|
+
import { getIntent, INTENT, parseIntent, updateList } from './intent.mjs';
|
|
4
4
|
|
|
5
5
|
var VALIDATION_UNDEFINED = '__undefined__';
|
|
6
6
|
var VALIDATION_SKIPPED = '__skipped__';
|
|
7
7
|
function parse(payload, options) {
|
|
8
8
|
var submission = {
|
|
9
9
|
intent: getIntent(payload),
|
|
10
|
-
payload: resolve(payload,
|
|
10
|
+
payload: resolve(payload, {
|
|
11
|
+
ignoreKeys: [INTENT],
|
|
12
|
+
stripEmptyValue: options === null || options === void 0 ? void 0 : options.stripEmptyValue
|
|
13
|
+
}),
|
|
11
14
|
error: {}
|
|
12
15
|
};
|
|
13
16
|
var intent = parseIntent(submission.intent);
|