Skip to content

Mampfinator/morphize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 }

About

Zod-inspired object remapping library.

Resources

Stars

Watchers

Forks

Packages

No packages published