const innerObj = {
foo: 'xcvb',
bar: 'vbnm',
baz: 'qwer',
qux: 'wert'
};
const obj = {
foo: 'abcd',
bar: {
foo: 'abcd',
bar: {
foo: 'abcd',
baz: 'efgh',
qux: 'ijkl',
quux: [
innerObj,
innerObj,
innerObj,
innerObj,
innerObj,
innerObj,
innerObj,
innerObj
]
},
baz: 'efgh',
qux: 'ijkl'
},
baz: 'efgh',
qux: 'ijkl'
};
function traverse(obj1, predicate) {
for (const [key, value] of Object.entries(obj1)) {
if (typeof(value) === 'string') {
if (predicate(key)) {
obj[key] = '***';
}
} else {
traverse(value, predicate);
}
}
}
const keysToRedactArray = ['foo', 'qux'];
for (let i = 0; i < 30; i++) {
const dummyKey = Math.random().toString(36).substr(2, 5);
keysToRedactArray.push(dummyKey);
}
const keysToRedactSet = new Set(keysToRedactArray);