@newdash/newdash
Version:
javascript/typescript utility library
37 lines (36 loc) • 1.64 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const baseIsEqual_1 = __importDefault(require("./baseIsEqual"));
const get_1 = __importDefault(require("../get"));
const hasIn_1 = __importDefault(require("../hasIn"));
const isKey_1 = __importDefault(require("./isKey"));
const isStrictComparable_1 = __importDefault(require("./isStrictComparable"));
const matchesStrictComparable_1 = __importDefault(require("./matchesStrictComparable"));
const toKey_1 = __importDefault(require("./toKey"));
/** Used to compose bitmasks for value comparisons. */
const COMPARE_PARTIAL_FLAG = 1;
const COMPARE_UNORDERED_FLAG = 2;
/**
* The base implementation of `matchesProperty` which doesn't clone `srcValue`.
*
* @private
* @ignore
* @param {string} path The path of the property to get.
* @param {*} srcValue The value to match.
* @returns {Function} Returns the new spec function.
*/
function baseMatchesProperty(path, srcValue) {
if ((0, isKey_1.default)(path) && (0, isStrictComparable_1.default)(srcValue)) {
return (0, matchesStrictComparable_1.default)((0, toKey_1.default)(path), srcValue);
}
return function (object) {
var objValue = (0, get_1.default)(object, path);
return (objValue === undefined && objValue === srcValue)
? (0, hasIn_1.default)(object, path)
: (0, baseIsEqual_1.default)(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
};
}
exports.default = baseMatchesProperty;