UNPKG

tiny-types

Version:

A tiny library that brings Tiny Types to JavaScript and TypeScript

26 lines 773 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isOneOf = isOneOf; const isEqualTo_1 = require("./isEqualTo"); const or_1 = require("./or"); /** * @desc Ensures that the `value` is equal to one of the `allowedValues` * * @example * import { ensure, isOneOf, TinyType } from 'tiny-types'; * * class StreetLight extends TinyType { * constructor(public readonly value: string) { * super(); * * ensure('StreetLight', value, isOneOf('red', 'yellow', 'green')); * } * } * * @param {...T[]} allowedValues * @returns {Predicate<T>} */ function isOneOf(...allowedValues) { return (0, or_1.or)(...allowedValues.map(allowed => (0, isEqualTo_1.isEqualTo)(allowed))); } //# sourceMappingURL=isOneOf.js.map