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

json-redactor

v0.6.0

Published

removes key value pairs from json objects, or redacts strings, if they contain regex keywords

Downloads

4

Readme

JSON Redactor

Travis Build Coverage Status JavaScript Style Guide json-redactor

Recursively clean a list of arguments before sending them out somewhere.

This is a standard npm module, so you'll install it via

npm install --save json-redactor

require it like:

var jsonRedactor = require('json-redactor')({
  watchKeys: // array of regex values, default is an empty array
  error: // string, default is '-'
})

watchKeys is the list of things to watch for, only accepts regex

error is the error message to replace strings that match the watchKeys with.

test it by:

npm test

use it like:

as a go-between, example using bole

var bole = require('bole');
var jsonRedactor = require('./logFilter.js')({
    watchKeys : [ /firstName/gi , /lastName/gi , /phone/gi , /^_.*/ ],
    error: 'Dont Log sensitive data'
  });

var b = bole(name)
var pre = {
  error : function(){
    b.error.apply(null,_.values(jsonRedactor.apply(null,arguments)))
  },
  info :function(){
    b.info.apply(null,_.values(jsonRedactor.apply(null,arguments)))
  },
  warn : function(){
    b.warn.apply(null,_.values(jsonRedactor.apply(null,arguments)))
  },
  debug : function(){
    b.debug.apply(null,_.values(jsonRedactor.apply(null,arguments)))
  }
}

return pre

standard usage

jsonRedactor()

Some examples

var jsonRedactor = require('json-redactor')({
    watchKeys:[/error/gi]
  })
console.log(jsonRedactor('this is an error'))
// logs {'0':'-'}

The outer object is because we copy and return the arguments object, this way we can parse through an arbitrary amount of args. The inner string got redacted because our regex matches error in the clean function, and the argument was a string

var jsonRedactor = require('json-redactor')({
    watchKeys:[/string/gi],
    error: 'redacted!'
  })
console.log(jsonRedactor({string:'test',test2:'string'}))
// logs {'0':{test2:'redacted!'}}

In the inner object, key string matches the regex so it gets stripped out. The value of key test2 gets replaced with redacted! because that is what our error message is set to (and the value matches the regex)