enumwaii

Schemas and adapters

Use native Standard Schema support or opt into Zod, Valibot, and nuqs entry points.

Standard Schema is the default

An enumwaii declaration is already a Standard Schema v1 schema. Pass the declaration itself to a compatible library; no wrapper or adapter is necessary.

Start with Standard Schema

Standard Schema integrations accept the enumwaii declaration directly. Add Zod or Valibot when the receiving API requires that library's schema type.

const  = (["ADMIN", "USER"]);

.("role", );
.();

Enumwaii uses the official StandardSchemaV1 type from @standard-schema/spec, but does not re-export it. Import the type from the official package when authoring a generic Standard Schema integration:

import type {  } from "@standard-schema/spec";

The spec package is a regular enumwaii dependency because its type appears in enumwaii's public declarations. It contributes no validation runtime of its own. Applications that name the type in their own source should also declare the spec package directly instead of relying on a transitive dependency.

@standard-schema/utils is not required by enumwaii. It is useful to authors of generic Standard Schema tooling, but adding it to the runtime package would not improve declaration validation or the consumer API.

Library-specific adapters

Choose the adapter required by the surrounding API. The package-manager choice is shared with every other install command in these docs.

Install Zod for APIs that require a Zod schema:

npm install zod
import {  } from "zod";
import {  } from "enumwaii";
import {  } from "enumwaii/zod";

const  = (["ADMIN", "USER"]);
const  = .({
  : (),
});

const  = .();
// input.role is the branded enumwaii member union

The adapter follows Zod's normal parse and error behavior while preserving the branded output type.

Both library adapters are separate package entry points and both validator packages are optional peers. Applications that use only Standard Schema do not load either integration.

nuqs query parsers

Install nuqs when URL query state should use enumwaii's validation and branded member type:

npm install nuqs

For a shared default, create the parser beside the declaration and export both:

import {  } from "enumwaii";
import {  } from "enumwaii/nuqs";

export const  = (["ADMIN", "USER"]);
export const  = .;
export type  = (typeof )["~type"];
export const  = (, .);

When the default depends on component state or props, create it inside the component:

import {  } from "nuqs";
import {  } from "enumwaii";
import {  } from "enumwaii/nuqs";

const  = (["ADMIN", "USER"]);
const  = .;
type  = (typeof )["~type"];

export function ({  }: { :  }) {
  const  = (, );
  const [, ] = ("role", );

  return < ={() => (.)}>{}</>;
}

The parser returns null for invalid query strings as required by nuqs, applies the supplied owned member as its default, and serializes members as their raw string value. The enumwaii/nuqs entry point and nuqs peer are optional; applications that do not import it do not load nuqs.

On this page