summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-audit-report/lib/utils.js
blob: 069ebac8a09171940c07bcc0c6fe397735defec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'

exports.severityLabel = severityLabel
exports.color = color

const ccs = require('console-control-strings')

const severityColors = {
  critical: {
    color: 'brightMagenta',
    label: 'Critical'
  },
  high: {
    color: 'brightRed',
    label: 'High'
  },
  moderate: {
    color: 'brightYellow',
    label: 'Moderate'
  },
  low: {
    color: 'bold',
    label: 'Low'
  }
}

function color (value, colorName, withColor) {
  return (colorName && withColor) ? ccs.color(colorName) + value + ccs.color('reset') : value
}

function severityLabel (sev, withColor, bold) {
  let colorName = severityColors[sev].color
  if (bold) colorName = [colorName, 'bold']
  return color(severityColors[sev].label, colorName, withColor)
}