Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validateObjectWithArrayProps.js 898B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const _ = require('lodash');
  3. /**
  4. * @template T
  5. * @typedef {(i: T) => boolean} Validator
  6. */
  7. /**
  8. * Check whether the variable is an object and all it's properties are arrays of string values:
  9. *
  10. * ignoreProperties = {
  11. * value1: ["item11", "item12", "item13"],
  12. * value2: ["item21", "item22", "item23"],
  13. * value3: ["item31", "item32", "item33"],
  14. * }
  15. * @template T
  16. * @param {Validator<T>|Validator<T>[]} validator
  17. * @returns {(value: {[k: any]: T|T[]}) => boolean}
  18. */
  19. module.exports = (validator) => (value) => {
  20. if (!_.isPlainObject(value)) {
  21. return false;
  22. }
  23. return Object.values(value).every((array) => {
  24. if (!Array.isArray(array)) {
  25. return false;
  26. }
  27. // Make sure the array items are strings
  28. return array.every((item) => {
  29. if (Array.isArray(validator)) {
  30. return validator.some((v) => v(item));
  31. }
  32. return validator(item);
  33. });
  34. });
  35. };