pii-mask

createMasker

Factory function that returns a configured masker instance.

Usage

import { createMasker } from '@pii-mask/core';

const masker = createMasker({
  mode: 'mask',
  disable: ['person-name'],
});

Options

OptionTypeDefaultDescription
modeMaskMode'mask'Masking mode to use
disablestring[][]Detector IDs to disable
onlystring[]undefinedRun only these detectors
extendPIIDetector[][]Additional custom detectors
keyNameOnlybooleanfalseSkip regex detection, use key heuristics only

Return value

The returned masker exposes four methods:

  • maskString(input, key?) — mask a single string value
  • maskObject(input) — deep-walk an object and mask all string values
  • maskArray(input) — deep-walk an array and mask all string values
  • restore(masked, tokenMap) — reverse tokenization

Each masking method returns a MaskResult:

interface MaskResult {
  result: string;
  tokenMap: Record<string, string>;
  detections: string[];
}

Try it in the browser ↗