UNPKG

stnl

Version:

A simple, opinionated type validator built for performance

53 lines (52 loc) 1.23 kB
import type { TFloat, TInt, TString } from "./type.js"; export interface Limit<I extends number = number> { [0]: I; 1: any; } /** * Set minimum value for a number * @param n */ export declare const min: (n: number) => LMin; export type LMin = Limit<0>; /** * Set maximum value for a number * @param n */ export declare const max: (n: number) => LMax; export type LMax = Limit<1>; /** * Set minimum length for a string or array * @param n */ export declare const minLen: (n: number) => LMinLen; export type LMinLen = Limit<2>; /** * Set maximum length for a string or array * @param n */ export declare const maxLen: (n: number) => LMaxLen; export type LMaxLen = Limit<3>; /** * Set constant length for a string or array * @param n */ export declare const len: (n: number) => LConstLen; export type LConstLen = Limit<4>; export type LLen = LMinLen | LMaxLen | LConstLen; export type LNumber = LMin | LMax; /** * Create an integer type with limits * @param a */ export declare const int: (...a: LNumber[]) => TInt; /** * Create a float type with limits * @param a */ export declare const float: (...a: LNumber[]) => TFloat; /** * Create a string type with limits * @param a */ export declare const string: (...a: LLen[]) => TString;