• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const reporters = {
4  install: require('./reporters/install'),
5  detail: require('./reporters/detail'),
6  json: require('./reporters/json'),
7  quiet: require('./reporters/quiet'),
8}
9
10const exitCode = require('./exit-code.js')
11
12module.exports = Object.assign((data, options = {}) => {
13  const {
14    reporter = 'install',
15    chalk,
16    unicode = true,
17    indent = 2,
18  } = options
19
20  // CLI defaults this to `null` so the defaulting method above doesn't work
21  const auditLevel = options.auditLevel || 'low'
22
23  if (!data) {
24    throw Object.assign(
25      new TypeError('ENOAUDITDATA'),
26      {
27        code: 'ENOAUDITDATA',
28        message: 'missing audit data',
29      }
30    )
31  }
32
33  if (typeof data.toJSON === 'function') {
34    data = data.toJSON()
35  }
36
37  return {
38    report: reporters[reporter](data, { chalk, unicode, indent }),
39    exitCode: exitCode(data, auditLevel),
40  }
41}, { reporters })
42