Package Exports
- stnl
- stnl/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stnl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Stnl
A JSON validator format.
import stnl, { type InferSchema } from 'stnl';
// A wrapper for type autocomplete
export const User = stnl({
props: {
name: {
type: 'string',
minLength: 3
},
age: 'int',
pwd: {
type: 'string',
minLength: 8,
maxLength: 16
}
}
});
export type User = InferSchema<typeof User>;Compilers
stnl has compilers to compile the schema to other utilities.
Assert
To JIT compile a schema to an assert function with code generation:
import { build } from 'stnl/compilers/validate-json';
import type { InferSchema, TSchema } from 'stnl';
const isUser = build(User);
isUser({ name: 'reve', age: 16, pwd: 'revenode' }); // trueTo compile a schema to an assert function without code generation:
import build from 'stnl/compilers/validate-json/compose';
const isUser = build(User);
isUser({ name: 'reve', age: 16, pwd: 'revenode' }); // trueStringify
To JIT compile a schema to a JSON stringifier with code generation:
import { build } from 'stnl/compilers/stringify-json';
import type { InferSchema, TSchema } from 'stnl';
const stringifyUser = build(User);
stringifyUser({ name: 'reve', age: 16, pwd: 'revenode' });To compile a schema to a JSON stringifier without code generation:
import build from 'stnl/compilers/stringify-json/compose';
const isUser = build(User);
isUser({ name: 'reve', age: 16, pwd: 'revenode' }); // true