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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redactum

v1.1.0

Published

Comprehensive PII redaction library for AI applications with framework adapters for LangChain, LlamaIndex, Haystack, OpenAI SDK, Anthropic SDK, and Vercel AI SDK

Readme

⛨ redactum - automated PII & secret redaction

NPM Version Codecov Install Size Build

What It Does

Fast, zero-dependency PII redaction library for TypeScript and JavaScript that automatically removes sensitive data before it leaves your stack.

Redactum protects you and your users by redacting:

  • 👤 Personal information (emails, phone numbers, SSNs)
  • 💳 Financial data (credit cards, bank accounts)
  • 🔑 Developer secrets (API keys, database URLs, JWT tokens)
  • 🏗️ Infrastructure details (IP addresses, AWS credentials)

190+ built-in patterns across 32 categories for comprehensive detection of personal, financial, and technical sensitive data.

Installation

pnpm install redactum

Quick Start

import { redactum } from "redactum";

const userMessage = `Errors found in cloudwatch
ERROR: Failed to connect to database
DEBUG: DATABASE=postgres://admin:u$k9!fR2@qLx2@db:5432/db`;

const result = redactum(userMessage);
Errors found in cloudwatch
ERROR: Failed to connect to database
DEBUG: DATABASE=postgres://[REDACTED]:[REDACTED]@db:5432/db

Provider Integrations

Redactum works seamlessly with popular AI SDKs:

OpenAI

import { createOpenAIAdapter } from "redactum/providers";
import OpenAI from "openai";

const adapter = createOpenAIAdapter();
const openai = adapter.createClientWrapper(new OpenAI());

const completion = await openai.chat.completions.create({
  model: "gpt-4",
  messages: [
    {
      role: "user",
      content: `Errors found in cloudwatch
                ERROR: Failed to connect to database
                DEBUG: DATABASE=postgres://admin:u$k9!fR2@qLx2@db:5432/db`,
    },
  ],
});

Anthropic

import { createAnthropicAdapter } from "redactum/providers";
import Anthropic from "@anthropic-ai/sdk";

const adapter = createAnthropicAdapter();
const anthropic = adapter.createClientWrapper(new Anthropic());

const message = await anthropic.messages.create({
  model: "claude-3-5-sonnet-20241022",
  max_tokens: 1000,
  messages: [
    {
      role: "user",
      content: "Process this: API_KEY=sk_live_4eC39HqLyjWDarjtT1zdp7dc",
    },
  ],
});

LangChain

import { createLangChainAdapter } from "redactum/providers";
import { Document } from "@langchain/core/documents";

const adapter = createLangChainAdapter();
const transformer = adapter.createDocumentTransformer();

const docs = await transformer([
  new Document({
    pageContent: "Contact: [email protected], Phone: +44 20 7946 0958",
  }),
]);

Vercel AI

import { createVercelAIAdapter } from "redactum/providers";
import { openai } from "@ai-sdk/openai";

const adapter = createVercelAIAdapter();
const { streamText } = adapter.createStreamingWrapper();

const result = await streamText({
  model: openai("gpt-4"),
  prompt: "Credit card: 4111-1111-1111-1111",
});

LlamaIndex

import { createLlamaIndexAdapter } from "redactum/providers";
import { TextNode } from "llamaindex";

const adapter = createLlamaIndexAdapter();
const transformer = adapter.createNodeTransformer();

const nodes = await transformer.transform([
  new TextNode({
    text: "SSN: 123-45-6789",
  }),
]);

Usage

Basic Redaction

import { redactum } from "redactum";

const result = redactum("Email me at [email protected]");
console.log(result.redactedText);

Custom Replacement

const result = redactum("Email: [email protected]", {
  replacement: "***",
});

const result = redactum("Email: [email protected]", {
  replacement: (match, category) => `[${category}]`,
});

Selective Redaction

const result = redactum("Email: [email protected], SSN: 123-45-6789", {
  policies: ["EMAIL_ADDRESS", "SSN"],
});

Custom Patterns

import { PolicyCategory } from "redactum";

const result = redactum("Employee: EMP-123456", {
  customPolicies: [
    {
      name: "EMPLOYEE_ID",
      pattern: /EMP-\d{6}/g,
      category: PolicyCategory.CUSTOM,
    },
  ],
});

Length Preservation

const result = redactum("Stripe: sk_live_4eC39HqLyjWDarjtT1zdp7dc", {
  preserveLength: true,
  replacement: "*",
});

Batch Processing

import { redactumBatch } from "redactum";

const messages = [
  "Support ticket from [email protected]",
  "Customer callback: +44 20 7946 0958",
  "Payment failed: 4111-1111-1111-1111",
];

const results = await redactumBatch(messages);
const redactedMessages = results.map((result) => result.redactedText);

Error Handling

import { redactumValidateOptions, PolicyCategory } from "redactum";

try {
  redactumValidateOptions({
    policies: ["EMAIL_ADDRESS", "PHONE_NUMBER_UK"],
    customPolicies: [
      {
        name: "EMPLOYEE_ID",
        pattern: /EMP-\d{6}/g,
        category: PolicyCategory.CUSTOM,
      },
    ],
  });
} catch (error) {
  console.error("Invalid configuration:", error.message);
}

API

Core Functions

  • redactum(text, options?) - Main redaction function
  • redactumBatch(texts[], options?) - Batch process multiple texts
  • redactumFromConfig(text, configOptions?) - Load from config file
  • createRedactum(options?) - Create stateful instance

Validation Functions

  • redactumValidateOptions(options) - Validate configuration
  • redactumValidatePolicy(pattern) - Validate custom policy

Utility Functions

  • redactumCalculateEntropy(text) - Shannon entropy (0-8)
  • redactumLooksLikeSecret(text, minLength?, threshold?) - Heuristic secret detection
  • redactumGetAllPatterns() - All built-in policies
  • redactumGetPatterns(options?) - Patterns for config
  • redactumGetEnabledPolicies(options?) - Enabled policy names
  • redactumGetEnabledCategories(options?) - Enabled categories

Contributing

Contributions, issues, and feature requests are welcome. If you would like to get involved, please open an issue or submit a pull request to help improve the project.

License

This project is released under the MIT License. Created and maintained by Alex Whinfield.