Socket
Socket
Sign inDemoInstall

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.4.4 to 1.5.0

8

lib/redactor.js

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

if (typeof o !== 'object' || o == null) {
${strictImpl(strict)}
${strictImpl(strict, serialize)}
}

@@ -91,4 +91,6 @@ const { censor, secret } = this

function strictImpl (strict) {
return strict === true ? `throw Error('fast-redact: primitives cannot be redacted')` : `return typeof o === 'string' ? JSON.stringify(o) : o`
function strictImpl (strict, serialize) {
return strict === true
? `throw Error('fast-redact: primitives cannot be redacted')`
: serialize === false ? `return o` : `return this.serialize(o)`
}
{
"name": "fast-redact",
"version": "1.4.4",
"version": "1.5.0",
"description": "very fast object redaction",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -160,4 +160,5 @@ # fast-redact

of an object it finds a primitive. When `strict` is set to `false`, the redactor function
will return the primitive value without being redacted and if the primitive is of type "string",
the primitive value is returned as JSON (i.e. within double quotes and escaped per JSON rules).
will treat the primitive value as having already been redacted, and return it serialized (with
`JSON.stringify` or the user's custom `serialize` function), or as-is if the `serialize` option
was set to false.

@@ -164,0 +165,0 @@ ## Approach

@@ -37,39 +37,53 @@ 'use strict'

test('returns original value when passed non-object boolean using [strict: false]', ({ end, is, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: false })
doesNotThrow(() => redact(true))
const o = redact(true)
is(o, true)
end()
})
test('returns JSON.stringified value when passed non-object using [strict: false] and no serialize option', ({ end, is, doesNotThrow }) => {
const redactDefaultSerialize = fastRedact({ paths: ['a.b.c'], strict: false })
test('returns original value when passed non-object null using [strict: false]', ({ end, is, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: false })
doesNotThrow(() => redact(null))
const o = redact(null)
is(o, null)
end()
})
// expectedOutputs holds `JSON.stringify`ied versions of each primitive.
// We write them out explicitly though to make the test a bit clearer.
const primitives = [null, undefined, 'A', 1, false]
const expectedOutputs = ['null', undefined, '"A"', '1', 'false']
test('returns original value when passed non-object undefined using [strict: false]', ({ end, is, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: false })
doesNotThrow(() => redact())
const o = redact()
is(o, undefined)
primitives.forEach((it, i) => {
doesNotThrow(() => redactDefaultSerialize(it))
const res = redactDefaultSerialize(it)
is(res, expectedOutputs[i])
})
end()
})
test('returns original value quoted when passed non-object string using [strict: false]', ({ end, is, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: false })
doesNotThrow(() => redact(1))
const o = redact('A')
is(o, '"A"')
test('returns custom serialized value when passed non-object using [strict: false, serialize: fn]', ({ end, is, doesNotThrow }) => {
const customSerialize = (v) => `Hello ${v}!`
const redactCustomSerialize = fastRedact({
paths: ['a.b.c'],
strict: false,
serialize: customSerialize
})
const primitives = [null, undefined, 'A', 1, false]
primitives.forEach((it) => {
doesNotThrow(() => redactCustomSerialize(it))
const res = redactCustomSerialize(it)
is(res, customSerialize(it))
})
end()
})
test('returns original value quoted when passed non-object string using [strict: false]', ({ end, is, doesNotThrow }) => {
const redact = fastRedact({ paths: ['a.b.c'], strict: false })
doesNotThrow(() => redact(1))
const o = redact('A')
is(o, '"A"')
test('returns original value when passed non-object using [strict: false, serialize: false]', ({ end, is, doesNotThrow }) => {
const redactSerializeFalse = fastRedact({
paths: ['a.b.c'],
strict: false,
serialize: false
})
const primitives = [null, undefined, 'A', 1, false]
primitives.forEach((it) => {
doesNotThrow(() => redactSerializeFalse(it))
const res = redactSerializeFalse(it)
is(res, it)
})
end()

@@ -76,0 +90,0 @@ })

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