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.

stringifyValidator.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. export default function stringifyValidator(validator, nodePrefix) {
  2. if (validator === undefined) {
  3. return "any";
  4. }
  5. if (validator.each) {
  6. return `Array<${stringifyValidator(validator.each, nodePrefix)}>`;
  7. }
  8. if (validator.chainOf) {
  9. return stringifyValidator(validator.chainOf[1], nodePrefix);
  10. }
  11. if (validator.oneOf) {
  12. return validator.oneOf.map(JSON.stringify).join(" | ");
  13. }
  14. if (validator.oneOfNodeTypes) {
  15. return validator.oneOfNodeTypes.map(_ => nodePrefix + _).join(" | ");
  16. }
  17. if (validator.oneOfNodeOrValueTypes) {
  18. return validator.oneOfNodeOrValueTypes
  19. .map(_ => {
  20. return isValueType(_) ? _ : nodePrefix + _;
  21. })
  22. .join(" | ");
  23. }
  24. if (validator.type) {
  25. return validator.type;
  26. }
  27. if (validator.shapeOf) {
  28. return (
  29. "{ " +
  30. Object.keys(validator.shapeOf)
  31. .map(shapeKey => {
  32. const propertyDefinition = validator.shapeOf[shapeKey];
  33. if (propertyDefinition.validate) {
  34. const isOptional =
  35. propertyDefinition.optional || propertyDefinition.default != null;
  36. return (
  37. shapeKey +
  38. (isOptional ? "?: " : ": ") +
  39. stringifyValidator(propertyDefinition.validate)
  40. );
  41. }
  42. return null;
  43. })
  44. .filter(Boolean)
  45. .join(", ") +
  46. " }"
  47. );
  48. }
  49. return ["any"];
  50. }
  51. /**
  52. * Heuristic to decide whether or not the given type is a value type (eg. "null")
  53. * or a Node type (eg. "Expression").
  54. */
  55. function isValueType(type) {
  56. return type.charAt(0).toLowerCase() === type.charAt(0);
  57. }