blob: 8598e5c2f1edb6ea3b83ec1cbbf230ab9d9e5d4d [file] [log] [blame]
import { isPlainObject } from './validateTypes.mjs';
/**
* Check whether the variable is an object and all its properties agree with the provided validator.
*
* @example
* config = {
* value1: 1,
* value2: 2,
* value3: 3,
* };
* validateObjectWithProps(isNumber)(config);
* //=> true
*
* @param {(value: unknown) => boolean} validator
* @returns {(value: unknown) => boolean}
*/
export default function validateObjectWithProps(validator) {
return (value) => {
if (!isPlainObject(value)) {
return false;
}
return Object.values(value).every((item) => {
return validator(item);
});
};
}