UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

64 lines (63 loc) 2.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Stack_1 = __importDefault(require("./Stack")); const baseIsEqual_1 = __importDefault(require("./baseIsEqual")); /** Used to compose bitmasks for value comparisons. */ const COMPARE_PARTIAL_FLAG = 1; const COMPARE_UNORDERED_FLAG = 2; /** * The base implementation of `isMatch`. * * @private * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. * @param {Array} matchData The property names, values, and compare flags to match. * @param {Function} [customizer] The function to customize comparisons. * @returns {boolean} Returns `true` if `object` is a match, else `false`. */ function baseIsMatch(object, source, matchData, customizer) { let index = matchData.length; const length = index; const noCustomizer = !customizer; if (object == null) { return !length; } let data; let result; object = Object(object); while (index--) { data = matchData[index]; if ((noCustomizer && data[2]) ? data[1] !== object[data[0]] : !(data[0] in object)) { return false; } } while (++index < length) { data = matchData[index]; const key = data[0]; const objValue = object[key]; const srcValue = data[1]; if (noCustomizer && data[2]) { if (objValue === undefined && !(key in object)) { return false; } } else { const stack = new Stack_1.default; if (customizer) { result = customizer(objValue, srcValue, key, object, source, stack); } if (!(result === undefined ? (0, baseIsEqual_1.default)(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) : result)) { return false; } } } return true; } exports.default = baseIsMatch;