action-debian-package/node_modules/fast-redact/index.js
Dawid Dziurla 9308795b8b
update
2020-03-26 15:37:35 +01:00

56 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict'
const validator = require('./lib/validator')
const parse = require('./lib/parse')
const redactor = require('./lib/redactor')
const restorer = require('./lib/restorer')
const { groupRedact, nestedRedact } = require('./lib/modifiers')
const state = require('./lib/state')
const rx = require('./lib/rx')
const validate = validator()
const noop = (o) => o
noop.restore = noop
const DEFAULT_CENSOR = '[REDACTED]'
fastRedact.rx = rx
fastRedact.validator = validator
module.exports = fastRedact
function fastRedact (opts = {}) {
const paths = Array.from(new Set(opts.paths || []))
const serialize = 'serialize' in opts ? (
opts.serialize === false ? opts.serialize
: (typeof opts.serialize === 'function' ? opts.serialize : JSON.stringify)
) : JSON.stringify
const remove = opts.remove
if (remove === true && serialize !== JSON.stringify) {
throw Error('fast-redact remove option may only be set when serializer is JSON.stringify')
}
const censor = remove === true
? undefined
: 'censor' in opts ? opts.censor : DEFAULT_CENSOR
const isCensorFct = typeof censor === 'function'
if (paths.length === 0) return serialize || noop
validate({ paths, serialize, censor })
const { wildcards, wcLen, secret } = parse({ paths, censor })
const compileRestore = restorer({ secret, wcLen })
const strict = 'strict' in opts ? opts.strict : true
return redactor({ secret, wcLen, serialize, strict, isCensorFct }, state({
secret,
censor,
compileRestore,
serialize,
groupRedact,
nestedRedact,
wildcards,
wcLen
}))
}