tiny-types
Version:
A tiny library that brings Tiny Types to JavaScript and TypeScript
23 lines • 698 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isInstanceOf = isInstanceOf;
const Predicate_1 = require("./Predicate");
/**
* @desc Ensures that the `value` is an instance of `type`
*
* @example
* import { ensure, isInstanceOf, TinyType } from 'tiny-types';
*
* class Birthday extends TinyType {
* constructor(public readonly value: Date) {
* ensure('Date', value, isInstanceOf(Date));
* }
* }
*
* @param {Constructor<T>} type
* @returns {Predicate<T>}
*/
function isInstanceOf(type) {
return Predicate_1.Predicate.to(`be instance of ${type.name}`, (value) => value instanceof type);
}
//# sourceMappingURL=isInstanceOf.js.map