source: node_modules/es-toolkit/dist/compat/predicate/matchesProperty.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 918 bytes
RevLine 
[a762898]1import { isMatch } from './isMatch.mjs';
2import { toKey } from '../_internal/toKey.mjs';
3import { cloneDeep } from '../object/cloneDeep.mjs';
4import { get } from '../object/get.mjs';
5import { has } from '../object/has.mjs';
6
7function matchesProperty(property, source) {
8 switch (typeof property) {
9 case 'object': {
10 if (Object.is(property?.valueOf(), -0)) {
11 property = '-0';
12 }
13 break;
14 }
15 case 'number': {
16 property = toKey(property);
17 break;
18 }
19 }
20 source = cloneDeep(source);
21 return function (target) {
22 const result = get(target, property);
23 if (result === undefined) {
24 return has(target, property);
25 }
26 if (source === undefined) {
27 return result === undefined;
28 }
29 return isMatch(result, source);
30 };
31}
32
33export { matchesProperty };
Note: See TracBrowser for help on using the repository browser.