4
0

validateObjectWithProps.cjs 823 B

12345678910111213141516171819202122232425262728293031323334
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const validateTypes = require('./validateTypes.cjs');
  5. /**
  6. * Check whether the variable is an object and all its properties agree with the provided validator.
  7. *
  8. * @example
  9. * config = {
  10. * value1: 1,
  11. * value2: 2,
  12. * value3: 3,
  13. * };
  14. * validateObjectWithProps(isNumber)(config);
  15. * //=> true
  16. *
  17. * @param {(value: unknown) => boolean} validator
  18. * @returns {(value: unknown) => boolean}
  19. */
  20. function validateObjectWithProps(validator) {
  21. return (value) => {
  22. if (!validateTypes.isPlainObject(value)) {
  23. return false;
  24. }
  25. return Object.values(value).every((item) => {
  26. return validator(item);
  27. });
  28. };
  29. }
  30. module.exports = validateObjectWithProps;