Skip to main content
Home
Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads2/wk
Published4 days ago (0.4.0)

a just-in-time function compilation-based typescript data validation library

justin

a runtime type info library with just-in-time compilation for type validation and deep equality.

available on jsr.io.

features

  • dependency-free
  • small bundle size (pay for what you use, ranges from sub-1kb to 4kb)
  • low-allocation design of generated functions
  • much faster than validation via interpreting schema objects

limitations

  • since all checks are inlined, we do not support circular schemas
    • you probably want to use j.unknown and reapply the validator function to the member object
  • transformation is not supported since we return the exact same object that was passed in
  • compilation is very slow, so ad-hoc construction of schemata is considered an anti-pattern

example

import * as j from "@char/justin";

const PersonSchema = j.obj({
  fullName: j.string,
  preferredName: j.string,
  i18nInflection: j.optional(
    j.union(j.literal("masculine"), j.literal("feminine"), j.literal("neutral")),
  ),
});

type Person = j.Infer<typeof PersonSchema>;
/* ⇒ {
    fullName: string;
    preferredName: string;
    i18nInflection?: "masculine" | "feminine" | "neutral" | undefined;
} */

const validator = j.validation.compile(PersonSchema);
const { value: person, errors: personErrors } = validator({
  fullName: "Guy Jones",
  preferredName: "guy",
  i18nInflection: "masculine",
});
// person: passed through verbatim, personErrors: undefined

const { errors } = validator({
  fullName: "Guy Jones",
});
// errors: [ { path: ".preferredName", msg: "must be string" } ]

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@char/justin

Import symbol

import * as justin from "@char/justin";
or

Import directly with a jsr specifier

import * as justin from "jsr:@char/justin";

Add Package

pnpm i jsr:@char/justin
or (using pnpm 10.8 or older)
pnpm dlx jsr add @char/justin

Import symbol

import * as justin from "@char/justin";

Add Package

yarn add jsr:@char/justin
or (using Yarn 4.8 or older)
yarn dlx jsr add @char/justin

Import symbol

import * as justin from "@char/justin";

Add Package

vlt install jsr:@char/justin

Import symbol

import * as justin from "@char/justin";

Add Package

npx jsr add @char/justin

Import symbol

import * as justin from "@char/justin";

Add Package

bunx jsr add @char/justin

Import symbol

import * as justin from "@char/justin";