UNPKG

shapeit

Version:

Object validation tools for Javascript and, specially, Typescript

20 lines (19 loc) 589 B
import { GuardSchema, ShapeGuard, UnshapeSchema } from '../types/guards'; /** * Makes a guard for an object. Types can be specified with other guards or * primitive names. * * @example * const isValidData = shape({ * name: 'string', * emails: arrayOf('string') * }); * * if (isValidData(input)) { * doSomethingWith(input); // input is typed as { name: string, emails: string[] } * } * else { * console.error(isValidData.errors); // Errors found * } */ export default function shape<V extends GuardSchema>(schema: V, strict?: boolean): ShapeGuard<UnshapeSchema<V>>;