UNPKG

object-shape-tester

Version:
42 lines (41 loc) 1.33 kB
import { type MinMax, type PartialWithUndefined } from '@augment-vir/common'; import { type TUnsafe } from '@sinclair/typebox'; import { type Shape } from '../shape/shape.js'; /** * Parameters for {@link rangeShape}. * * @category Internal */ export type RangeShapeParams = MinMax & PartialWithUndefined<{ /** * If set to `true`, the `max` is exclusive (all values must be below the max). * * @default false */ exclusiveMax: boolean; /** * If set to `true`, the `min` is exclusive (all values must be above the min). * * @default false */ exclusiveMin: boolean; /** The shape's default value. If not provided, a value in between min and max is chosen. */ default: number; }>; /** * Creates a shape that requires a number within the given range. By default, the range is * inclusive. See {@link RangeShapeParams} for how to change that. * * @category Shape * @example * * ```ts * import {rangeShape, checkValidShape} from 'object-shape-tester'; * * const myShape = rangeShape({min: 1, max: 10}); * * checkValidShape(1, myShape); // `true` * checkValidShape(0, myShape); // `false` * ``` */ export declare function rangeShape<const T extends number = number>({ exclusiveMax, exclusiveMin, ...params }: Readonly<RangeShapeParams>): Shape<TUnsafe<T>>;