checkConfigValid.js 893 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.checkConfigValid = void 0;
  4. const checkConfigMap = {
  5. endpoint: checkEndpoint,
  6. region: /^[a-zA-Z0-9\-_]+$/
  7. };
  8. function checkEndpoint(endpoint) {
  9. if (typeof endpoint === 'string') {
  10. return /^[a-zA-Z0-9._:/-]+$/.test(endpoint);
  11. }
  12. else if (endpoint.host) {
  13. return /^[a-zA-Z0-9._:/-]+$/.test(endpoint.host);
  14. }
  15. return false;
  16. }
  17. exports.checkConfigValid = (conf, key) => {
  18. if (checkConfigMap[key]) {
  19. let isConfigValid = true;
  20. if (checkConfigMap[key] instanceof Function) {
  21. isConfigValid = checkConfigMap[key](conf);
  22. }
  23. else {
  24. isConfigValid = checkConfigMap[key].test(conf);
  25. }
  26. if (!isConfigValid) {
  27. throw new Error(`The ${key} must be conform to the specifications`);
  28. }
  29. }
  30. };