@monstermann/fn
Version:
A utility library for TypeScript.
25 lines (23 loc) • 638 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/object/matches.ts
/**
* `matches(target, props)`
*
* Checks if all properties in `props` object have equal values in `target` object.
*
* ```ts
* matches({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 }); // true
* matches({ a: 1, b: 2, c: 3 }, { a: 1, b: 3 }); // false
* ```
*
* ```ts
* pipe({ a: 1, b: 2, c: 3 }, matches({ a: 1, b: 2 })); // true
* pipe({ a: 1, b: 2, c: 3 }, matches({ a: 1, b: 3 })); // false
* ```
*/
const matches = dfdlT((target, props) => {
for (const key in props) if (target[key] !== props[key]) return false;
return true;
}, 2);
//#endregion
export { matches };