Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 915 Bytes

README.md

File metadata and controls

48 lines (37 loc) · 915 Bytes

Morphize

A (work in progress) Zod-inspired object transform & remapping library with static type inference.

Usage

import { m } from "morphize";

const schema = m.object({
    example: m.object({
        foo: m.to("bar"),
        test_status: m.enum([0, 1, 2], ["Success", "Pending", "Failed"]).to("testStatus")
    }).to("somewhereElse"),
});

const example = schema.map({
    example: {
        foo: "c:",
        test_status: 0,
    }
});

// returns: 
//{
//    somewhereElse: {
//        bar: "c:",
//        testStatus: "Success"
//    }
//}

For type inference, simply use m.infer<TSchema, TInput>:

import { m } from "morphize";

const TestSchema = m.object({
    test: m.to("tested"),
});

type Input = {
    test: string,
    unaffected: boolean
}

type Test = m.infer<typeof TestSchema, Input>; // { tested: string, unaffected: boolean }