@ikasoba000/kensho-ts
v0.1.0
Published
<h1> <p align="center"> <i>⚡kensho-ts⚡</i> </p> </h1>
Downloads
2
Readme
about
kensho-ts
is a small validator for TypeScript compatible with JSONSchema.
example
import {
$object,
$opt,
$regexp,
$string,
createValidator,
Infer,
} from "https://esm.sh/gh/ikasoba/[email protected]/mod.ts";
const UserSchema = $object({
id: $string,
name: $regexp(/^[a-zA-Z0-9_-]+$/),
displayName: $opt($string),
});
// {
// type: "object",
// properties: {
// id: { type: "string" },
// name: { type: "string", pattern: "^[a-zA-Z0-9_-]+$" },
// displayName: { type: "string", required: false }
// }
// }
type User = Infer<typeof UserSchema>;
// {
// id: string;
// name: string;
// displayName?: string | undefined;
// }
// type User = Infer<typeof UserSchema, /* strict flag */ true>;
// // {
// // id: string;
// // name: ParsedString<RegExp>;
// // displayName?: string | undefined;
// // }
const validateUser = createValidator(UserSchema);
validateUser({
id: "abcdef1234567890",
name: "ikasoba",
} as User);