mirror of
https://github.com/nodejs/node.git
synced 2025-08-18 07:08:50 +02:00

PR-URL: https://github.com/nodejs/node/pull/48378 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Luke Karrys <luke@lukekarrys.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
41 lines
911 B
JavaScript
41 lines
911 B
JavaScript
'use strict'
|
|
|
|
const reporters = {
|
|
install: require('./reporters/install'),
|
|
detail: require('./reporters/detail'),
|
|
json: require('./reporters/json'),
|
|
quiet: require('./reporters/quiet'),
|
|
}
|
|
|
|
const exitCode = require('./exit-code.js')
|
|
|
|
module.exports = Object.assign((data, options = {}) => {
|
|
const {
|
|
reporter = 'install',
|
|
chalk,
|
|
unicode = true,
|
|
indent = 2,
|
|
} = options
|
|
|
|
// CLI defaults this to `null` so the defaulting method above doesn't work
|
|
const auditLevel = options.auditLevel || 'low'
|
|
|
|
if (!data) {
|
|
throw Object.assign(
|
|
new TypeError('ENOAUDITDATA'),
|
|
{
|
|
code: 'ENOAUDITDATA',
|
|
message: 'missing audit data',
|
|
}
|
|
)
|
|
}
|
|
|
|
if (typeof data.toJSON === 'function') {
|
|
data = data.toJSON()
|
|
}
|
|
|
|
return {
|
|
report: reporters[reporter](data, { chalk, unicode, indent }),
|
|
exitCode: exitCode(data, auditLevel),
|
|
}
|
|
}, { reporters })
|