import { Predicate } from './Predicate.js'; /** * @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} */ export function matches(expression: RegExp): Predicate { return Predicate.to(`match pattern ${ expression }`, (value: string) => expression.test(value)); }