UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

24 lines (22 loc) 601 B
function conformsTo(target, source) { if (source == null) { return true; } if (target == null) { return Object.keys(source).length === 0; } const keys = Object.keys(source); for (let i = 0; i < keys.length; i++) { const key = keys[i]; const predicate = source[key]; const value = target[key]; if (value === undefined && !(key in target)) { return false; } if (typeof predicate === 'function' && !predicate(value)) { return false; } } return true; } export { conformsTo };