UNPKG

object-shape-tester

Version:
31 lines (30 loc) 933 B
export { Kind } from '@sinclair/typebox'; /** * Easily create a custom shape. * * @category Shape * @example * * ```ts * import {checkValidShape, createCustomShape} from 'object-shape-tester'; * import {UtcIsoString, isValidIsoString} from 'date-vir'; * * const utcIsoStringShape = createCustomShape({ * default: new Date().toISOString() as UtcIsoString, * name: 'UtcIsoString', * checkValue(value) { * return isValidIsoString(value); * }, * }); * * const myShape = utcIsoStringShape(); * * checkValidShape(new Date().toISOString(), myShape); // `true` * checkValidShape('', myShape); // `false` * ``` */ export declare function createCustomShape<T>({ checkValue, default: outerDefaultValue, name, }: { default: T; name: string; checkValue: (value: unknown) => value is T; }): (defaultValue?: T) => import("../shape/shape.js").Shape<import("@sinclair/typebox").TUnsafe<T>>;