decode-formdata
Advanced tools
Comparing version 0.7.5 to 0.8.0
@@ -122,7 +122,23 @@ // src/regex.ts | ||
const [info, transform] = typeof arg2 === "function" ? [void 0, arg2] : [arg2, arg3]; | ||
if (info) { | ||
for (const key of [ | ||
"arrays", | ||
"booleans", | ||
"dates", | ||
"files", | ||
"numbers" | ||
]) { | ||
if (info[key]?.length) { | ||
info[key] = info[key].map( | ||
(templateName) => templateName.replace(/\[\$\]/g, ".$") | ||
); | ||
} | ||
} | ||
} | ||
const values = {}; | ||
for (const [path, input] of formData.entries()) { | ||
const templateName = path.replace(/\.\d+\./g, ".$.").replace(/\.\d+$/, ".$"); | ||
const normlizedPath = path.replace(/\[(\d+)\]/g, ".$1"); | ||
const templateName = normlizedPath.replace(/\.\d+\./g, ".$.").replace(/\.\d+$/, ".$"); | ||
const templateKeys = templateName.split("."); | ||
path.split(".").reduce((object, key, index, keys) => { | ||
normlizedPath.split(".").reduce((object, key, index, keys) => { | ||
if (index < keys.length - 1) { | ||
@@ -129,0 +145,0 @@ if (object[key]) { |
{ | ||
"name": "decode-formdata", | ||
"description": "Decodes complex FormData into a JavaScript object", | ||
"version": "0.7.5", | ||
"version": "0.8.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": "Fabian Hiller", |
@@ -34,4 +34,6 @@ # Decode FormData | ||
Another problem are objects and arrays, which are usually mapped using dot notation. For example, the input field `<input name="todos.0.label" />` should map to the object `{ todos: [{ label: "" }] }`. By telling `decode` where arrays, booleans, dates, files, and numbers are located, the function can decode your `FormData` back into a complex JavaScript object. | ||
Another problem are objects and arrays, which are usually mapped using dot and bracket notation. For example, the input field `<input name="todos.0.label" />` should map to the object `{ todos: [{ label: "" }] }`. By telling `decode` where arrays, booleans, dates, files, and numbers are located, the function can decode your `FormData` back into a complex JavaScript object. | ||
> Both dot and bracket notation are supported for arrays. | ||
Consider the following form to add a new product to an online store: | ||
@@ -178,1 +180,5 @@ | ||
This project is available free of charge and licensed under the [MIT license](https://github.com/fabian-hiller/decode-formdata/blob/main/LICENSE.md). | ||
## Note | ||
Both dot and bracket notation are supported for arrays. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26883
514
183