Object Reshaper
![Known Vulnerabilities](https://snyk.io/test/github/dextertanyj/object-reshaper/badge.svg)
TypeScript-first schema-based object transformation.
Installation
Requirements
$ npm install object-reshaper
Basic Usage
Renaming property names
import { reshaperBuilder, Schema } from "object-reshaper";
type Input = {
id: number;
};
const schema = {
new: "id",
} as const satisfies Schema<Input>;
const reshaper = reshaperBuilder<Input, typeof schema>(schema);
reshaper({ id: 1 });
Extracting nested properties
import { reshaperBuilder, Schema } from "object-reshaper";
type Input = {
user: {
address: {
street: string;
};
};
};
const schema = {
street: "user.address.street",
} as const satisfies Schema<Input>;
const reshaper = reshaperBuilder<Input, typeof schema>(schema);
reshaper({ user: { address: { street: "home" } } });