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.

validate.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _defaultConfig = _interopRequireDefault(require('./defaultConfig'));
  7. var _utils = require('./utils');
  8. function _interopRequireDefault(obj) {
  9. return obj && obj.__esModule ? obj : {default: obj};
  10. }
  11. /**
  12. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  13. *
  14. * This source code is licensed under the MIT license found in the
  15. * LICENSE file in the root directory of this source tree.
  16. */
  17. let hasDeprecationWarnings = false;
  18. const shouldSkipValidationForPath = (path, key, denylist) =>
  19. denylist ? denylist.includes([...path, key].join('.')) : false;
  20. const _validate = (config, exampleConfig, options, path = []) => {
  21. if (
  22. typeof config !== 'object' ||
  23. config == null ||
  24. typeof exampleConfig !== 'object' ||
  25. exampleConfig == null
  26. ) {
  27. return {
  28. hasDeprecationWarnings
  29. };
  30. }
  31. for (const key in config) {
  32. if (
  33. options.deprecatedConfig &&
  34. key in options.deprecatedConfig &&
  35. typeof options.deprecate === 'function'
  36. ) {
  37. const isDeprecatedKey = options.deprecate(
  38. config,
  39. key,
  40. options.deprecatedConfig,
  41. options
  42. );
  43. hasDeprecationWarnings = hasDeprecationWarnings || isDeprecatedKey;
  44. } else if (allowsMultipleTypes(key)) {
  45. const value = config[key];
  46. if (
  47. typeof options.condition === 'function' &&
  48. typeof options.error === 'function'
  49. ) {
  50. if (key === 'maxWorkers' && !isOfTypeStringOrNumber(value)) {
  51. throw new _utils.ValidationError(
  52. 'Validation Error',
  53. `${key} has to be of type string or number`,
  54. `maxWorkers=50% or\nmaxWorkers=3`
  55. );
  56. }
  57. }
  58. } else if (Object.hasOwnProperty.call(exampleConfig, key)) {
  59. if (
  60. typeof options.condition === 'function' &&
  61. typeof options.error === 'function' &&
  62. !options.condition(config[key], exampleConfig[key])
  63. ) {
  64. options.error(key, config[key], exampleConfig[key], options, path);
  65. }
  66. } else if (
  67. shouldSkipValidationForPath(path, key, options.recursiveDenylist)
  68. ) {
  69. // skip validating unknown options inside blacklisted paths
  70. } else {
  71. options.unknown &&
  72. options.unknown(config, exampleConfig, key, options, path);
  73. }
  74. if (
  75. options.recursive &&
  76. !Array.isArray(exampleConfig[key]) &&
  77. options.recursiveDenylist &&
  78. !shouldSkipValidationForPath(path, key, options.recursiveDenylist)
  79. ) {
  80. _validate(config[key], exampleConfig[key], options, [...path, key]);
  81. }
  82. }
  83. return {
  84. hasDeprecationWarnings
  85. };
  86. };
  87. const allowsMultipleTypes = key => key === 'maxWorkers';
  88. const isOfTypeStringOrNumber = value =>
  89. typeof value === 'number' || typeof value === 'string';
  90. const validate = (config, options) => {
  91. hasDeprecationWarnings = false; // Preserve default denylist entries even with user-supplied denylist
  92. const combinedDenylist = [
  93. ...(_defaultConfig.default.recursiveDenylist || []),
  94. ...(options.recursiveDenylist || [])
  95. ];
  96. const defaultedOptions = Object.assign({
  97. ..._defaultConfig.default,
  98. ...options,
  99. recursiveDenylist: combinedDenylist,
  100. title: options.title || _defaultConfig.default.title
  101. });
  102. const {hasDeprecationWarnings: hdw} = _validate(
  103. config,
  104. options.exampleConfig,
  105. defaultedOptions
  106. );
  107. return {
  108. hasDeprecationWarnings: hdw,
  109. isValid: true
  110. };
  111. };
  112. var _default = validate;
  113. exports.default = _default;