UNPKG

postel-ita

Version:

Library to create files compatible with italian Poste Postel system

18 lines 742 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringOfLength = void 0; // This is a type guard function which can be used to assert that a string // is of type StringOfLength<Min,Max> const isStringOfLength = (str, min, max) => str.length >= min && str.length <= max; // type constructor function const stringOfLength = (input, min, max) => { if (typeof input !== 'string') { throw new Error('invalid input'); } if (!isStringOfLength(input, min, max)) { throw new Error('input is not between specified min and max'); } return input; // the type of input here is now StringOfLength<Min,Max> }; exports.stringOfLength = stringOfLength; //# sourceMappingURL=types.js.map