Skip to content

Replace using function

Choose a tag to compare

@shaunburdick shaunburdick released this 06 Jun 15:25
· 41 commits to main since this release

Added the ability to use a function to replace the value.

Example:

const obj = {
   firstname: 'Han',
   lastname: 'Solo',
};

const replacer =  val => `[ REDACTED (${val.length}) ]`;
const redacted = redact(obj, ['firstname', 'lastname'], replacer);

/**
 * Results in:
 * {
 *   firstname: '[ REDACTED (3) ]',
 *   lastname: '[ REDACTED (4) ]',
 * };
 */

Thanks @dylansmith for the suggestion!