npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@siddicky/anonymizerts

v1.0.3

Published

TypeScript implementation of Microsoft Presidio using transformers.js for PII detection and anonymization

Readme

AnonymizerTS

A TypeScript implementation of Microsoft Presidio for PII (Personally Identifiable Information) detection and anonymization, powered by Transformers.js v4.

Features

  • 🔍 PII Detection: Automatically detect sensitive information in text

    • Named Entity Recognition (NER) using transformer models
    • Pattern-based recognition for emails, phone numbers, credit cards, SSNs, etc.
  • 🛡️ Anonymization: Multiple anonymization strategies

    • Redact: Replace with entity type label (e.g., <PERSON>)
    • Replace: Substitute with custom values
    • Mask: Partial obfuscation (e.g., ***-**-1234)
    • Hash: One-way cryptographic transformation
  • 🚀 Powered by Transformers.js: Run state-of-the-art NLP models directly in Node.js/Browser

  • 📦 Zero Python Dependencies: Pure TypeScript implementation

  • 🎯 Easy to Use: Simple, intuitive API

Supported Entity Types

  • PERSON - Person names
  • LOCATION - Geographic locations
  • ORGANIZATION - Companies, institutions
  • EMAIL_ADDRESS - Email addresses
  • PHONE_NUMBER - Phone numbers
  • CREDIT_CARD - Credit card numbers
  • US_SSN - US Social Security Numbers
  • IP_ADDRESS - IP addresses
  • URL - Web URLs

Installation

npm install @siddicky/anonymizerts

Quick Start

import { PresidioAnalyzer, PresidioAnonymizer, OperatorType } from '@siddicky/anonymizerts';

async function anonymizeText() {
  // Initialize analyzer
  const analyzer = new PresidioAnalyzer({ useNER: true });
  await analyzer.initialize();

  // Analyze text
  const text = "John Smith's email is [email protected] and phone is (555) 123-4567";
  const results = await analyzer.analyze(text);

  // Anonymize
  const anonymizer = new PresidioAnonymizer({ type: OperatorType.REDACT });
  const anonymized = anonymizer.anonymize(text, results);
  
  console.log(anonymized.text);
  // Output: "<PERSON>'s email is <EMAIL_ADDRESS> and phone is <PHONE_NUMBER>"
}

anonymizeText();

Usage Examples

Example 1: Redact All PII

import { PresidioAnalyzer, PresidioAnonymizer, OperatorType } from '@siddicky/anonymizerts';

const analyzer = new PresidioAnalyzer({ useNER: true });
await analyzer.initialize();

const text = "Contact John at [email protected] or call 555-1234";
const results = await analyzer.analyze(text);

const anonymizer = new PresidioAnonymizer({ type: OperatorType.REDACT });
const anonymized = anonymizer.anonymize(text, results);

console.log(anonymized.text);
// "Contact <PERSON> at <EMAIL_ADDRESS> or call <PHONE_NUMBER>"

Example 2: Selective Masking

import { EntityType, OperatorType } from '@siddicky/anonymizerts';

const operators = new Map();

// Mask phone numbers (show only first 3 digits)
operators.set(EntityType.PHONE_NUMBER, {
  type: OperatorType.MASK,
  maskingChar: '*',
  charsToMask: 7,
  fromEnd: true,
});

// Hash SSNs
operators.set(EntityType.US_SSN, {
  type: OperatorType.HASH,
});

const anonymized = anonymizer.anonymize(text, results, operators);

Example 3: Custom Replacements

const operators = new Map();

operators.set(EntityType.PERSON, {
  type: OperatorType.REPLACE,
  newValue: '[REDACTED]',
});

operators.set(EntityType.EMAIL_ADDRESS, {
  type: OperatorType.REPLACE,
  newValue: '[email protected]',
});

const anonymized = anonymizer.anonymize(text, results, operators);

Example 4: Pattern-Only (No NER)

For faster processing without NER models:

const analyzer = new PresidioAnalyzer({ useNER: false });
// No need to call initialize() when NER is disabled

const results = await analyzer.analyze(text);

API Reference

PresidioAnalyzer

Constructor Options:

  • useNER?: boolean - Enable NER-based recognition (default: true)
  • modelName?: string - Hugging Face model name (default: 'Xenova/bert-base-NER')

Methods:

  • initialize(): Promise<void> - Load NER model (required if useNER is true)
  • analyze(text: string, entities?: EntityType[]): Promise<RecognizerResult[]> - Analyze text for PII

PresidioAnonymizer

Constructor:

  • defaultOperator: OperatorConfig - Default anonymization operator

Methods:

  • anonymize(text: string, results: RecognizerResult[], operators?: Map<EntityType, OperatorConfig>): AnonymizerResult

OperatorConfig

interface OperatorConfig {
  type: OperatorType;
  newValue?: string;          // For REPLACE operator
  maskingChar?: string;       // For MASK operator (default: '*')
  charsToMask?: number;       // For MASK operator
  fromEnd?: boolean;          // For MASK operator
}

Development

# Install dependencies
npm install

# Build
npm run build

# Run example
npm run example

Architecture

AnonymizerTS follows Microsoft Presidio's architecture:

  1. Analyzer: Detects PII using multiple recognizers

    • NERRecognizer: Uses transformers.js for named entity recognition
    • PatternRecognizer: Regex-based patterns for structured data
  2. Anonymizer: Applies anonymization operators to detected entities

    • Supports multiple strategies per entity type
    • Maintains text structure and readability

License

MIT

Credits