zod-form-data
Advanced tools
Comparing version
@@ -49,34 +49,3 @@ "use strict"; | ||
}); | ||
// ../set-get/dist/index.esm.js | ||
var stringToPathArray = (path) => { | ||
if (path.length === 0) | ||
return []; | ||
const match = path.match(/^\[(.+?)\](.*)$/) || path.match(/^\.?([^\.\[\]]+)(.*)$/); | ||
if (match) { | ||
const [_, key, rest] = match; | ||
return [/^\d+$/.test(key) ? Number(key) : key, ...stringToPathArray(rest)]; | ||
} | ||
return [path]; | ||
}; | ||
function setPath(object, path, value) { | ||
const parts = Array.isArray(path) ? path : stringToPathArray(path); | ||
let obj = object; | ||
for (let i = 0; i < parts.length - 1; i++) { | ||
const part = parts[i]; | ||
const nextPart = parts[i + 1]; | ||
if (obj[part] === void 0) { | ||
if (typeof nextPart === "number") { | ||
obj[part] = []; | ||
} else { | ||
obj[part] = {}; | ||
} | ||
} | ||
obj = obj[part]; | ||
} | ||
obj[parts[parts.length - 1]] = value; | ||
return object; | ||
} | ||
// src/helpers.ts | ||
var import_set_get = require("@rvf/set-get"); | ||
var import_zod = require("zod"); | ||
@@ -147,3 +116,3 @@ var stripEmpty = import_zod.z.literal("").transform(() => void 0); | ||
(acc, [key, value]) => { | ||
return setPath(acc, key, value.length === 1 ? value[0] : value); | ||
return (0, import_set_get.setPath)(acc, key, value.length === 1 ? value[0] : value); | ||
}, | ||
@@ -150,0 +119,0 @@ {} |
{ | ||
"name": "zod-form-data", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"homepage": "https://github.com/airjp73/rvf/tree/main/packages/zod-form-data", | ||
@@ -27,2 +27,5 @@ "main": "./dist/index.js", | ||
}, | ||
"dependencies": { | ||
"@rvf/set-get": "^7.0.0" | ||
}, | ||
"peerDependencies": { | ||
@@ -29,0 +32,0 @@ "zod": ">= 3.11.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
45584
-17.19%2
100%555
-9.46%+ Added
+ Added