0.1.2 • Published 1 year ago

morphize v0.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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 }
0.1.2

1 year ago

0.1.1

1 year ago