@monstermann/fn
Version:
A utility library for TypeScript.
25 lines (23 loc) • 740 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/object/testAll.ts
/**
* `testAll(target, props)`
*
* Checks if all properties in `target` object pass their corresponding predicate functions in `props` object.
*
* ```ts
* testAll({ a: 5, b: 2 }, { a: (x) => x > 3, b: (x) => x > 0 }); // true
* testAll({ a: 1, b: 2 }, { a: (x) => x > 3, b: (x) => x > 0 }); // false
* ```
*
* ```ts
* pipe({ a: 5, b: 2 }, testAll({ a: (x) => x > 3, b: (x) => x > 0 })); // true
* pipe({ a: 1, b: 2 }, testAll({ a: (x) => x > 3, b: (x) => x > 0 })); // false
* ```
*/
const testAll = dfdlT((target, props) => {
for (const key in props) if (!props[key](target[key], key, target)) return false;
return true;
}, 2);
//#endregion
export { testAll };