UNPKG

tiny-types

Version:

A tiny library that brings Tiny Types to JavaScript and TypeScript

27 lines 758 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.startsWith = startsWith; const Predicate_1 = require("./Predicate"); /** * @desc Ensures that the `value` starts with a given prefix. * * @example * import { ensure, startsWith, TinyType } from 'tiny-types'; * * class Username extends TinyType { * constructor(public readonly value: string) { * super(); * * ensure('Username', value, startsWith('usr')); * } * } * * @param {string} prefix * * @returns {Predicate<string>} */ function startsWith(prefix) { return Predicate_1.Predicate.to(`start with '${prefix}'`, (value) => typeof value === 'string' && value.startsWith(prefix)); } //# sourceMappingURL=startsWith.js.map