ts-prims
Version:
Typescript Primitives
17 lines • 865 B
JavaScript
import { display } from './prim.js';
/** The lengths in chars of the short lengths */
export const shortLengthChars = [0, 64, 96, 128, 160, 192, 224, 256];
/** The lengths in chars of the medium lengths */
export const mediumLengthChars = [512, 1024, 2048, 4096];
/** The lengths in chars of the high lengths */
export const longLengthChars = [16384, 262144, 16777216, 4294967296];
/** The lengths in chars of all `Length`s */
export const lengthChars = [...shortLengthChars, ...mediumLengthChars, ...longLengthChars];
/** Generates a runtime constraint for length `l` */
export const lengthConstraint = (l) => {
const max = lengthChars[l];
return (pc, v) => (typeof v == 'string') && (v.length <= max) ? undefined :
`${display(v)} is not assignable to '${pc.name}'.\n` +
` Length exceeds ${max}.`;
};
//# sourceMappingURL=length.js.map