diff --git a/index.js b/index.js index 8c98cf6..562345f 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ * Module dependencies. */ -const { cloneDeepWith, isObject, some } = require('lodash'); +const { cloneDeepWith, isObject, toLower, some } = require('lodash'); /** * Export `maskJson` function. @@ -15,13 +15,8 @@ module.exports = function maskJson(collection, { } = {}) { return function(values) { return cloneDeepWith(values, (value, key) => { - // The top-most object has no key. - if (!key) { - return; - } - // Strip matching keys. - if (some(collection, (item) => ignoreCase ? key.toLowerCase() === item.toLowerCase() : key === item)) { + if (some(collection, item => ignoreCase ? toLower(key) === toLower(item) : key === item)) { return replacement; } @@ -34,4 +29,4 @@ module.exports = function maskJson(collection, { return value; }); }; -} +}; diff --git a/test/index_test.js b/test/index_test.js index 8a90c69..8355217 100644 --- a/test/index_test.js +++ b/test/index_test.js @@ -12,6 +12,7 @@ const maskJson = require('../index'); describe('maskJson()', () => { it('should accept a custom `ignoreCase`', () => { const object = { + bar: ['biz', 'baz'], foo: { PaSSWorD: 'barbiz', password: 'foobar', @@ -20,6 +21,7 @@ describe('maskJson()', () => { }; maskJson(['password', 'secret'], { ignoreCase: true })(object).should.eql({ + bar: ['biz', 'baz'], foo: { PaSSWorD: '--REDACTED--', password: '--REDACTED--',