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