UNPKG

object-shape-tester

Version:
28 lines (27 loc) 979 B
import { type Values } from '@augment-vir/common'; import { type TConst } from '@sinclair/typebox'; import { type ShapeInitSchema } from '../shape/shape.js'; /** * Creates a shape that requires matching a value within the given enum. * * @category Shape * @example * * ```ts * import {enumShape, checkValidShape} from 'object-shape-tester'; * * enum MyEnum { * A = 'a', * B = 'b', * } * * const myShape = enumShape(MyEnum); * * checkValidShape(MyEnum.A, myShape); // `true` * checkValidShape('a', myShape); // `true` * checkValidShape('c', myShape); // `false` * ``` */ export declare function enumShape<const EnumObject extends Record<string, number | string>>(enumObject: EnumObject, /** If omitted or `undefined`, the first value in the enum object will be used as the default. */ defaultValue?: Values<EnumObject> | undefined): import("../shape/shape.js").Shape<import("@sinclair/typebox").TUnion<ShapeInitSchema<TConst<Values<EnumObject>>>[]>>;