@newdash/newdash
Version:
javascript/typescript utility library
43 lines (42 loc) • 1.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchesProperty = void 0;
// @ts-nocheck
const baseClone_1 = __importDefault(require("./.internal/baseClone"));
const baseMatchesProperty_1 = __importDefault(require("./.internal/baseMatchesProperty"));
/** Used to compose bitmasks for cloning. */
const CLONE_DEEP_FLAG = 1;
/**
* Creates a function that performs a partial deep comparison between the
* value at `path` of a given object to `srcValue`, returning `true` if the
* object value is equivalent, else `false`.
*
* **Note:** Partial comparisons will match empty array and empty object
* `srcValue` values against any array or object value, respectively. See
* `isEqual` for a list of supported value comparisons.
*
* @since 5.11.0
* @category Util
* @param path The path of the property to get.
* @param srcValue The value to match.
* @returns {Function} Returns the new spec function.
* @example
*
* ```js
* const objects = [
* { 'a': 1, 'b': 2, 'c': 3 },
* { 'a': 4, 'b': 5, 'c': 6 }
* ]
*
* find(objects, matchesProperty('a', 4))
* // => { 'a': 4, 'b': 5, 'c': 6 }
* ```
*/
function matchesProperty(path, srcValue) {
return (0, baseMatchesProperty_1.default)(path, (0, baseClone_1.default)(srcValue, CLONE_DEEP_FLAG));
}
exports.matchesProperty = matchesProperty;
exports.default = matchesProperty;