validateObjectWithArrayProps.cjs 947 B

1234567891011121314151617181920212223242526272829303132333435
  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 are one or more values
  7. * that satisfy the specified validator(s):
  8. *
  9. * @example
  10. * ignoreProperties = {
  11. * value1: ["item11", "item12", "item13"],
  12. * value2: "item2",
  13. * };
  14. * validateObjectWithArrayProps(isString)(ignoreProperties);
  15. * //=> true
  16. *
  17. * @typedef {(value: unknown) => boolean} Validator
  18. * @param {...Validator} validators
  19. * @returns {Validator}
  20. */
  21. function validateObjectWithArrayProps(...validators) {
  22. return (value) => {
  23. if (!validateTypes.isPlainObject(value)) {
  24. return false;
  25. }
  26. return Object.values(value)
  27. .flat()
  28. .every((item) => validators.some((v) => v(item)));
  29. };
  30. }
  31. module.exports = validateObjectWithArrayProps;