TypeScript client for the PiiSweep API — Swedish PII detection and stripping.
npm install piisweepimport { PiiSweep } from "piisweep";
const pii = new PiiSweep("pg_live_...");
// Strip PII from text
const stripped = await pii.strip("Ring Johan Andersson på 070-123 45 67");
console.log(stripped.stripped_text);
// "Ring [NAMN] på [TELEFON]"
// Detect PII without stripping
const detected = await pii.detect("Personnummer: 199001011234");
console.log(detected.pii_found); // true
console.log(detected.detections);
// [{ type: "personnummer", original: "199001011234", placeholder: "[PERSONNUMMER]" }]// API key only
const pii = new PiiSweep("pg_live_...");
// With options
const pii = new PiiSweep({
apiKey: "pg_live_...",
baseUrl: "http://localhost:3000", // default: "https://piisweep.com"
});Strip PII from text, replacing detections with placeholders.
const result = await pii.strip("Email: test@example.com", ["email"]);Returns StripResult:
| Field | Type | Description |
|---|---|---|
original_length |
number |
Character count of input text |
stripped_length |
number |
Character count of output text |
stripped_text |
string |
Text with PII replaced |
detections |
PiiDetection[] |
List of detected PII |
processing_time_ms |
number |
Server processing time in ms |
Detect PII in text without modifying it.
const result = await pii.detect("Ring 08-123 456");Returns DetectResult:
| Field | Type | Description |
|---|---|---|
original_length |
number |
Character count of input text |
detections |
PiiDetection[] |
List of detected PII |
pii_found |
boolean |
Whether any PII was found |
processing_time_ms |
number |
Server processing time in ms |
Pass an optional array to scan for specific types only:
await pii.strip(text, ["personnummer", "email"]);Available types: personnummer, phone, email, name
API errors throw PiiSweepError with code, message, and status:
import { PiiSweep, PiiSweepError } from "piisweep";
try {
await pii.strip(text);
} catch (err) {
if (err instanceof PiiSweepError) {
console.error(err.code); // "UNAUTHORIZED"
console.error(err.status); // 401
console.error(err.message); // "Invalid or missing API key"
}
}All types are exported for use in your application:
import type {
PiiType,
PiiDetection,
StripResult,
DetectResult,
PiiSweepOptions,
} from "piisweep";MIT