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

@aismarttalk/anondocs-sdk

v1.2.1

Published

TypeScript SDK for AnonDocs API - Privacy-first text and document anonymization

Readme

AnonDocs SDK

TypeScript/JavaScript SDK for AnonDocs - Privacy-first text and document anonymization powered by LLMs.

Made with ❤️ by AI SmartTalk

Installation

npm install @aismarttalk/anondocs-sdk

Quick Start

import { AnonDocsClient } from '@aismarttalk/anondocs-sdk';

const client = new AnonDocsClient({
  baseUrl: 'http://localhost:3000',
  defaultProvider: 'ollama'
});

// Anonymize text
const result = await client.anonymizeText('My name is John Smith and my email is [email protected]');

console.log(result.anonymizedText);
// Output: "My name is [NAME] and my email is [EMAIL]"

console.log(result.piiDetected);
// Output: { names: ['John Smith'], emails: ['[email protected]'], ... }

console.log(result.replacements);
// Output: [
//   { original: 'John Smith', anonymized: '[NAME]' },
//   { original: '[email protected]', anonymized: '[EMAIL]' }
// ]

Features

  • 🔒 Privacy-first anonymization using local or cloud LLMs
  • 📄 Document support (PDF, DOCX, TXT)
  • DOCX formatting preserved - Bold, italic, colors, and more!
  • 🎯 Precision mapping - Track every replacement with replacements array
  • 🌊 Streaming with real-time progress updates
  • 💾 Full TypeScript support with strict types
  • 🚀 Works in Node.js and Browser
  • Multiple LLM providers (OpenAI, Anthropic, Ollama)
  • 🆓 Zero runtime dependencies

API Reference

Initialize Client

const client = new AnonDocsClient({
  baseUrl: 'http://localhost:3000',  // Optional, defaults to localhost
  defaultProvider: 'ollama',          // Optional: 'openai' | 'anthropic' | 'ollama'
  timeout: 30000                      // Optional, defaults to 30s
});

Check Health

const health = await client.health();
// Returns: { status: 'ok', timestamp: '2025-11-04T...' }

Anonymize Text

const result = await client.anonymizeText(
  'John Smith lives at 123 Main St and his email is [email protected]',
  { provider: 'ollama' }  // Optional, uses defaultProvider if not specified
);

console.log(result.anonymizedText);
console.log(result.piiDetected);
console.log(result.processingTimeMs);
console.log(result.wordsPerMinute);
console.log(result.chunksProcessed);

Anonymize Document

Node.js:

import { readFileSync } from 'fs';

const fileBuffer = readFileSync('./document.pdf');
const result = await client.anonymizeDocument(fileBuffer, {
  provider: 'ollama'
});

// For DOCX files: formatting is preserved!
if (result.downloadUrl) {
  console.log('Download anonymized DOCX:', result.downloadUrl);
  console.log('Original filename:', result.originalFilename);
}

// Access replacement mappings
result.replacements.forEach(r => {
  console.log(`"${r.original}" → "${r.anonymized}"`);
});

Browser:

const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];

const result = await client.anonymizeDocument(file, {
  provider: 'openai'
});

// Download DOCX with preserved formatting
if (result.downloadUrl) {
  window.open(result.downloadUrl, '_blank');
}

Streaming Anonymization

Get real-time progress updates for long texts or documents:

await client.streamAnonymizeText(longText, {
  provider: 'ollama',
  onProgress: (event) => {
    console.log(`${event.progress}% - ${event.message}`);
    // Progress: 0-100
    // Types: 'started', 'chunk_processing', 'chunk_completed', 'completed', 'error'
  },
  onComplete: (result) => {
    console.log('Done!', result.anonymizedText);
  },
  onError: (error) => {
    console.error('Error:', error.message);
  }
});

Streaming Document Anonymization

await client.streamAnonymizeDocument(file, {
  provider: 'ollama',
  onProgress: (event) => {
    updateProgressBar(event.progress);
  },
  onComplete: (result) => {
    displayResults(result);
  },
  onError: (error) => {
    showError(error);
  }
});

Response Types

AnonymizationResult

interface AnonymizationResult {
  anonymizedText: string;
  piiDetected: {
    names: string[];
    addresses: string[];
    emails: string[];
    phoneNumbers: string[];
    dates: string[];
    organizations: string[];
    other: string[];
  };
  replacements: Array<{
    original: string;      // Exact original PII text
    anonymized: string;    // What it was replaced with (e.g., "[NAME]")
  }>;
  chunksProcessed: number;
  wordsPerMinute: number;
  processingTimeMs: number;
  // DOCX only: present when document is DOCX with preserved formatting
  downloadUrl?: string;
  filename?: string;
  originalFilename?: string;
}

What's New:

  • replacements - Precision mapping of original → anonymized text
  • downloadUrl - Download link for DOCX files with preserved formatting
  • filename - Generated filename for the anonymized document
  • originalFilename - Original document filename

ProgressEvent

interface ProgressEvent {
  type: 'started' | 'chunk_processing' | 'chunk_completed' | 'completed' | 'error';
  progress: number;        // 0-100
  message: string;
  currentChunk?: number;   // 1-indexed
  totalChunks?: number;
  data?: AnonymizationResult;  // Only on 'completed'
}

Error Handling

The SDK provides typed error classes:

import { 
  AnonDocsError,
  AnonDocsApiError,
  AnonDocsNetworkError,
  AnonDocsValidationError,
  AnonDocsStreamError
} from '@aismarttalk/anondocs-sdk';

try {
  await client.anonymizeText('');
} catch (error) {
  if (error instanceof AnonDocsValidationError) {
    console.error('Validation error:', error.message);
  } else if (error instanceof AnonDocsApiError) {
    console.error('API error:', error.statusCode, error.message);
  } else if (error instanceof AnonDocsNetworkError) {
    console.error('Network error:', error.message);
  }
}

Supported File Types

  • DOCX: application/vnd.openxmlformats-officedocument.wordprocessingml.document
    • Formatting preserved (bold, italic, colors, alignment, etc.)
    • Download link provided via downloadUrl
    • Best anonymization experience
  • PDF: application/pdf
    • ⚠️ Text extraction only (no formatting preserved)
    • Returns anonymized text in response
  • TXT: text/plain
    • Plain text anonymization
    • Returns anonymized text in response

Max file size: 10MB

LLM Providers

  • OpenAI - Cloud-based, requires API key
  • Anthropic - Cloud-based, requires API key
  • Ollama - Local/self-hosted, privacy-first

Examples

See the examples/ directory for complete usage examples:

TypeScript Support

The SDK is written in TypeScript and includes full type definitions. All types are exported:

import type {
  LLMProvider,
  PIIDetected,
  PIIReplacement,
  AnonymizationResult,
  ProgressEvent,
  ClientConfig
} from '@aismarttalk/anondocs-sdk';

Requirements

  • Node.js: >= 18.0.0 (uses native fetch, FormData, Blob)
  • Browser: Modern browsers with fetch and ReadableStream support
  • Zero runtime dependencies - works everywhere!

License

MIT

Links

Made with ❤️ by AI SmartTalk