SDK Reference

Node.js SDK

Zero-dependency PII redaction for Node.js. 86KB package, 0.02ms per redaction.

Installation

Terminal
$ npm install euredact

redact()

Main entry point. Redact PII from a text string. Returns a RedactResult with the cleaned text and a list of detections.

Signature
function redact(
  text: string,
  options?: RedactOptions
): RedactResult
ParameterTypeDefaultDescription
textstringThe input text to redact.
countriesstring[]undefinedCountry codes (e.g. ["NL", "BE"]). Recommended for best precision. Omit to detect all supported countries.
referentialIntegritybooleanfalseReplace PII with consistent labels (ENTITY_1, ENTITY_2, ...) instead of generic type labels.
detectDatesbooleanfalseInclude DOB and date-of-death detections. Off by default.
cachebooleantrueEnable result caching for faster subsequent calls.

Return value

A RedactResult object with:

ParameterTypeDefaultDescription
redactedTextstringThe text with PII replaced by labels like [NATIONAL_ID], [IBAN], etc.
detectionsDetection[]Array of detected PII entities with type, value, position, and country.
sourcestringSource identifier for the redaction engine.
degradedbooleanWhether the result was produced in a degraded mode.

Detection

Each detection in the array contains:

ParameterTypeDefaultDescription
entityTypeEntityTypeThe type of PII detected (enum value).
startnumberStart character index in the original text.
endnumberEnd character index in the original text.
textstringThe original PII text that was detected.
sourceDetectionSourceThe detection engine that found this entity.
countrystring | nullThe country code associated with this detection, or null.
confidencestringConfidence level of the detection.

Example

index.ts
import { redact } from "euredact";

const result = redact(
  "Mijn BSN is 111222333 en IBAN NL91ABNA0417164300.",
  { countries: ["NL"] }
);

console.log(result.redactedText);
// "Mijn BSN is [NATIONAL_ID] en IBAN [IBAN]."

console.log(result.detections);

redactBatch()

Process multiple texts efficiently. Loads country configs once. Same options as redact(), returns an array of RedactResult.

Signature
function redactBatch(
  texts: string[],
  options?: RedactOptions
): RedactResult[]

Example

batch.ts
import { redactBatch } from "euredact";

const results = redactBatch([
  "BSN 111222333",
  "IBAN DE89370400440532013000",
]);

results.forEach((r) => {
  console.log(r.redactedText);
});

addCustomPattern()

Register a custom regex pattern at runtime. Detected matches will be labeled with the given entity type.

Signature
function addCustomPattern(
  entityType: string,
  pattern: string
): void
ParameterTypeDefaultDescription
entityTypestringThe label to use for matches (e.g. "EMPLOYEE_ID").
patternstringA regex pattern string to match against input text.

Example

custom.ts
import { addCustomPattern, redact } from "euredact";

addCustomPattern("EMPLOYEE_ID", "EMP-\\d{6}");

const result = redact("Contact EMP-123456 for details");

console.log(result.redactedText);
// "Contact [EMPLOYEE_ID] for details"

availableCountries()

Returns an array of supported ISO country codes.

example.ts
import { availableCountries } from "euredact";

console.log(availableCountries());  // ["AT", "BE", "BG", ...]

Secret Detection

euRedact automatically detects secrets and API keys using two strategies: known-prefix patterns for popular services (AWS, GitHub, Stripe, OpenAI, Slack, JWT, SendGrid) and an entropy-based fallback that catches generic secrets near context keywords like api_key, token, and secret. Detected secrets are labeled as [SECRET].

secrets.ts
import { redact } from "euredact";

const result = redact(
  "My API key is sk-proj-abc123def456ghi789"
);

console.log(result.redactedText);
// "My API key is [SECRET]"

Performance

~0.02ms
Per page (~500 words)
~50,000
Records per second
~50KB
Memory per country
86KB
Package size
0
Dependencies

Supported Countries

31 European and EEA countries with country-specific PII patterns.

ATBEBGCHCYCZDEDKEEELESFIFRHRHUIEISITLTLULVMTNLNOPLPTROSESISKUK

Entity Types

[NAME][ADDRESS][IBAN][BIC][CREDIT_CARD][PHONE][EMAIL][DOB][DATE_OF_DEATH][NATIONAL_ID][SSN][TAX_ID][PASSPORT][DRIVERS_LICENSE][RESIDENCE_PERMIT][LICENSE_PLATE][VIN][VAT][POSTAL_CODE][IP_ADDRESS][IPV6_ADDRESS][MAC_ADDRESS][HEALTH_INSURANCE][HEALTHCARE_PROVIDER][CHAMBER_OF_COMMERCE][IMEI][GPS_COORDINATES][UUID][SOCIAL_HANDLE][SECRET][OTHER]

View source on GitHub

Browse the code, report issues, or contribute.

GitHubarrow_outward