securityos/node_modules/stylelint/lib/utils/validateObjectWithProps.js

29 lines
592 B
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
'use strict';
const { isPlainObject } = require('./validateTypes');
/**
* 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}
*/
module.exports = (validator) => (value) => {
if (!isPlainObject(value)) {
return false;
}
return Object.values(value).every((item) => {
return validator(item);
});
};