/redact-pii

Remove personally identifiable information from text.

Primary LanguageJavaScriptMIT LicenseMIT

redact-pii

NPM Package Build Status Coverage Status Commitizen friendly Dependencies

Remove personally identifiable information from text.

Usage

npm install redact-pii
var redactor = require('redact-pii')();
var redacted = redactor.redact('Hi David Johnson, Please give me a call at 555-555-5555');
// Hi NAME, Please give me a call at PHONE_NUMBER

API

Redactor(options)

  • options {Object}
    • replace {String|Function} If a string, the value will be used as the replacement for all identified patterns. If a function, the function will be called with the name of each pattern to determine the replacement value for the pattern.
    • * {RegExp|false} Any other key in options will be treated as a regular expression to use for replacing matches, false if no replacement is desired for a particular pattern. The following patterns are enabled by default.
      • credentials
      • creditCardNumber
      • emailAddress
      • ipAddress
      • name
      • password
      • phoneNumber
      • streetAddress
      • username
      • ssn
      • zipcode
      • url
      • digits

redactor.redact(text)

  • text {String} The text which contains PII to redact
  • returns {String} The text with PII redacted

Customization

Replacement Values

var redactor = require('redact-pii')({replace: 'TOP_SECRET'});
redactor.redact('Dear David Johnson, I live at 42 Wallaby Way');
// Dear TOP_SECRET, I live at TOP_SECRET

var redactor = require('redact-pii')({
  replace: function (name, defaultReplacement) {
    if (name === 'creditCardNumber') {
      return value => 'XXXXXXXXXXXX' + value.slice(12);
    } else {
      return defaultReplacement;
    }
  }
});
redactor.redact('my CC is 1234567812345678');
// my CC is XXXXXXXXXXXX5678

Patterns

var redactor = require('redact-pii')({name: false});
redactor.redact('Dear David Johnson, I live at 42 Wallaby Way');
// Dear David Johnson, I live at STREET_ADDRESS


var redactor = require('redact-pii')({animal: /\b(cat|dog|cow)s?\b/gi});
redactor.redact('I love cats, dogs, and cows');
// I love ANIMAL, ANIMAL, and ANIMAL