@treasured/zod-to-leva-schema
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

zod-to-leva-schema

Converts a typed schema written in Zod into a schema that can be used by Leva.

We use this library in the Treasured player to easily modify portions of the level schema for debugging purposes.

Usage

Imagine we have the following schema written in Zod:

import { z } from "zod";

const FeaturesSchema = z.object({
  matterportStyleNavigation: z.boolean().default(true),
  guidedTour: z.boolean().default(false),
});

We can convert this into the equivalent schema in Leva:

import zodToLevaSchema from "@treasured/zod-to-leva-schema";
import { useControls } from "leva";

const levaSchema = zodToLevaSchema(FeaturesSchema);

and levaSchema will be:

{
    matterportStyleNavigation: {
        type: "boolean",
        value: false,
    },
    guidedTour: {
        type: "boolean",
        value: false,
    },
}

Readme

Keywords

none

Package Sidebar

Install

npm i @treasured/zod-to-leva-schema

Weekly Downloads

0

Version

0.0.8

License

none

Unpacked Size

19.2 kB

Total Files

5

Last publish

Collaborators

  • umarahmed
  • nikitavr