Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-redact

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-redact - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

16

benchmark/index.js

@@ -5,11 +5,11 @@ 'use strict'

const fastRedact = require('..')
const redactNoSerialize = fastRedact({paths: ['a.b.c'], serialize: false})
const redactWildNoSerialize = fastRedact({paths: ['a.b.*'], serialize: false})
const redactIntermediateWildNoSerialize = fastRedact({paths: ['a.*.c'], serialize: false})
const redact = fastRedact({paths: ['a.b.c']})
const redactNoSerialize = fastRedact({ paths: ['a.b.c'], serialize: false })
const redactWildNoSerialize = fastRedact({ paths: ['a.b.*'], serialize: false })
const redactIntermediateWildNoSerialize = fastRedact({ paths: ['a.*.c'], serialize: false })
const redact = fastRedact({ paths: ['a.b.c'] })
const noirWild = require('pino-noir')(['a.b.*'])
const redactWild = fastRedact({paths: ['a.b.*']})
const redactIntermediateWild = fastRedact({paths: ['a.*.c']})
const redactIntermediateWildMatchWildOutcome = fastRedact({paths: ['a.*.c', 'a.*.b', 'a.*.a']})
const redactStaticMatchWildOutcome = fastRedact({paths: ['a.b.c', 'a.d.a', 'a.d.b', 'a.d.c']})
const redactWild = fastRedact({ paths: ['a.b.*'] })
const redactIntermediateWild = fastRedact({ paths: ['a.*.c'] })
const redactIntermediateWildMatchWildOutcome = fastRedact({ paths: ['a.*.c', 'a.*.b', 'a.*.a'] })
const redactStaticMatchWildOutcome = fastRedact({ paths: ['a.b.c', 'a.d.a', 'a.d.b', 'a.d.c'] })

@@ -16,0 +16,0 @@ const obj = {

'use strict'
const fastRedact = require('..')
const redact = fastRedact({paths: ['a[*].c.d']})
const redact = fastRedact({ paths: ['a[*].c.d'] })
const obj = {
a: [
{c: {d: 'hide me', e: 'leave me be'}},
{c: {d: 'and me', f: 'I want to live'}},
{c: {d: 'and also I', g: 'I want to run in a stream'}}
{ c: { d: 'hide me', e: 'leave me be' } },
{ c: { d: 'and me', f: 'I want to live' } },
{ c: { d: 'and also I', g: 'I want to run in a stream' } }
]
}
console.log(redact(obj))

@@ -7,3 +7,3 @@ 'use strict'

})
const o = {a: 1, b: 2}
const o = { a: 1, b: 2 }
console.log(redact(o) === o)

@@ -10,0 +10,0 @@ console.log(o)

'use strict'
const fastRedact = require('..')
const redact = fastRedact({paths: ['a'], serialize: (o) => JSON.stringify(o, 0, 2)})
console.log(redact({a: 1, b: 2}))
const redact = fastRedact({ paths: ['a'], serialize: (o) => JSON.stringify(o, 0, 2) })
console.log(redact({ a: 1, b: 2 }))
'use strict'
const fastRedact = require('..')
const redact = fastRedact({paths: ['*.c.d']})
const redact = fastRedact({ paths: ['*.c.d'] })
const obj = {
x: {c: {d: 'hide me', e: 'leave me be'}},
y: {c: {d: 'and me', f: 'I want to live'}},
z: {c: {d: 'and also I', g: 'I want to run in a stream'}}
x: { c: { d: 'hide me', e: 'leave me be' } },
y: { c: { d: 'and me', f: 'I want to live' } },
z: { c: { d: 'and also I', g: 'I want to run in a stream' } }
}
console.log(redact(obj))

@@ -36,10 +36,10 @@ 'use strict'

