307 tests · zero runtime dependencies · MIT

Swedish PII detection & masking

Finds names, personnummer, addresses, financial and sensitive data in Swedish text — with checksum validation, confidence scores and exact offsets. Runs anywhere JavaScript runs.

GitHub
47
PII labels
151k+
registered names
22,350
OSM streets
~0.1 ms
per detection

Live playground

Input
Masked output
Loading detection engine…

What can be detected?

Every detector reports a confidence score — checksum-validated matches score 0.95, gazetteer hits 0.9, plain shapes 0.6.

👤

Names

20,524 male + 23,347 female first names and 107,762 surnames from SCB, fuzzy-matched with Jaro–Winkler.

🆔

Identity numbers

Personnummer, samordningsnummer and passport numbers — with Luhn checksums and real calendar-date validation.

💳

Financial

Cards (Luhn), IBAN (mod-97), BIC, bank accounts, Bankgiro & Plusgiro, VAT numbers and crypto wallets.

📞

Contact

Email addresses, Swedish phone formats and social media handles & profile URLs.

📍

Location

22,350 OSM streets, postal codes, 290 municipalities, 21 counties, cities, GPS coordinates and property designations.

🏢

Work & education

Organizations, org numbers (Luhn), 414 professions and SUN education programs.

🔒

Sensitive attributes

Marital status, religion, disability, orientation, demographics, political ideology and union membership.

🧩

Misc

License plates, IPv4 & IPv6, MAC addresses, dates, times, case numbers and age.

mask.ts
import { maskPII } from "swedish-pii";

const { maskedText, entities } = maskPII(
  "Anna Andersson bor på Storgatan 12."
);

// "<PER_FIRST_1> <PER_LAST_1> bor på <SE_STREET_ADDRESS_1>."
// entities → exact offsets + confidence scores

maskPII(text, { strict: true });          // checksums must pass
maskPII(text, { scoreThreshold: 0.2 });   // recall-first