Node.js SDK
Zero-dependency PII redaction for Node.js. 86KB package, 0.02ms per redaction.
Installation
$ npm install euredactredact()
Main entry point. Redact PII from a text string. Returns a RedactResult with the cleaned text and a list of detections.
function redact(
text: string,
options?: RedactOptions
): RedactResult| Parameter | Type | Default | Description |
|---|---|---|---|
text | string | — | The input text to redact. |
countries | string[] | undefined | Country codes (e.g. ["NL", "BE"]). Recommended for best precision. Omit to detect all supported countries. |
referentialIntegrity | boolean | false | Replace PII with consistent labels (ENTITY_1, ENTITY_2, ...) instead of generic type labels. |
detectDates | boolean | false | Include DOB and date-of-death detections. Off by default. |
cache | boolean | true | Enable result caching for faster subsequent calls. |
Return value
A RedactResult object with:
| Parameter | Type | Default | Description |
|---|---|---|---|
redactedText | string | — | The text with PII replaced by labels like [NATIONAL_ID], [IBAN], etc. |
detections | Detection[] | — | Array of detected PII entities with type, value, position, and country. |
source | string | — | Source identifier for the redaction engine. |
degraded | boolean | — | Whether the result was produced in a degraded mode. |
Detection
Each detection in the array contains:
| Parameter | Type | Default | Description |
|---|---|---|---|
entityType | EntityType | — | The type of PII detected (enum value). |
start | number | — | Start character index in the original text. |
end | number | — | End character index in the original text. |
text | string | — | The original PII text that was detected. |
source | DetectionSource | — | The detection engine that found this entity. |
country | string | null | — | The country code associated with this detection, or null. |
confidence | string | — | Confidence level of the detection. |
Example
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.
function redactBatch(
texts: string[],
options?: RedactOptions
): RedactResult[]Example
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.
function addCustomPattern(
entityType: string,
pattern: string
): void| Parameter | Type | Default | Description |
|---|---|---|---|
entityType | string | — | The label to use for matches (e.g. "EMPLOYEE_ID"). |
pattern | string | — | A regex pattern string to match against input text. |
Example
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.
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].
import { redact } from "euredact";
const result = redact(
"My API key is sk-proj-abc123def456ghi789"
);
console.log(result.redactedText);
// "My API key is [SECRET]"Performance
Supported Countries
31 European and EEA countries with country-specific PII patterns.
Entity Types
View source on GitHub
Browse the code, report issues, or contribute.