severity.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import * as strings from './strings.js';
  6. var Severity;
  7. (function (Severity) {
  8. Severity[Severity["Ignore"] = 0] = "Ignore";
  9. Severity[Severity["Info"] = 1] = "Info";
  10. Severity[Severity["Warning"] = 2] = "Warning";
  11. Severity[Severity["Error"] = 3] = "Error";
  12. })(Severity || (Severity = {}));
  13. (function (Severity) {
  14. const _error = 'error';
  15. const _warning = 'warning';
  16. const _warn = 'warn';
  17. const _info = 'info';
  18. const _ignore = 'ignore';
  19. /**
  20. * Parses 'error', 'warning', 'warn', 'info' in call casings
  21. * and falls back to ignore.
  22. */
  23. function fromValue(value) {
  24. if (!value) {
  25. return Severity.Ignore;
  26. }
  27. if (strings.equalsIgnoreCase(_error, value)) {
  28. return Severity.Error;
  29. }
  30. if (strings.equalsIgnoreCase(_warning, value) || strings.equalsIgnoreCase(_warn, value)) {
  31. return Severity.Warning;
  32. }
  33. if (strings.equalsIgnoreCase(_info, value)) {
  34. return Severity.Info;
  35. }
  36. return Severity.Ignore;
  37. }
  38. Severity.fromValue = fromValue;
  39. function toString(severity) {
  40. switch (severity) {
  41. case Severity.Error: return _error;
  42. case Severity.Warning: return _warning;
  43. case Severity.Info: return _info;
  44. default: return _ignore;
  45. }
  46. }
  47. Severity.toString = toString;
  48. })(Severity || (Severity = {}));
  49. export default Severity;