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.1.14 to 1.2.0

3

index.js

@@ -41,4 +41,5 @@ 'use strict'

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

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

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

function redactor ({secret, serialize, wcLen}, state) {
function redactor ({secret, serialize, wcLen, strict}, state) {
/* eslint-disable-next-line */
const redact = Function('o', `
if (typeof o !== 'object' || o == null) {
throw Error('fast-redact: primitives cannot be redacted')
${strictImpl(strict)}
}

@@ -47,3 +47,3 @@ const { censor, secret } = this

${hops.reverse().map((p) => `
case o${delim}${p} === censor:
case o${delim}${p} === censor:
secret[${escPath}].circle = ${JSON.stringify(p)}

@@ -91,1 +91,5 @@ break

}
function strictImpl (strict) {
return strict === true ? `throw Error('fast-redact: primitives cannot be redacted')` : `return o`
}

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

wildcards,
wcLen
wcLen,
} = o

@@ -17,0 +17,0 @@ const builder = [{secret, censor, compileRestore}]

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

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

@@ -157,2 +157,7 @@ # fast-redact

#### `strict` – `Boolean` - `[true]`
The `strict` option, when set to `true`, will cause the redactor function to throw if instead
of an object it finds a primitive. When `strict` is set to `false`, the redactor function
will return the primitive value without being redacted.
## Approach

@@ -159,0 +164,0 @@

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

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

@@ -31,2 +31,16 @@ end()

test('throws when passed non-object using [strict: true]', ({end, throws}) => {
const redact = fastRedact({paths: ['a.b.c'], strict: true})
throws(() => redact(1))
end()
})
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))
const o = redact(1)
is(o, 1)
end()
})
test('throws if a path is not a string', ({end, is, throws}) => {

@@ -33,0 +47,0 @@ throws((e) => {

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