severity.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. // Note: Ideally the `SeverityLevel` type would be derived from `validSeverityLevels`, but that would mean either
  3. //
  4. // a) moving `validSeverityLevels` to `@sentry/types`,
  5. // b) moving the`SeverityLevel` type here, or
  6. // c) importing `validSeverityLevels` from here into `@sentry/types`.
  7. //
  8. // Option A would make `@sentry/types` a runtime dependency of `@sentry/utils` (not good), and options B and C would
  9. // create a circular dependency between `@sentry/types` and `@sentry/utils` (also not good). So a TODO accompanying the
  10. // type, reminding anyone who changes it to change this list also, will have to do.
  11. const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'];
  12. /**
  13. * Converts a string-based level into a member of the deprecated {@link Severity} enum.
  14. *
  15. * @deprecated `severityFromString` is deprecated. Please use `severityLevelFromString` instead.
  16. *
  17. * @param level String representation of Severity
  18. * @returns Severity
  19. */
  20. function severityFromString(level) {
  21. return severityLevelFromString(level) ;
  22. }
  23. /**
  24. * Converts a string-based level into a `SeverityLevel`, normalizing it along the way.
  25. *
  26. * @param level String representation of desired `SeverityLevel`.
  27. * @returns The `SeverityLevel` corresponding to the given string, or 'log' if the string isn't a valid level.
  28. */
  29. function severityLevelFromString(level) {
  30. return (level === 'warn' ? 'warning' : validSeverityLevels.includes(level) ? level : 'log') ;
  31. }
  32. exports.severityFromString = severityFromString;
  33. exports.severityLevelFromString = severityLevelFromString;
  34. exports.validSeverityLevels = validSeverityLevels;
  35. //# sourceMappingURL=severity.js.map