@typed-web/form-utils
v0.2.1
Published
Shared utilities for form handling: path parsing, error conversion, and array diffing
Maintainers
Readme
@typed-web/form-utils
Utilities for form handling: path conversion, object flattening, and array diffing.
Installation
npm install @typed-web/form-utilsExports
Object Conversion
flatObjectToNestedObject- Convert flat objects to nested structuresnestedObjectToFlatObject- Convert nested objects to flat structures
Path Utilities
setValueAtPath- Set value at path in objectstringPathToArrayPath- Convert string path to arrayarrayPathToStringPath- Convert array path to string
Array Utilities
getArraysDiff- Compute differences between arrays
Types
FlatObject,NestedObject,GetArraysDiffArgs
Usage
import {
flatObjectToNestedObject,
stringPathToArrayPath,
setValueAtPath,
} from "@typed-web/form-utils";
// Convert flat to nested
const nested = flatObjectToNestedObject({
"user.name": "John",
"addresses[0].city": "NYC",
});
// { user: { name: "John" }, addresses: [{ city: "NYC" }] }
// Parse path
const path = stringPathToArrayPath("user.addresses[0].city");
// ["user", "addresses", 0, "city"]
// Set value at path
const obj = {};
setValueAtPath(obj, ["user", "name"], "John");
// { user: { name: "John" } }License
MIT