validate({paths, serialize, censor})
validate({ paths, serialize, censor })
const { wildcards, wcLen, secret } = parse({paths, censor})
const { wildcards, wcLen, secret } = parse({ paths, censor })
const compileRestore = restorer({secret, wcLen})
const compileRestore = restorer({ secret, wcLen })
const strict = 'strict' in opts ? opts.strict : true
return redactor({secret, wcLen, serialize, strict}, state({
return redactor({ secret, wcLen, serialize, strict }, state({
secret,

@@ -46,0 +46,0 @@ censor,

@@ -10,3 +10,3 @@ 'use strict'

function groupRestore ({keys, values, target}) {
function groupRestore ({ keys, values, target }) {
if (target == null) return

@@ -22,3 +22,3 @@ const length = keys.length

const target = get(o, path)
if (target == null) return {keys: null, values: null, target: null, flat: true}
if (target == null) return { keys: null, values: null, target: null, flat: true }
const keys = Object.keys(target)

@@ -32,3 +32,3 @@ const length = keys.length

}
return {keys, values, target, flat: true}
return { keys, values, target, flat: true }
}

@@ -54,3 +54,3 @@

if (exists === true && parent !== null) {
store.push({key: ns[ns.length - 1], target: parent, value})
store.push({ key: ns[ns.length - 1], target: parent, value })
}

@@ -75,3 +75,3 @@ }

ov = n = o[k]
if (typeof n !== 'object') return {value: null, parent: null, exists}
if (typeof n !== 'object') return { value: null, parent: null, exists }
while (n != null && ++i < l) {

@@ -91,3 +91,3 @@ k = p[i]

}
return {value: ov, parent: oov, exists}
return { value: ov, parent: oov, exists }
}

@@ -94,0 +94,0 @@ function get (o, p) {

@@ -7,3 +7,3 @@ 'use strict'

function parse ({paths, censor}) {
function parse ({ paths }) {
const wildcards = []

@@ -35,3 +35,3 @@ var wcLen = 0

path: path,
val: null,
val: undefined,
precensored: false,

@@ -38,0 +38,0 @@ circle: '',

@@ -7,3 +7,3 @@ 'use strict'

function redactor ({secret, serialize, wcLen, strict}, state) {
function redactor ({ secret, serialize, wcLen, strict }, state) {
/* eslint-disable-next-line */

@@ -10,0 +10,0 @@ const redact = Function('o', `

@@ -7,3 +7,3 @@ 'use strict'

function restorer ({secret, wcLen}) {
function restorer ({ secret, wcLen }) {
return function compileRestore () {

@@ -15,3 +15,3 @@ if (this.restore) return

const hasWildcards = wcLen > 0
const state = hasWildcards ? {secret, groupRestore, nestedRestore} : {secret}
const state = hasWildcards ? { secret, groupRestore, nestedRestore } : { secret }
/* eslint-disable-next-line */

@@ -25,2 +25,14 @@ this.restore = Function(

/**
* Mutates the original object to be censored by restoring its original values
* prior to censoring.
*
* @param {object} secret Compiled object describing which target fields should
* be censored and the field states.
* @param {string[]} paths The list of paths to censor as provided at
* initialization time.
*
* @returns {string} String of JavaScript to be used by `Function()`. The
* string compiles to the function that does the work in the description.
*/
function resetTmpl (secret, paths) {

@@ -35,4 +47,6 @@ return paths.map((path) => {

return `
try { ${reset} } catch (e) {}
${clear}
if (secret[${escPath}].val !== undefined) {
try { ${reset} } catch (e) {}
${clear}
}
`

@@ -39,0 +53,0 @@ }).join('')

@@ -14,9 +14,9 @@ 'use strict'

wildcards,
wcLen,
wcLen
} = o
const builder = [{secret, censor, compileRestore}]
builder.push({secret})
if (serialize !== false) builder.push({serialize})
if (wcLen > 0) builder.push({groupRedact, nestedRedact, wildcards, wcLen})
const builder = [{ secret, censor, compileRestore }]
builder.push({ secret })
if (serialize !== false) builder.push({ serialize })
if (wcLen > 0) builder.push({ groupRedact, nestedRedact, wildcards, wcLen })
return Object.assign(...builder)
}

@@ -14,3 +14,3 @@ 'use strict'

return function validate ({paths, serialize, censor}) {
return function validate ({ paths, serialize, censor }) {
if (typeof censor === 'function') {

@@ -25,3 +25,3 @@ throw Error(ERR_CENSOR_MUST_NOT_BE_FUNCTION())

if (/〇/.test(s)) throw Error()
const proxy = new Proxy({}, {get: () => proxy, set: () => { throw Error() }})
const proxy = new Proxy({}, { get: () => proxy, set: () => { throw Error() } })
const expr = (s[0] === '[' ? '' : '.') + s.replace(/^\*/, '〇').replace(/\.\*/g, '.〇').replace(/\[\*\]/g, '[〇]')

@@ -36,4 +36,4 @@ if (/\n|\r|;/.test(expr)) throw Error()

})()
`, createContext({o: proxy, 〇: null}), {
codeGeneration: {strings: false, wasm: false}
`, createContext({ o: proxy, 〇: null }), {
codeGeneration: { strings: false, wasm: false }
})

@@ -40,0 +40,0 @@ } catch (e) {

{
"name": "fast-redact",
"version": "1.2.0",
"version": "1.3.0",
"description": "very fast object redaction",

@@ -8,2 +8,3 @@ "main": "index.js",

"test": "tap test",
"pretest": "standard index.js 'lib/*.js' 'example/*.js' benchmark/index.js test/index.js | snazzy",
"cov": "tap --cov test",

@@ -30,2 +31,4 @@ "cov-ui": "tap --coverage-report=html test",

"pino-noir": "^2.2.1",
"snazzy": "^8.0.0",
"standard": "^12.0.1",
"tap": "^12.0.1"

@@ -36,3 +39,2 @@ },

},
"dependencies": {},
"directories": {

@@ -39,0 +41,0 @@ "example": "example",

@@ -8,4 +8,4 @@ 'use strict'

test('returns no-op when passed no paths [serialize: false]', ({end, doesNotThrow}) => {
const redact = fastRedact({paths: [], serialize: false})
test('returns no-op when passed no paths [serialize: false]', ({ end, doesNotThrow }) => {
const redact = fastRedact({ paths: [], serialize: false })
doesNotThrow(() => redact({}))

@@ -19,4 +19,4 @@ doesNotThrow(() => {

test('returns serializer when passed no paths [serialize: default]', ({end, is}) => {
is(fastRedact({paths: []}), JSON.stringify)
test('returns serializer when passed no paths [serialize: default]', ({ end, is }) => {
is(fastRedact({ paths: [] }), JSON.stringify)
is(fastRedact(), JSON.stringify)

@@ -26,4 +26,4 @@ end()

test('throws when passed non-object using defaults', ({end, throws}) => {
const redact = fastRedact({paths: ['a.b.c']})
test('throws when passed non-object using defaults', ({ end, throws }) => {
const redact = fastRedact({ paths: ['a.b.c'] })
throws(() => redact(1))

@@ -33,4 +33,4 @@ end()

test('throws when passed non-object using [strict: true]', ({end, throws}) => {
const redact = fastRedact({paths: ['a.b.c'], strict: true})
test('throws when passed non-object using [strict: true]', ({ end, throws }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: true })
throws(() => redact(1))

@@ -40,4 +40,4 @@ end()

test('returns original value when passed non-object using [strict: false]', ({end, is, doesNotThrow}) => {
const redact = fastRedact({paths: ['a.b.c'], strict: false})
test('returns original value when passed non-object using [strict: false]', ({ end, is, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: false })
doesNotThrow(() => redact(1))

@@ -49,14 +49,14 @@ const o = redact(1)

test('throws if a path is not a string', ({end, is, throws}) => {
test('throws if a path is not a string', ({ end, is, throws }) => {
throws((e) => {
fastRedact({paths: [1]})
fastRedact({ paths: [1] })
}, Error('fast-redact - Paths must be strings'))
throws((e) => {
fastRedact({paths: [null]})
fastRedact({ paths: [null] })
}, Error('fast-redact - Paths must be strings'))
throws((e) => {
fastRedact({paths: [undefined]})
fastRedact({ paths: [undefined] })
}, Error('fast-redact - Paths must be strings'))
throws((e) => {
fastRedact({paths: [{}]})
fastRedact({ paths: [{}] })
}, Error('fast-redact - Paths must be strings'))

@@ -66,90 +66,90 @@ end()

test('throws when passed illegal paths', ({end, is, throws}) => {
test('throws when passed illegal paths', ({ end, is, throws }) => {
const err = (s) => Error(`fast-redact – Invalid path (${s})`)
throws((e) => {
fastRedact({paths: ['@']})
fastRedact({ paths: ['@'] })
}, err('@'))
throws((e) => {
fastRedact({paths: ['0']})
fastRedact({ paths: ['0'] })
}, err('0'))
throws((e) => {
fastRedact({paths: ['〇']})
fastRedact({ paths: ['〇'] })
}, err('〇'))
throws((e) => {
fastRedact({paths: ['a.1.c']})
fastRedact({ paths: ['a.1.c'] })
}, err('a.1.c'))
throws((e) => {
fastRedact({paths: ['a..c']})
fastRedact({ paths: ['a..c'] })
}, err('a..c'))
throws((e) => {
fastRedact({paths: ['1..c']})
fastRedact({ paths: ['1..c'] })
}, err('1..c'))
throws((e) => {
fastRedact({paths: ['a = b']})
fastRedact({ paths: ['a = b'] })
}, err('a = b'))
throws((e) => {
fastRedact({paths: ['a(b)']})
fastRedact({ paths: ['a(b)'] })
}, err('a(b)'))
throws((e) => {
fastRedact({paths: ['//a.b.c']})
fastRedact({ paths: ['//a.b.c'] })
}, err('//a.b.c'))
throws((e) => {
fastRedact({paths: ['\\a.b.c']})
fastRedact({ paths: ['\\a.b.c'] })
}, err('\\a.b.c'))
throws((e) => {
fastRedact({paths: ['a.#.c']})
fastRedact({ paths: ['a.#.c'] })
}, err('a.#.c'))
throws((e) => {
fastRedact({paths: ['~~a.b.c']})
fastRedact({ paths: ['~~a.b.c'] })
}, err('~~a.b.c'))
throws((e) => {
fastRedact({paths: ['^a.b.c']})
fastRedact({ paths: ['^a.b.c'] })
}, err('^a.b.c'))
throws((e) => {
fastRedact({paths: ['a + b']})
fastRedact({ paths: ['a + b'] })
}, err('a + b'))
throws((e) => {
fastRedact({paths: ['return a + b']})
fastRedact({ paths: ['return a + b'] })
}, err('return a + b'))
throws((e) => {
fastRedact({paths: ['a / b']})
fastRedact({ paths: ['a / b'] })
}, err('a / b'))
throws((e) => {
fastRedact({paths: ['a * b']})
fastRedact({ paths: ['a * b'] })
}, err('a * b'))
throws((e) => {
fastRedact({paths: ['a - b']})
fastRedact({ paths: ['a - b'] })
}, err('a - b'))
throws((e) => {
fastRedact({paths: ['a ** b']})
fastRedact({ paths: ['a ** b'] })
}, err('a ** b'))
throws((e) => {
fastRedact({paths: ['a % b']})
fastRedact({ paths: ['a % b'] })
}, err('a % b'))
throws((e) => {
fastRedact({paths: ['a.b*.c']})
fastRedact({ paths: ['a.b*.c'] })
}, err('a.b*.c'))
throws((e) => {
fastRedact({paths: ['a;global.foo = "bar"']})
fastRedact({ paths: ['a;global.foo = "bar"'] })
}, err('a;global.foo = "bar"'))
throws((e) => {
fastRedact({paths: ['a;while(1){}']})
fastRedact({ paths: ['a;while(1){}'] })
}, err('a;while(1){}'))
throws((e) => {
fastRedact({paths: ['a//']})
fastRedact({ paths: ['a//'] })
}, err('a//'))
throws((e) => {
fastRedact({paths: ['a/*foo*/']})
fastRedact({ paths: ['a/*foo*/'] })
}, err('a/*foo*/'))
throws((e) => {
fastRedact({paths: ['a,o.b']})
fastRedact({ paths: ['a,o.b'] })
}, err('a,o.b'))
throws((e) => {
fastRedact({paths: ['a = o.b']})
fastRedact({ paths: ['a = o.b'] })
}, err('a = o.b'))
throws((e) => {
fastRedact({paths: ['a\n']})
fastRedact({ paths: ['a\n'] })
}, err('a\n'))
throws((e) => {
fastRedact({paths: ['a\r']})
fastRedact({ paths: ['a\r'] })
}, err('a\r'))

@@ -159,5 +159,5 @@ end()

test('throws if more than one wildcard in a path', ({end, throws}) => {
test('throws if more than one wildcard in a path', ({ end, throws }) => {
throws(() => {
fastRedact({paths: ['a.*.x.*'], serialize: false})
fastRedact({ paths: ['a.*.x.*'], serialize: false })
}, Error('fast-redact – Only one wildcard per path is supported'))

@@ -167,5 +167,5 @@ end()

test('throws if a custom serializer is used and remove is true', ({end, throws}) => {
test('throws if a custom serializer is used and remove is true', ({ end, throws }) => {
throws(() => {
fastRedact({paths: ['a'], serialize: (o) => o, remove: true})
fastRedact({ paths: ['a'], serialize: (o) => o, remove: true })
}, Error('fast-redact – remove option may only be set when serializer is JSON.stringify'))

@@ -175,5 +175,5 @@ end()

test('throws if serialize is false and remove is true', ({end, throws}) => {
test('throws if serialize is false and remove is true', ({ end, throws }) => {
throws(() => {
fastRedact({paths: ['a'], serialize: false, remove: true})
fastRedact({ paths: ['a'], serialize: false, remove: true })
}, Error('fast-redact – remove option may only be set when serializer is JSON.stringify'))

@@ -183,12 +183,12 @@ end()

test('masks according to supplied censor', ({end, is}) => {
test('masks according to supplied censor', ({ end, is }) => {
const censor = 'test'
const redact = fastRedact({paths: ['a'], censor, serialize: false})
is(redact({a: 'a'}).a, censor)
const redact = fastRedact({ paths: ['a'], censor, serialize: false })
is(redact({ a: 'a' }).a, censor)
end()
})
test('redact.restore function is available when serialize is false', ({end, is}) => {
test('redact.restore function is available when serialize is false', ({ end, is }) => {
const censor = 'test'
const redact = fastRedact({paths: ['a'], censor, serialize: false})
const redact = fastRedact({ paths: ['a'], censor, serialize: false })
is(typeof redact.restore, 'function')

@@ -198,6 +198,6 @@ end()

test('redact.restore function places original values back in place', ({end, is}) => {
test('redact.restore function places original values back in place', ({ end, is }) => {
const censor = 'test'
const redact = fastRedact({paths: ['a'], censor, serialize: false})
const o = {a: 'a'}
const redact = fastRedact({ paths: ['a'], censor, serialize: false })
const o = { a: 'a' }
redact(o)

@@ -210,5 +210,5 @@ is(o.a, censor)

test('serializes with JSON.stringify by default', ({end, is}) => {
const redact = fastRedact({paths: ['a']})
const o = {a: 'a'}
test('serializes with JSON.stringify by default', ({ end, is }) => {
const redact = fastRedact({ paths: ['a'] })
const o = { a: 'a' }
is(redact(o), `{"a":"${censor}"}`)

@@ -219,5 +219,5 @@ is(o.a, 'a')

test('removes during serialization instead of redacting when remove option is true', ({end, is}) => {
const redact = fastRedact({paths: ['a'], remove: true})
const o = {a: 'a', b: 'b'}
test('removes during serialization instead of redacting when remove option is true', ({ end, is }) => {
const redact = fastRedact({ paths: ['a'], remove: true })
const o = { a: 'a', b: 'b' }
is(redact(o), `{"b":"b"}`)

@@ -228,5 +228,5 @@ is(o.a, 'a')

test('serializes with JSON.stringify if serialize is true', ({end, is}) => {
const redact = fastRedact({paths: ['a'], serialize: true})
const o = {a: 'a'}
test('serializes with JSON.stringify if serialize is true', ({ end, is }) => {
const redact = fastRedact({ paths: ['a'], serialize: true })
const o = { a: 'a' }
is(redact(o), `{"a":"${censor}"}`)

@@ -237,5 +237,5 @@ is(o.a, 'a')

test('serializes with JSON.stringify if serialize is not a function', ({end, is}) => {
const redact = fastRedact({paths: ['a'], serialize: {}})
const o = {a: 'a'}
test('serializes with JSON.stringify if serialize is not a function', ({ end, is }) => {
const redact = fastRedact({ paths: ['a'], serialize: {} })
const o = { a: 'a' }
is(redact(o), `{"a":"${censor}"}`)

@@ -246,5 +246,5 @@ is(o.a, 'a')

test('serializes with custom serializer if supplied', ({end, is}) => {
const redact = fastRedact({paths: ['a'], serialize: (o) => JSON.stringify(o, 0, 2)})
const o = {a: 'a'}
test('serializes with custom serializer if supplied', ({ end, is }) => {
const redact = fastRedact({ paths: ['a'], serialize: (o) => JSON.stringify(o, 0, 2) })
const o = { a: 'a' }
is(redact(o), `{\n "a": "${censor}"\n}`)

@@ -255,5 +255,5 @@ is(o.a, 'a')

test('redacts parent keys', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('redacts parent keys', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -263,43 +263,43 @@ end()

test('supports paths with array indexes', ({end, same}) => {
const redact = fastRedact({paths: ['insideArray.like[3].this'], serialize: false})
same(redact({insideArray: {like: ['a', 'b', 'c', {this: {foo: 'meow'}}]}}), {insideArray: {like: ['a', 'b', 'c', {this: censor}]}})
test('supports paths with array indexes', ({ end, same }) => {
const redact = fastRedact({ paths: ['insideArray.like[3].this'], serialize: false })
same(redact({ insideArray: { like: ['a', 'b', 'c', { this: { foo: 'meow' } }] } }), { insideArray: { like: ['a', 'b', 'c', { this: censor }] } })
end()
})
test('censor may be any type, except function which will throw', ({end, same, throws}) => {
const redactToString = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: 'censor', serialize: false})
const redactToUndefined = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: undefined, serialize: false})
test('censor may be any type, except function which will throw', ({ end, same, throws }) => {
const redactToString = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: 'censor', serialize: false })
const redactToUndefined = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: undefined, serialize: false })
const sym = Symbol('sym')
const redactToSymbol = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: sym, serialize: false})
const redactToNumber = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: 0, serialize: false})
const redactToBoolean = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: false, serialize: false})
const redactToNull = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: null, serialize: false})
const redactToObject = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: {redacted: true}, serialize: false})
const redactToArray = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: ['redacted'], serialize: false})
const redactToBuffer = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: Buffer.from('redacted'), serialize: false})
const redactToError = fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: Error('redacted'), serialize: false})
same(redactToString({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: 'censor', d: {x: 'censor', y: 'censor'}}}})
same(redactToUndefined({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: undefined, d: {x: undefined, y: undefined}}}})
same(redactToSymbol({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: sym, d: {x: sym, y: sym}}}})
same(redactToNumber({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: 0, d: {x: 0, y: 0}}}})
same(redactToBoolean({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: false, d: {x: false, y: false}}}})
same(redactToNull({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: null, d: {x: null, y: null}}}})
same(redactToObject({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: {redacted: true}, d: {x: {redacted: true}, y: {redacted: true}}}}})
same(redactToArray({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: ['redacted'], d: {x: ['redacted'], y: ['redacted']}}}})
same(redactToBuffer({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: Buffer.from('redacted'), d: {x: Buffer.from('redacted'), y: Buffer.from('redacted')}}}})
same(redactToError({a: {b: {c: 's', d: {x: 's', y: 's'}}}}), {a: {b: {c: Error('redacted'), d: {x: Error('redacted'), y: Error('redacted')}}}})
throws(() => fastRedact({paths: ['a.b.c', 'a.b.d.*'], censor: () => {}, serialize: false}))
const redactToSymbol = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: sym, serialize: false })
const redactToNumber = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: 0, serialize: false })
const redactToBoolean = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: false, serialize: false })
const redactToNull = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: null, serialize: false })
const redactToObject = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: { redacted: true }, serialize: false })
const redactToArray = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: ['redacted'], serialize: false })
const redactToBuffer = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: Buffer.from('redacted'), serialize: false })
const redactToError = fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: Error('redacted'), serialize: false })
same(redactToString({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: 'censor', d: { x: 'censor', y: 'censor' } } } })
same(redactToUndefined({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: undefined, d: { x: undefined, y: undefined } } } })
same(redactToSymbol({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: sym, d: { x: sym, y: sym } } } })
same(redactToNumber({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: 0, d: { x: 0, y: 0 } } } })
same(redactToBoolean({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: false, d: { x: false, y: false } } } })
same(redactToNull({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: null, d: { x: null, y: null } } } })
same(redactToObject({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: { redacted: true }, d: { x: { redacted: true }, y: { redacted: true } } } } })
same(redactToArray({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: ['redacted'], d: { x: ['redacted'], y: ['redacted'] } } } })
same(redactToBuffer({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: Buffer.from('redacted'), d: { x: Buffer.from('redacted'), y: Buffer.from('redacted') } } } })
same(redactToError({ a: { b: { c: 's', d: { x: 's', y: 's' } } } }), { a: { b: { c: Error('redacted'), d: { x: Error('redacted'), y: Error('redacted') } } } })
throws(() => fastRedact({ paths: ['a.b.c', 'a.b.d.*'], censor: () => {}, serialize: false }))
end()
})
test('supports multiple paths from the same root', ({end, same}) => {
const redact = fastRedact({paths: ['deep.bar.shoe', 'deep.baz.shoe', 'deep.foo', 'deep.not.there.sooo', 'deep.fum.shoe'], serialize: false})
same(redact({deep: {bar: 'hmm', baz: {shoe: {k: 1}}, foo: {}, fum: {shoe: 'moo'}}}), {deep: {bar: 'hmm', baz: {shoe: censor}, foo: censor, fum: {shoe: censor}}})
test('supports multiple paths from the same root', ({ end, same }) => {
const redact = fastRedact({ paths: ['deep.bar.shoe', 'deep.baz.shoe', 'deep.foo', 'deep.not.there.sooo', 'deep.fum.shoe'], serialize: false })
same(redact({ deep: { bar: 'hmm', baz: { shoe: { k: 1 } }, foo: {}, fum: { shoe: 'moo' } } }), { deep: { bar: 'hmm', baz: { shoe: censor }, foo: censor, fum: { shoe: censor } } })
end()
})
test('supports strings in bracket notation paths (single quote)', ({end, is}) => {
const redact = fastRedact({paths: [`a['@#!='].c`], serialize: false})
const result = redact({a: {'@#!=': {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('supports strings in bracket notation paths (single quote)', ({ end, is }) => {
const redact = fastRedact({ paths: [`a['@#!='].c`], serialize: false })
const result = redact({ a: { '@#!=': { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a['@#!='].c, censor)

@@ -309,5 +309,5 @@ end()

test('supports strings in bracket notation paths (double quote)', ({end, is}) => {
const redact = fastRedact({paths: [`a["@#!="].c`], serialize: false})
const result = redact({a: {'@#!=': {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('supports strings in bracket notation paths (double quote)', ({ end, is }) => {
const redact = fastRedact({ paths: [`a["@#!="].c`], serialize: false })
const result = redact({ a: { '@#!=': { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a['@#!='].c, censor)

@@ -317,5 +317,5 @@ end()

test('supports strings in bracket notation paths (backtick quote)', ({end, is}) => {
const redact = fastRedact({paths: ['a[`@#!=`].c'], serialize: false})
const result = redact({a: {'@#!=': {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('supports strings in bracket notation paths (backtick quote)', ({ end, is }) => {
const redact = fastRedact({ paths: ['a[`@#!=`].c'], serialize: false })
const result = redact({ a: { '@#!=': { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a['@#!='].c, censor)

@@ -325,5 +325,5 @@ end()

test('allows * within a bracket notation string', ({end, is}) => {
const redact = fastRedact({paths: ['a["*"].c'], serialize: false})
const result = redact({a: {'*': {c: 's', x: 1}}})
test('allows * within a bracket notation string', ({ end, is }) => {
const redact = fastRedact({ paths: ['a["*"].c'], serialize: false })
const result = redact({ a: { '*': { c: 's', x: 1 } } })
is(result.a['*'].c, censor)

@@ -334,5 +334,5 @@ is(result.a['*'].x, 1)

test('redacts parent keys – restore', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('redacts parent keys – restore', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -344,5 +344,5 @@ redact.restore(result)

test('handles null proto objects', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c'], serialize: false})
const result = redact({__proto__: null, a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('handles null proto objects', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c'], serialize: false })
const result = redact({ __proto__: null, a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -352,5 +352,5 @@ end()

test('handles null proto objects – restore', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c'], serialize: false})
const result = redact({__proto__: null, a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('handles null proto objects – restore', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c'], serialize: false })
const result = redact({ __proto__: null, a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -362,17 +362,17 @@ redact.restore(result, 's')

test('handles paths that do not match object structure', ({end, same}) => {
const redact = fastRedact({paths: ['x.y.z'], serialize: false})
same(redact({a: {b: {c: 's'}}}), {a: {b: {c: 's'}}})
test('handles paths that do not match object structure', ({ end, same }) => {
const redact = fastRedact({ paths: ['x.y.z'], serialize: false })
same(redact({ a: { b: { c: 's' } } }), { a: { b: { c: 's' } } })
end()
})
test('ignores missing paths in object', ({end, same}) => {
const redact = fastRedact({paths: ['a.b.c', 'a.z.d', 'a.b.z'], serialize: false})
same(redact({a: {b: {c: 's'}}}), {a: {b: {c: censor}}})
test('ignores missing paths in object', ({ end, same }) => {
const redact = fastRedact({ paths: ['a.b.c', 'a.z.d', 'a.b.z'], serialize: false })
same(redact({ a: { b: { c: 's' } } }), { a: { b: { c: censor } } })
end()
})
test('ignores missing paths in object – restore', ({end, doesNotThrow}) => {
const redact = fastRedact({paths: ['a.b.c', 'a.z.d', 'a.b.z'], serialize: false})
const o = {a: {b: {c: 's'}}}
test('ignores missing paths in object – restore', ({ end, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c', 'a.z.d', 'a.b.z'], serialize: false })
const o = { a: { b: { c: 's' } } }
redact(o)

@@ -386,28 +386,28 @@ doesNotThrow(() => {

test('gracefully handles primitives that match intermediate keys in paths', ({end, same}) => {
const redact = fastRedact({paths: ['a.b.c', 'a.b.c.d'], serialize: false})
same(redact({a: {b: null}}), {a: {b: null}})
same(redact({a: {b: 's'}}), {a: {b: 's'}})
same(redact({a: {b: 1}}), {a: {b: 1}})
same(redact({a: {b: undefined}}), {a: {b: undefined}})
same(redact({a: {b: true}}), {a: {b: true}})
test('gracefully handles primitives that match intermediate keys in paths', ({ end, same }) => {
const redact = fastRedact({ paths: ['a.b.c', 'a.b.c.d'], serialize: false })
same(redact({ a: { b: null } }), { a: { b: null } })
same(redact({ a: { b: 's' } }), { a: { b: 's' } })
same(redact({ a: { b: 1 } }), { a: { b: 1 } })
same(redact({ a: { b: undefined } }), { a: { b: undefined } })
same(redact({ a: { b: true } }), { a: { b: true } })
const sym = Symbol('sym')
same(redact({a: {b: sym}}), {a: {b: sym}})
same(redact({ a: { b: sym } }), { a: { b: sym } })
end()
})
test('handles circulars', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.baz'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar}
test('handles circulars', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.baz'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar }
bar.baz = bar
o.bar.baz = o.bar
same(redact(o), {a: 1, bar: {b: 2, baz: censor}})
same(redact(o), { a: 1, bar: { b: 2, baz: censor } })
end()
})
test('handles circulars – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.baz'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar}
test('handles circulars – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.baz'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar }
bar.baz = bar

@@ -423,6 +423,6 @@ o.bar.baz = o.bar

test('handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.baz', 'cf.bar'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar, cf: {bar}}
test('handles circulars and cross references – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.baz', 'cf.bar'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar, cf: { bar } }
bar.baz = bar

@@ -441,35 +441,35 @@ o.bar.baz = o.bar

test('ultimate wildcards – shallow', ({end, same}) => {
const redact = fastRedact({paths: ['test.*'], serialize: false})
same(redact({test: {baz: 1, bar: 'private'}}), {test: {baz: censor, bar: censor}})
test('ultimate wildcards – shallow', ({ end, same }) => {
const redact = fastRedact({ paths: ['test.*'], serialize: false })
same(redact({ test: { baz: 1, bar: 'private' } }), { test: { baz: censor, bar: censor } })
end()
})
test('ultimate wildcards – deep', ({end, same}) => {
const redact = fastRedact({paths: ['deep.bar.baz.ding.*'], serialize: false})
same(redact({deep: {a: 1, bar: {b: 2, baz: {c: 3, ding: {d: 4, e: 5, f: 'six'}}}}}), {deep: {a: 1, bar: {b: 2, baz: {c: 3, ding: {d: censor, e: censor, f: censor}}}}})
test('ultimate wildcards – deep', ({ end, same }) => {
const redact = fastRedact({ paths: ['deep.bar.baz.ding.*'], serialize: false })
same(redact({ deep: { a: 1, bar: { b: 2, baz: { c: 3, ding: { d: 4, e: 5, f: 'six' } } } } }), { deep: { a: 1, bar: { b: 2, baz: { c: 3, ding: { d: censor, e: censor, f: censor } } } } })
end()
})
test('ultimate wildcards - array – shallow', ({end, same}) => {
const redact = fastRedact({paths: ['array[*]'], serialize: false})
same(redact({array: ['a', 'b', 'c', 'd']}), {array: [censor, censor, censor, censor]})
test('ultimate wildcards - array – shallow', ({ end, same }) => {
const redact = fastRedact({ paths: ['array[*]'], serialize: false })
same(redact({ array: ['a', 'b', 'c', 'd'] }), { array: [censor, censor, censor, censor] })
end()
})
test('ultimate wildcards – array – deep', ({end, same}) => {
const redact = fastRedact({paths: ['deepArray.down.here[*]'], serialize: false})
same(redact({deepArray: {down: {here: ['a', 'b', 'c']}}}), {deepArray: {down: {here: [censor, censor, censor]}}})
test('ultimate wildcards – array – deep', ({ end, same }) => {
const redact = fastRedact({ paths: ['deepArray.down.here[*]'], serialize: false })
same(redact({ deepArray: { down: { here: ['a', 'b', 'c'] } } }), { deepArray: { down: { here: [censor, censor, censor] } } })
end()
})
test('ultimate wildcards – array – single index', ({end, same}) => {
const redact = fastRedact({paths: ['insideArray.like[3].this.*'], serialize: false})
same(redact({insideArray: {like: ['a', 'b', 'c', {this: {foo: 'meow'}}]}}), {insideArray: {like: ['a', 'b', 'c', {this: {foo: censor}}]}})
test('ultimate wildcards – array – single index', ({ end, same }) => {
const redact = fastRedact({ paths: ['insideArray.like[3].this.*'], serialize: false })
same(redact({ insideArray: { like: ['a', 'b', 'c', { this: { foo: 'meow' } }] } }), { insideArray: { like: ['a', 'b', 'c', { this: { foo: censor } }] } })
end()
})
test('ultimate wildcards - handles null proto objects', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c'], serialize: false})
const result = redact({__proto__: null, a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('ultimate wildcards - handles null proto objects', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c'], serialize: false })
const result = redact({ __proto__: null, a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -479,34 +479,34 @@ end()

test('ultimate wildcards - handles paths that do not match object structure', ({end, same}) => {
const redact = fastRedact({paths: ['x.y.z'], serialize: false})
same(redact({a: {b: {c: 's'}}}), {a: {b: {c: 's'}}})
test('ultimate wildcards - handles paths that do not match object structure', ({ end, same }) => {
const redact = fastRedact({ paths: ['x.y.z'], serialize: false })
same(redact({ a: { b: { c: 's' } } }), { a: { b: { c: 's' } } })
end()
})
test('ultimate wildcards - gracefully handles primitives that match intermediate keys in paths', ({end, same}) => {
const redact = fastRedact({paths: ['a.b.c', 'a.b.c.d'], serialize: false})
same(redact({a: {b: null}}), {a: {b: null}})
same(redact({a: {b: 's'}}), {a: {b: 's'}})
same(redact({a: {b: 1}}), {a: {b: 1}})
same(redact({a: {b: undefined}}), {a: {b: undefined}})
same(redact({a: {b: true}}), {a: {b: true}})
test('ultimate wildcards - gracefully handles primitives that match intermediate keys in paths', ({ end, same }) => {
const redact = fastRedact({ paths: ['a.b.c', 'a.b.c.d'], serialize: false })
same(redact({ a: { b: null } }), { a: { b: null } })
same(redact({ a: { b: 's' } }), { a: { b: 's' } })
same(redact({ a: { b: 1 } }), { a: { b: 1 } })
same(redact({ a: { b: undefined } }), { a: { b: undefined } })
same(redact({ a: { b: true } }), { a: { b: true } })
const sym = Symbol('sym')
same(redact({a: {b: sym}}), {a: {b: sym}})
same(redact({ a: { b: sym } }), { a: { b: sym } })
end()
})
test('ultimate wildcards – handles circulars', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.*'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar}
test('ultimate wildcards – handles circulars', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.*'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar }
bar.baz = bar
o.bar.baz = o.bar
same(redact(o), {a: 1, bar: {b: censor, baz: censor}})
same(redact(o), { a: 1, bar: { b: censor, baz: censor } })
end()
})
test('ultimate wildcards – handles circulars – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.*'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar}
test('ultimate wildcards – handles circulars – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.*'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar }
bar.baz = bar

@@ -522,6 +522,6 @@ o.bar.baz = o.bar

test('ultimate wildcards – handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.*', 'cf.*'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar, cf: {bar}}
test('ultimate wildcards – handles circulars and cross references – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.*', 'cf.*'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar, cf: { bar } }
bar.baz = bar

@@ -540,5 +540,5 @@ o.bar.baz = o.bar

test('static + wildcards', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c', 'a.d.*', 'a.b.z.*'], serialize: false})
const result = redact({a: {b: {c: 's', z: {x: 's', y: 's'}}, d: {a: 's', b: 's', c: 's'}}})
test('static + wildcards', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c', 'a.d.*', 'a.b.z.*'], serialize: false })
const result = redact({ a: { b: { c: 's', z: { x: 's', y: 's' } }, d: { a: 's', b: 's', c: 's' } } })

@@ -554,5 +554,5 @@ is(result.a.b.c, censor)

test('static + wildcards reuse', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.c', 'a.d.*'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('static + wildcards reuse', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.c', 'a.d.*'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })

@@ -566,3 +566,3 @@ is(result.a.b.c, censor)

const result2 = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
const result2 = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result2.a.b.c, censor)

@@ -577,5 +577,5 @@ is(result2.a.d.a, censor)

test('parent wildcard – first position', ({end, is}) => {
const redact = fastRedact({paths: ['*.c'], serialize: false})
const result = redact({b: {c: 's'}, d: {a: 's', b: 's', c: 's'}})
test('parent wildcard – first position', ({ end, is }) => {
const redact = fastRedact({ paths: ['*.c'], serialize: false })
const result = redact({ b: { c: 's' }, d: { a: 's', b: 's', c: 's' } })
is(result.b.c, censor)

@@ -588,5 +588,5 @@ is(result.d.a, 's')

test('parent wildcard – one following key', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.c'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('parent wildcard – one following key', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.c'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -599,5 +599,5 @@ is(result.a.d.a, 's')

test('restore parent wildcard – one following key', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.c'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('restore parent wildcard – one following key', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.c'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
redact.restore(result)

@@ -611,5 +611,5 @@ is(result.a.b.c, 's')

test('parent wildcard – one following key – reuse', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.c'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('parent wildcard – one following key – reuse', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.c'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -619,3 +619,3 @@ is(result.a.d.a, 's')

is(result.a.d.c, censor)
const result2 = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
const result2 = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result2.a.b.c, censor)

@@ -629,5 +629,5 @@ is(result2.a.d.a, 's')

test('parent wildcard – two following keys', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.x.c'], serialize: false})
const result = redact({a: {b: {x: {c: 's'}}, d: {x: {a: 's', b: 's', c: 's'}}}})
test('parent wildcard – two following keys', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.x.c'], serialize: false })
const result = redact({ a: { b: { x: { c: 's' } }, d: { x: { a: 's', b: 's', c: 's' } } } })
is(result.a.b.x.c, censor)

@@ -640,5 +640,5 @@ is(result.a.d.x.a, 's')

test('parent wildcard – two following keys – reuse', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.x.c'], serialize: false})
const result = redact({a: {b: {x: {c: 's'}}, d: {x: {a: 's', b: 's', c: 's'}}}})
test('parent wildcard – two following keys – reuse', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.x.c'], serialize: false })
const result = redact({ a: { b: { x: { c: 's' } }, d: { x: { a: 's', b: 's', c: 's' } } } })
is(result.a.b.x.c, censor)

@@ -649,3 +649,3 @@ is(result.a.d.x.a, 's')

redact.restore(result)
const result2 = redact({a: {b: {x: {c: 's'}}, d: {x: {a: 's', b: 's', c: 's'}}}})
const result2 = redact({ a: { b: { x: { c: 's' } }, d: { x: { a: 's', b: 's', c: 's' } } } })
is(result2.a.b.x.c, censor)

@@ -658,5 +658,5 @@ is(result2.a.d.x.a, 's')

test('restore parent wildcard – two following keys', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.x.c'], serialize: false})
const result = redact({a: {b: {x: {c: 's'}}, d: {x: {a: 's', b: 's', c: 's'}}}})
test('restore parent wildcard – two following keys', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.x.c'], serialize: false })
const result = redact({ a: { b: { x: { c: 's' } }, d: { x: { a: 's', b: 's', c: 's' } } } })
redact.restore(result)

@@ -670,5 +670,5 @@ is(result.a.b.x.c, 's')

test('parent wildcard - array', ({end, is}) => {
const redact = fastRedact({paths: ['a.b[*].x'], serialize: false})
const result = redact({a: {b: [{x: 1}, {a: 2}], d: {a: 's', b: 's', c: 's'}}})
test('parent wildcard - array', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b[*].x'], serialize: false })
const result = redact({ a: { b: [{ x: 1 }, { a: 2 }], d: { a: 's', b: 's', c: 's' } } })
is(result.a.b[0].x, censor)

@@ -681,11 +681,11 @@ is(result.a.b[1].a, 2)

test('parent wildcards – array – single index', ({end, same}) => {
const redact = fastRedact({paths: ['insideArray.like[3].*.foo'], serialize: false})
same(redact({insideArray: {like: ['a', 'b', 'c', {this: {foo: 'meow'}}]}}), {insideArray: {like: ['a', 'b', 'c', {this: {foo: censor}}]}})
test('parent wildcards – array – single index', ({ end, same }) => {
const redact = fastRedact({ paths: ['insideArray.like[3].*.foo'], serialize: false })
same(redact({ insideArray: { like: ['a', 'b', 'c', { this: { foo: 'meow' } }] } }), { insideArray: { like: ['a', 'b', 'c', { this: { foo: censor } }] } })
end()
})
test('parent wildcards - handles null proto objects', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.c'], serialize: false})
const result = redact({__proto__: null, a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('parent wildcards - handles null proto objects', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.c'], serialize: false })
const result = redact({ __proto__: null, a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result.a.b.c, censor)

@@ -695,34 +695,34 @@ end()

test('parent wildcards - handles paths that do not match object structure', ({end, same}) => {
const redact = fastRedact({paths: ['a.*.y.z'], serialize: false})
same(redact({a: {b: {c: 's'}}}), {a: {b: {c: 's'}}})
test('parent wildcards - handles paths that do not match object structure', ({ end, same }) => {
const redact = fastRedact({ paths: ['a.*.y.z'], serialize: false })
same(redact({ a: { b: { c: 's' } } }), { a: { b: { c: 's' } } })
end()
})
test('parent wildcards - gracefully handles primitives that match intermediate keys in paths', ({end, same}) => {
const redact = fastRedact({paths: ['a.*.c'], serialize: false})
same(redact({a: {b: null}}), {a: {b: null}})
same(redact({a: {b: 's'}}), {a: {b: 's'}})
same(redact({a: {b: 1}}), {a: {b: 1}})
same(redact({a: {b: undefined}}), {a: {b: undefined}})
same(redact({a: {b: true}}), {a: {b: true}})
test('parent wildcards - gracefully handles primitives that match intermediate keys in paths', ({ end, same }) => {
const redact = fastRedact({ paths: ['a.*.c'], serialize: false })
same(redact({ a: { b: null } }), { a: { b: null } })
same(redact({ a: { b: 's' } }), { a: { b: 's' } })
same(redact({ a: { b: 1 } }), { a: { b: 1 } })
same(redact({ a: { b: undefined } }), { a: { b: undefined } })
same(redact({ a: { b: true } }), { a: { b: true } })
const sym = Symbol('sym')
same(redact({a: {b: sym}}), {a: {b: sym}})
same(redact({ a: { b: sym } }), { a: { b: sym } })
end()
})
test('parent wildcards – handles circulars', ({end, is, same}) => {
const redact = fastRedact({paths: ['x.*.baz'], serialize: false})
const bar = {b: 2}
const o = {x: {a: 1, bar}}
test('parent wildcards – handles circulars', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['x.*.baz'], serialize: false })
const bar = { b: 2 }
const o = { x: { a: 1, bar } }
bar.baz = bar
o.x.bar.baz = o.x.bar
same(redact(o), {x: {a: 1, bar: {b: 2, baz: censor}}})
same(redact(o), { x: { a: 1, bar: { b: 2, baz: censor } } })
end()
})
test('parent wildcards – handles circulars – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['x.*.baz'], serialize: false})
const bar = {b: 2}
const o = {x: {a: 1, bar}}
test('parent wildcards – handles circulars – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['x.*.baz'], serialize: false })
const bar = { b: 2 }
const o = { x: { a: 1, bar } }
bar.baz = bar

@@ -739,6 +739,6 @@ o.x.bar.baz = o.x.bar

test('parent wildcards – handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['x.*.baz', 'x.*.cf.bar'], serialize: false})
const bar = {b: 2}
const o = {x: {a: 1, bar, y: {cf: {bar}}}}
test('parent wildcards – handles circulars and cross references – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['x.*.baz', 'x.*.cf.bar'], serialize: false })
const bar = { b: 2 }
const o = { x: { a: 1, bar, y: { cf: { bar } } } }
bar.baz = bar

@@ -757,5 +757,5 @@ o.x.bar.baz = o.x.bar

test('parent wildcards – handles missing paths', ({end, is, same}) => {
const redact = fastRedact({paths: ['z.*.baz']})
const o = {a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}}
test('parent wildcards – handles missing paths', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['z.*.baz'] })
const o = { a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } }
is(redact(o), JSON.stringify(o))

@@ -765,5 +765,5 @@ end()

test('ultimate wildcards – handles missing paths', ({end, is, same}) => {
const redact = fastRedact({paths: ['z.*']})
const o = {a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}}
test('ultimate wildcards – handles missing paths', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['z.*'] })
const o = { a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } }
is(redact(o), JSON.stringify(o))

@@ -773,5 +773,5 @@ end()

test('parent wildcards – removes during serialization instead of redacting when remove option is true', ({end, is}) => {
const redact = fastRedact({paths: ['a.*.c'], remove: true})
const o = {a: {b: {c: 'c'}, x: {c: 1}}}
test('parent wildcards – removes during serialization instead of redacting when remove option is true', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.*.c'], remove: true })
const o = { a: { b: { c: 'c' }, x: { c: 1 } } }
is(redact(o), `{"a":{"b":{},"x":{}}}`)

@@ -781,5 +781,5 @@ end()

test('ultimate wildcards – removes during serialization instead of redacting when remove option is true', ({end, is}) => {
const redact = fastRedact({paths: ['a.b.*'], remove: true})
const o = {a: {b: {c: 'c'}, x: {c: 1}}}
test('ultimate wildcards – removes during serialization instead of redacting when remove option is true', ({ end, is }) => {
const redact = fastRedact({ paths: ['a.b.*'], remove: true })
const o = { a: { b: { c: 'c' }, x: { c: 1 } } }
is(redact(o), `{"a":{"b":{},"x":{"c":1}}}`)

@@ -789,5 +789,5 @@ end()

test('supports leading bracket notation', ({end, is}) => {
const redact = fastRedact({paths: ['["a"].b.c']})
const o = {a: {b: {c: 'd'}}}
test('supports leading bracket notation', ({ end, is }) => {
const redact = fastRedact({ paths: ['["a"].b.c'] })
const o = { a: { b: { c: 'd' } } }
is(redact(o), `{"a":{"b":{"c":"${censor}"}}}`)

@@ -797,5 +797,5 @@ end()

test('supports leading bracket notation containing non-legal keyword characters', ({end, is}) => {
const redact = fastRedact({paths: ['["a-x"].b.c']})
const o = {'a-x': {b: {c: 'd'}}}
test('supports leading bracket notation containing non-legal keyword characters', ({ end, is }) => {
const redact = fastRedact({ paths: ['["a-x"].b.c'] })
const o = { 'a-x': { b: { c: 'd' } } }
is(redact(o), `{"a-x":{"b":{"c":"${censor}"}}}`)

@@ -805,20 +805,20 @@ end()

test('supports single leading bracket', ({end, is}) => {
test('supports single leading bracket', ({ end, is }) => {
const censor = 'test'
const redact = fastRedact({paths: ['["a"]'], censor, serialize: false})
is(redact({a: 'a'}).a, censor)
const redact = fastRedact({ paths: ['["a"]'], censor, serialize: false })
is(redact({ a: 'a' }).a, censor)
end()
})
test('supports single leading bracket containing non-legal keyword characters', ({end, is}) => {
test('supports single leading bracket containing non-legal keyword characters', ({ end, is }) => {
const censor = 'test'
const redact = fastRedact({paths: ['["a-x"]'], censor, serialize: false})
is(redact({'a-x': 'a'})['a-x'], censor)
const redact = fastRedact({ paths: ['["a-x"]'], censor, serialize: false })
is(redact({ 'a-x': 'a' })['a-x'], censor)
end()
})
test('(leading brackets) ultimate wildcards – handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.*', 'cf.*'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar, cf: {bar}}
test('(leading brackets) ultimate wildcards – handles circulars and cross references – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['bar.baz.*', 'cf.*'], serialize: false })
const bar = { b: 2 }
const o = { a: 1, bar, cf: { bar } }
bar.baz = bar

@@ -837,6 +837,6 @@ o.bar.baz = o.bar

test('(leading brackets) parent wildcards – handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['["x"].*.baz', '["x"].*.cf.bar'], serialize: false})
const bar = {b: 2}
const o = {x: {a: 1, bar, y: {cf: {bar}}}}
test('(leading brackets) parent wildcards – handles circulars and cross references – restore', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['["x"].*.baz', '["x"].*.cf.bar'], serialize: false })
const bar = { b: 2 }
const o = { x: { a: 1, bar, y: { cf: { bar } } } }
bar.baz = bar

@@ -855,5 +855,5 @@ o.x.bar.baz = o.x.bar

test('(leading brackets) ultimate wildcards – handles missing paths', ({end, is, same}) => {
const redact = fastRedact({paths: ['["z"].*']})
const o = {a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}}
test('(leading brackets) ultimate wildcards – handles missing paths', ({ end, is, same }) => {
const redact = fastRedact({ paths: ['["z"].*'] })
const o = { a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } }
is(redact(o), JSON.stringify(o))

@@ -863,5 +863,5 @@ end()

test('(leading brackets) static + wildcards reuse', ({end, is}) => {
const redact = fastRedact({paths: ['["a"].b.c', '["a"].d.*'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
test('(leading brackets) static + wildcards reuse', ({ end, is }) => {
const redact = fastRedact({ paths: ['["a"].b.c', '["a"].d.*'], serialize: false })
const result = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })

@@ -875,3 +875,3 @@ is(result.a.b.c, censor)

const result2 = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
const result2 = redact({ a: { b: { c: 's' }, d: { a: 's', b: 's', c: 's' } } })
is(result2.a.b.c, censor)

@@ -885,1 +885,18 @@ is(result2.a.d.a, censor)

})
test('correctly restores original object when a path does not match object', ({ end, is }) => {
const redact = fastRedact({ paths: ['foo.bar'], strict: false })
const o = {}
is(redact({ foo: o }), '{"foo":{}}')
is(o.hasOwnProperty('bar'), false)
end()
})
test('correctly restores original object when a matchin path has value of `undefined`', ({ end, is }) => {
const redact = fastRedact({ paths: ['foo.bar'], strict: false })
const o = { bar: undefined }
is(redact({ foo: o }), '{"foo":{}}')
is(o.hasOwnProperty('bar'), true)
is(o.bar, undefined)
end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc