updeep/src/matches.ts

16 lines
367 B
TypeScript
Raw Normal View History

2023-01-10 17:30:40 +00:00
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);