UNPKG

redact-pii

Version:

Remove personally identifiable information from text.

23 lines (19 loc) 541 B
import { ISyncRedactor } from '../types'; import { snakeCase } from 'lodash'; export class SimpleRegexpRedactor implements ISyncRedactor { regexpMatcher: RegExp; replaceWith: string; constructor({ replaceWith = snakeCase().toUpperCase(), regexpPattern: regexpMatcher, }: { replaceWith: string; regexpPattern: RegExp; }) { this.replaceWith = replaceWith; this.regexpMatcher = regexpMatcher; } redact(textToRedact: string) { return textToRedact.replace(this.regexpMatcher, this.replaceWith); } }