source: imaps-frontend/node_modules/eslint/lib/shared/severity.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * @fileoverview Helpers for severity values (e.g. normalizing different types).
3 * @author Bryan Mishkin
4 */
5
6"use strict";
7
8/**
9 * Convert severity value of different types to a string.
10 * @param {string|number} severity severity value
11 * @throws error if severity is invalid
12 * @returns {string} severity string
13 */
14function normalizeSeverityToString(severity) {
15 if ([2, "2", "error"].includes(severity)) {
16 return "error";
17 }
18 if ([1, "1", "warn"].includes(severity)) {
19 return "warn";
20 }
21 if ([0, "0", "off"].includes(severity)) {
22 return "off";
23 }
24 throw new Error(`Invalid severity value: ${severity}`);
25}
26
27/**
28 * Convert severity value of different types to a number.
29 * @param {string|number} severity severity value
30 * @throws error if severity is invalid
31 * @returns {number} severity number
32 */
33function normalizeSeverityToNumber(severity) {
34 if ([2, "2", "error"].includes(severity)) {
35 return 2;
36 }
37 if ([1, "1", "warn"].includes(severity)) {
38 return 1;
39 }
40 if ([0, "0", "off"].includes(severity)) {
41 return 0;
42 }
43 throw new Error(`Invalid severity value: ${severity}`);
44}
45
46module.exports = {
47 normalizeSeverityToString,
48 normalizeSeverityToNumber
49};
Note: See TracBrowser for help on using the repository browser.