updeep/src/matches.ts
2023-01-10 12:30:40 -05:00

16 lines
367 B
TypeScript

import { purry } from "remeda";
function matches(target, condition) {
if (typeof condition === "function") return condition(target);
if (typeof condition === "object") {
return Object.entries(condition).every(([key, value]) =>
matches(target[key], value)
);
}
return target === condition;
}
export default (...args) => purry(matches, args);