node/deps/npm/node_modules/npm-audit-report/lib/index.js
npm CLI robot 8c8e7e9e2c
deps: upgrade npm to 9.7.1
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>
2023-06-08 12:24:49 +00:00

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 })