fast-redact
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -91,3 +91,3 @@ 'use strict' | ||
function strictImpl (strict) { | ||
return strict === true ? `throw Error('fast-redact: primitives cannot be redacted')` : `return o` | ||
return strict === true ? `throw Error('fast-redact: primitives cannot be redacted')` : `return typeof o === 'string' ? JSON.stringify(o) : o` | ||
} |
{ | ||
"name": "fast-redact", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "very fast object redaction", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -160,3 +160,4 @@ # 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. | ||
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). | ||
@@ -163,0 +164,0 @@ ## Approach |
@@ -31,3 +31,3 @@ 'use strict' | ||
test('throws when passed non-object using [strict: true]', ({ end, throws }) => { | ||
test('throws when passed non-object number using [strict: true]', ({ end, throws }) => { | ||
const redact = fastRedact({ paths: ['a.b.c'], strict: true }) | ||
@@ -38,10 +38,42 @@ throws(() => redact(1)) | ||
test('returns original value when passed non-object using [strict: false]', ({ end, is, doesNotThrow }) => { | ||
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 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() | ||
}) | ||
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) | ||
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(1) | ||
is(o, 1) | ||
const o = redact('A') | ||
is(o, '"A"') | ||
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"') | ||
end() | ||
}) | ||
test('throws if a path is not a string', ({ end, is, throws }) => { | ||
@@ -48,0 +80,0 @@ throws((e) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63306
1404
280