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

@uphold/anonymizer

v5.1.0

Published

Object redaction with whitelist as main feature.

Downloads

2,155

Readme

anonymizer

Object redaction with whitelist and blacklist. Blacklist items have higher priority and will always supercede the whitelist.

Arguments

  1. whitelist (Array): The whitelist array.

  2. blacklist (Array): The blacklist array.

  3. options (Object): An object with optional options.

    options.replacement (Function): A function that allows customizing the replacement value (default implementation is --REDACTED--).

    options.serializers (List[Object]): A list with serializers to apply. Each serializers must contain two properties: path (path for the value to be serialized, must be a string) and serializer (function to be called on the path's value).

    options.trim (Boolean): A flag that enables trimming all redacted values, saving their keys to a __redacted__ list (default value is false).

Example

const { anonymizer } = require('@uphold/anonymizer');
const whitelist = ['foo.key', 'foo.depth.*', 'bar.*', 'toAnonymize.baz', 'toAnonymizeSuperString'];
const blacklist = ['foo.depth.innerBlacklist', 'toAnonymize.*'];
const anonymize = anonymizer({ blacklist, whitelist });

const data = {
  foo: { key: 'public', another: 'bar', depth: { bar: 10, innerBlacklist: 11 } },
  bar: { foo: 1, bar: 2 },
  toAnonymize: { baz: 11, bar: 12 },
  toAnonymizeSuperString: 'foo'
};

anonymize(data);

// {
//   foo: {
//     key: 'public',
//     another: '--REDACTED--',
//     depth: { bar: 10, innerBlacklist: '--REDACTED--' }
//   },
//   bar: { foo: 1, bar: 2 },
//   toAnonymize: { baz: '--REDACTED--', bar: '--REDACTED--' },
//   toAnonymizeSuperString: '--REDACTED--'
// }

Example using serializers

const { anonymizer } = require('@uphold/anonymizer');
const whitelist = ['foo.key', 'foo.depth.*', 'bar.*', 'toAnonymize.baz'];
const blacklist = ['foo.depth.innerBlacklist'];
const serializers = [
  { path: 'foo.key', serializer: () => 'biz' },
  { path: 'toAnonymize', serializer: () => ({ baz: 'baz' }) }
]
const anonymize = anonymizer({ blacklist, whitelist }, { serializers });

const data = {
  foo: { key: 'public', another: 'bar', depth: { bar: 10, innerBlacklist: 11 } },
  bar: { foo: 1, bar: 2 },
  toAnonymize: {}
};

anonymize(data);

// {
//   foo: {
//     key: 'biz',
//     another: '--REDACTED--',
//     depth: { bar: 10, innerBlacklist: '--REDACTED--' }
//   },
//   bar: { foo: 1, bar: 2 },
//   toAnonymize: { baz: 'baz' }
// }

Default serializers

The introduction of serializers also added the possibility of using serializer functions exported by our module. The list of default serializers is presented below:

  • error

Example

const { anonymizer, defaultSerializers } = require('@uphold/anonymizer');
const serializers = [
  { path: 'foo', serializer: defaultSerializers.error }
];

const anonymize = anonymizer({}, { serializers });

const data = { foo: new Error('Foobar') };

anonymize(data);

// {
//   foo: {
//     name: '--REDACTED--',
//     message: '--REDACTED--',
//     stack: '--REDACTED--'
//   }
// }

Release process

The release of a version is automated via the release GitHub workflow. Run it by clicking the "Run workflow" button.

License

MIT