@conform-to/dom
Advanced tools
Comparing version
@@ -31,3 +31,6 @@ /** | ||
*/ | ||
export declare function resolve(payload: FormData | URLSearchParams, ignoreKeys?: string[]): {}; | ||
export declare function resolve(payload: FormData | URLSearchParams, options?: { | ||
ignoreKeys?: string[]; | ||
stripEmptyValue?: boolean; | ||
}): {}; | ||
/** | ||
@@ -34,0 +37,0 @@ * Format the error messages into a validation message |
@@ -85,15 +85,25 @@ 'use strict'; | ||
*/ | ||
function resolve(payload, ignoreKeys) { | ||
function resolve(payload) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var data = {}; | ||
var _loop = function _loop(value) { | ||
if (ignoreKeys !== null && ignoreKeys !== void 0 && ignoreKeys.includes(key)) { | ||
var _loop = function _loop() { | ||
var _options$ignoreKeys; | ||
if ((_options$ignoreKeys = options.ignoreKeys) !== null && _options$ignoreKeys !== void 0 && _options$ignoreKeys.includes(key)) { | ||
return "continue"; | ||
} | ||
var next = value; | ||
if (options.stripEmptyValue && (typeof next === 'string' ? next === '' : next.name === '' && next.size === 0)) { | ||
// Set the value to undefined instead of skipping it | ||
// to maintain the data structure | ||
next = undefined; | ||
} | ||
setValue(data, key, prev => { | ||
if (!prev) { | ||
return value; | ||
return next; | ||
} else if (!next) { | ||
return prev; | ||
} else if (Array.isArray(prev)) { | ||
return prev.concat(value); | ||
return prev.concat(next); | ||
} else { | ||
return [prev, value]; | ||
return [prev, next]; | ||
} | ||
@@ -103,3 +113,3 @@ }); | ||
for (var [key, value] of payload.entries()) { | ||
var _ret = _loop(value); | ||
var _ret = _loop(); | ||
if (_ret === "continue") continue; | ||
@@ -106,0 +116,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"main": "index.js", | ||
@@ -9,0 +9,0 @@ "module": "index.mjs", |
@@ -15,2 +15,3 @@ export type Submission<Schema = any> = { | ||
}; | ||
stripEmptyValue?: boolean; | ||
}): Submission<Schema>; | ||
@@ -22,2 +23,3 @@ export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: { | ||
}>; | ||
stripEmptyValue?: boolean; | ||
}): Promise<Submission<Schema>>; | ||
@@ -32,2 +34,3 @@ export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: { | ||
}>; | ||
stripEmptyValue?: boolean; | ||
}): Submission<Schema> | Promise<Submission<Schema>>; |
@@ -14,3 +14,6 @@ 'use strict'; | ||
intent: intent.getIntent(payload), | ||
payload: formdata.resolve(payload, [intent.INTENT]), | ||
payload: formdata.resolve(payload, { | ||
ignoreKeys: [intent.INTENT], | ||
stripEmptyValue: options === null || options === void 0 ? void 0 : options.stripEmptyValue | ||
}), | ||
error: {} | ||
@@ -17,0 +20,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43332
3.11%1198
2.74%