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 🙏

© 2024 – Pkg Stats / Ryan Hefner

data-sanitizer

v1.8.1

Published

A simple data sanitizer that preserves the removed values for reference.

Downloads

2

Readme

data-sanitizer

A simple data sanitizer that preserves the removed values for reference.

Usage

const { sanitizeFields } = require('data-sanitizer')

let data = [
  { id: 1, name: 'Jen' },
  { id: 2, name: 'Derek' }
]

const result = sanitizeFields({ data, fieldNames: ['id'] })

console.log(result)

The above code will print

{
  data: [
    { id: '[SANITIZED]', name: 'Jen' },
    { id: '[SANITIZED]', name: 'Derek' }
  ],
  removedValues: { id: [ 1, 2 ] }
}

Sanitizing nested data

The sanitization is recursive, so it will work on nested data structures.

Sanitizing multiple fields

You can sanitize multiple fields:

let data = [
  { 
    id: 1, 
    name: 'Jen', 
    pets: [
      { id: 3, name: 'Frank' }
    ]
  },
  { 
    id: 2, 
    name: 'Derek', 
    pets: [
      { id: 4, name: 'Evey' },
      { id: 5, name: 'Alfie' }
    ]
  }
]

const result = sanitizeFields({ data, fieldNames: ['pets', 'id'] })

Be aware that the sanitization operations will run in field-name order.

Depending on the order of the field names you pass in, you may wind up with sanitized values in your removedValues result.

  • In the above example, the entire value of the fieldName pets would be preserved in sanitizationResult.removedValues, including the original numerical IDs. This is because pets was listed first in fieldNames, so no id fields had been sanitized yet at the time of preservation.
  • If id had been listed first instead, sanitizationResult.removedValues.pets would have sanitized IDs in it, rather than numerical ones, as the id sanitization operation would run first, impacting the entire data structure.

Why does this exist?

I use large data snapshots in Jest to test my database seeding modules. Though changes in the row IDs of seed data are often expected, I still want to monitor them. But when row IDs are left in large data snapshots, the volume of snapshot diff output from ID changes can obscure other unexpected changes.

This simple sanitizer lets me isolate IDs (and any other frequently-changing fields) from the original data structure, preserved in their original order so I can snapshot them in isolation. If something changes, I'll know about it -- with only one line of snapshot diff output instead of eleventy billion.