SDK and operations
Use maskera (rules + 68 MB Swedish AI model) or @maskera/core (rules only, zero dependencies) directly in your own TypeScript or JavaScript code.
Pick a package
Both packages share the same synchronous rule engine and restore map. maskera re-exports everything from @maskera/core. Both run in the browser (WASM or WebGPU) and in Node 18+.
| Package | Includes | Best when |
|---|---|---|
| maskera + @huggingface/transformers | Deterministic Swedish rules + the maskera-sv-ner ONNX model (68 MB in q4, 100 MB in q8). | Free-form Swedish text with names, street addresses, places, and organisations. |
| @maskera/core | Format and check-digit rules only, zero dependencies, synchronous. | Structured logs, constrained runtimes, or when you want no model weights. |
npm install maskera @huggingface/transformersimport { createNerRecognizer, redactWithNer } from "maskera"const recognizer = createNerRecognizer()const { text, restore } = await redactWithNer( "hej jag heter anna karlsson, personnummer 19900101-2385, och bor i uppsala", { recognizer },)// text: "hej jag heter [NAMN_1], personnummer [PERSONNUMMER_1], och bor i [PLATS_1]"const answer = await askAI(text)restore(answer)Core flow, clinical profile, and custom detectors
Create one recognizer at startup and reuse it across calls. For Swedish healthcare text, profile: "clinical" retains doses, measurements, and care terms while masking personal data. Add custom patterns with regexDetector.
import { createNerRecognizer, hybridDefaultDetectors, redactWithNer, regexDetector,} from "maskera"const recognizer = createNerRecognizer()// Custom patterns are added to the built-in rules, not used instead of themconst caseIdDetector = regexDetector("ARENDE", /(?<!\p{L})ÄRENDE-\d{4}-\d{4}(?!\p{L})/gu)const { text, restore } = await redactWithNer( "Patient Anna Lindqvist (19900101-2385) i ÄRENDE-2026-0412 fick Alvedon 500 mg.", { recognizer, profile: "clinical", detectors: [...hybridDefaultDetectors, caseIdDetector], },)// text: "Patient [NAMN_1] ([PERSONNUMMER_1]) i [ARENDE_1] fick Alvedon 500 mg."const answer = await callYourModel(text)const finalReply = restore(answer)Self-hosting the model and offline operation
By default, the model weights are fetched once from Hugging Face, checked with sha256 against a pinned commit, and cached locally. On air-gapped networks, download the model once and point to the folder.
// Download the model once, pinned to the published revision:// hf download joelhagvall/maskera-sv-ner onnx/model_quantized.onnx config.json \// tokenizer.json tokenizer_config.json special_tokens_map.json \// --revision e0d5d017383c2732c5cc3c962fd1afdd73bb8035 \// --local-dir /opt/models/maskera-sv-ner-v24// q8 is fastest on Node CPU; use q4 in browsersconst recognizer = createNerRecognizer({ localModelPath: "/opt/models", model: "maskera-sv-ner-v24", allowRemoteModels: false, dtype: "q8",})Production checklist
Maskera is defense in depth, not a zero-leak compliance guarantee.
- Reuse one createNerRecognizer() instance per process so the model is not reloaded per request.
- Never store the restore map in the same log, database, or trace as the redacted text.
- Fail closed on model errors: never fall through and forward unredacted text if NER throws.
- Run a synthetic smoke test on deploy with made-up Swedish data before sending real traffic.