UNPKG

beater-matcher

Version:
50 lines (27 loc) 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.partialObject = exports.matchString = exports.anyString = exports.anyObject = exports.anyNumber = exports.anyFunction = exports.anyBoolean = exports.anyBigInt = exports.anyArray = exports.any = void 0; var _helper = require("./helper"); var _matcher = require("./matcher"); const any = () => (0, _matcher.defineMatcher)(_ => true); exports.any = any; const anyArray = () => (0, _matcher.defineMatcher)(value => Array.isArray(value)); exports.anyArray = anyArray; const anyBigInt = () => (0, _matcher.defineMatcher)(value => typeof value === "bigint"); exports.anyBigInt = anyBigInt; const anyBoolean = () => (0, _matcher.defineMatcher)(value => typeof value === "boolean"); exports.anyBoolean = anyBoolean; const anyFunction = () => (0, _matcher.defineMatcher)(value => typeof value === "function"); exports.anyFunction = anyFunction; const anyNumber = () => (0, _matcher.defineMatcher)(value => typeof value === "number"); exports.anyNumber = anyNumber; const anyObject = () => (0, _matcher.defineMatcher)(value => (0, _helper.isObject)(value)); exports.anyObject = anyObject; const anyString = () => (0, _matcher.defineMatcher)(value => typeof value === "string"); exports.anyString = anyString; const matchString = regexp => (0, _matcher.defineMatcher)(value => typeof value === "string" && value.match(regexp) !== null); exports.matchString = matchString; const partialObject = o => (0, _matcher.defineMatcher)(value => (0, _helper.isObject)(value) && (0, _helper.isObject)(o) && Object.entries(o).every(([k, v]) => (0, _matcher.match)(value[k], v))); exports.partialObject = partialObject;