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

redact-record

v1.0.0

Published

Redact or modify values of an object

Readme

Redact Record

CI Status codecov npm version

A library to (partially) redact values with typesafety and zero dependencies. Allows redaction in nested objects.

Install

Sample:

import { redact } from 'redact-record'

const originalLog = {
  name: "Alice",
  action: "add ToDo"
}

// Redact `name` of the object. `name` will
// be redacted by only printing the first and last character
// other attributes will stay the same
const auditLog = redact(originalLog, {
  name: (name) => {
    if(name.length > 3) {
      const firstChar = name.charAt(0)
      const lastChar = name.charAt(name.length - 1)
      const redacted = "·".repeat(name.length - 2)
      return `${firstChar}${redacted}${lastChar}`·
    }
    else {
      return "·".repeat(name.length)
    }
  }
})

console.log(auditLog)

Will now return

{
  "action": "add ToDo",
  "name": "A···e",
}

It tries to be as simple as possible. The redact function takes the original object or value and a sanitizer object.

The sanitizer works as following:

// Assume the objects you want to redact are of type Log
type Log = {
    action: string;
    name: string;
    tags: string[];
}

// The sanitizer object type can be created as follows
type S = Sanitizer<Log>
// S will resolve to the type
//
// S = {
//     action?: (originalValue: string) => string;
//     name?: (originalValue: string) => string;
//     tags?: (originalTag: string) => string;
// } | (originalObject: Log) => Log
//
// To redact the complet object, or only individual fields

Installation

Usage

In order to redact an object, you need a sanitizer. This is either a function retrieving the original value and returning a redacted version of it, or an object to only redact individual attributes of the original object.

Single value examples

Change a string to [REDACTED]

redact("Hello World", () => '[REDACTED]'
// Result: "[REDACTED]"

Only print the first letter of the string, redact the rest

redact("Hello World", (original) => `${original.substring(0, 1)}...`)
// Result: "H..."

Array example

If the input is an array, the sanitizer function is called for each item.

redact(["Alice", "Bob"], (original) => `${original.substring(0, 1)}...`)
// Result: ["A...", "B..."]

Object example

If you want to redact an object, you can provide a sanitizer which follows the same attributes. Let's take the following example:

const input = {
    user: {
        name: 'Alice',
        age: 22,
    }
    action: "add Todo"
}

if you want redact the complete user information, but keep the action, you can do this

sanitizeValue(input, { user: (originalUser) => "REDACTED" })

If you only want to sanitize the name of the user, you could do this:

sanitizeValue(input, { user: { name: (originalName) => "REDACTED" } })