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.0.1 to 1.1.0

8

index.js

@@ -26,3 +26,9 @@ 'use strict'

) : JSON.stringify
const censor = 'censor' in opts ? opts.censor : DEFAULT_CENSOR
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

@@ -29,0 +35,0 @@ if (paths.length === 0) return serialize || noop

18

lib/parse.js

@@ -9,2 +9,3 @@ 'use strict'

const wildcards = []
var wcLen = 0
const secret = paths.reduce(function (o, strPath) {

@@ -21,19 +22,24 @@ var path = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ''))

const after = path.slice(star + 1, path.length)
if (after.indexOf('*') > -1) throw Error('Only one wildcard per path is supported')
const afterStr = after.join('.')
if (after.indexOf('*') > -1) throw Error('fast-redact – Only one wildcard per path is supported')
const nested = after.length > 0
wcLen++
wildcards.push({
before,
beforeStr,
afterStr,
after,
nested
})
} else o[strPath] = {path: path, val: null, precensored: false, circle: '', escPath: JSON.stringify(strPath)}
} else {
o[strPath] = {
path: path,
val: null,
precensored: false,
circle: '',
escPath: JSON.stringify(strPath)
}
}
return o
}, {})
const wcLen = Object.keys(wildcards).length
return { wildcards, wcLen, secret }
}
{
"name": "fast-redact",
"version": "1.0.1",
"version": "1.1.0",
"description": "very fast object redaction",

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

@@ -88,2 +88,16 @@ # fast-redact

#### `remove` - `Boolean` - `[false]`
The `remove` option, when set to `true` will cause keys to be removed from the
serialized output.
Since the implementation exploits the fact the `undefined` keys are ignored
by `JSON.stringify` the `remove` option may *only* be used when `JSON.stringify`
is the serializer (this is the default) – otherwise `fast-redact` will throw.
If supplying a custom serializer that has the same behavior (removing keys
with `undefined` values), this restriction can be bypassed by explicitly setting
the `censor` to `undefined`.
#### `censor` – `<Any type - Except Function>` – `('[REDACTED]')`

@@ -90,0 +104,0 @@

@@ -135,6 +135,20 @@ 'use strict'

fastRedact({paths: ['a.*.x.*'], serialize: false})
}, Error('Only one wildcard per path is supported'))
}, Error('fast-redact – Only one wildcard per path is supported'))
end()
})
test('throws if a custom serializer is used and remove is true', ({end, throws}) => {
throws(() => {
fastRedact({paths: ['a'], serialize: (o) => o, remove: true})
}, Error('fast-redact – remove option may only be set when serializer is JSON.stringify'))
end()
})
test('throws if serialize is false and remove is true', ({end, throws}) => {
throws(() => {
fastRedact({paths: ['a'], serialize: false, remove: true})
}, Error('fast-redact – remove option may only be set when serializer is JSON.stringify'))
end()
})
test('masks according to supplied censor', ({end, is}) => {

@@ -173,2 +187,11 @@ const censor = 'test'

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"}`)
is(o.a, 'a')
end()
})
test('serializes with JSON.stringify if serialize is true', ({end, is}) => {

@@ -175,0 +198,0 @@ const redact = fastRedact({paths: ['a'], serialize: true})

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