UNPKG

tiny-types

Version:

A tiny library that brings Tiny Types to JavaScript and TypeScript

26 lines 749 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matches = matches; const Predicate_1 = require("./Predicate"); /** * @desc Ensures that the `value` matches {@link RegExp}. * * @example * import { ensure, matches, TinyType } from 'tiny-types'; * * * class CompanyEmailAddress extends TinyType { * constructor(public readonly value: string) { * super(); * ensure('EmailAddress', value, matches(/[a-z]+\.[a-z]+@example\.org/)); * } * } * * @param {RegExp} expression * * @returns {Predicate<string>} */ function matches(expression) { return Predicate_1.Predicate.to(`match pattern ${expression}`, (value) => expression.test(value)); } //# sourceMappingURL=matches.js.map