Skip to content

gmh5225/justin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

justin

a typescript data validation library utilizing just-in-time function compilation.

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

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.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" } ]

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%