UNPKG

ts-prims

Version:
23 lines 815 B
/** Copyright 2025 by Stijn de Witt, some rights reserved */ import { Prim } from './prim.js'; import { charsConstraint } from './chars.js'; /** * The prim factory function for `varchar`. * * Returns the prim constructor for `varchar<N>`, based on the given `n`. * * ```ts * type zipcode = varchar<5> * const Zipcode = Varchar(5) * let zip: zipcode = Zipcode('90210') // ok * let oops: zipcode = Zipcode('Too long!') // runtime error * // TypeError: "Too long!" is not of type 'varchar<5>' * ``` * * @param n The max length for the varchar type. * Must be a positive integer number in the range `0` .. `256`. * * @returns The prim type constructor function for `varchar<N>` */ export const Varchar = (n) => Prim(`varchar<${n}>`, String, [charsConstraint(n)]); //# sourceMappingURL=varchar.js.map