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

hush

v0.2.3

Published

Redacts text according to the regexes you supply. Fires your callback when done.

Downloads

31

Readme

hush

This node module redacts text according to the regexes you supply and fires your callback when done.

Install

$ npm install hush

Usage

var hush = require('hush')

Now hush expects three arguments:

  1. A source file
  2. An options object
  3. And a callback: cb(err, data)
hush(source, options, callback)

The source file and callback are pretty self-explanatory (anyway, see below), so about that options object...

options.targets is required. That is the regular expression or array of regular expressions to be redacted. As the second argument to hush, you will definitely want something that looks like this:

{ targets: regexOrArrayOfRegexes }

options.replacement is optional. If given, it should be in the form of a string.

If you provide it as a single character, that character will be repeated for the length of the match that is replaced. This is actually the default behavior: if you do not provide options.replacement, it defaults to an asterisk. Thus, if the match is a four letter word, the match will be replaced by four asterisks.

However, if you provide a string of greater than one character, that string will be used as is.

For example, you could replace each instance of a match with [ REDACTED ] through use of the following options object:

{ targets : someRegEx
, replacement : '[ REDACTED ]'
}

Examples

Given a file, 'example.txt', that looks like this:

This is a US social security number sort of thing: 123-44-5555

This is a US phone number sort of thing: 555-555-5555

Here is another US social security number sort of thing: 987-65-4321

And another US phone number sort of thing: 123-456-7890

Here are some 123-456-7890 interspersed 123-456-7890 with random 987-65-4321 text 123-456-7890 just
to see 987-65-4321 how 123-456-7890 that 987-65-4321
sort of thing goes 987-65-4321...

You could do something like this:

const
  hush = require('hush')
, fs = require('fs')

, SS_Regex = /\d{3}-?\d{2}-?\d{4}/g
, PH_Regex = /\d{3}-?\d{3}-?\d{4}/g


hush(
  'example.txt'
, { targets: [SS_Regex, PH_Regex] // can be an array of regexes or a single regex
  , replacement: 'NOPE'           
  }
, function(err, data) {
    if (err) return console.error(err)

    fs.writeFile('redacted.txt', data, function(err) {
      if (err) return console.error(err)
      console.log('Check yer directory...')
    })
  }
)

in which case you would end up with this:

This is a US social security number sort of thing: NOPE

This is a US phone number sort of thing: NOPE

Here is another US social security number sort of thing: NOPE

And another US phone number sort of thing: NOPE

Here are some NOPE interspersed NOPE with random NOPE text NOPE just
to see NOPE how NOPE that NOPE
sort of thing goes NOPE...

Or, if you were to do this:

hush(
  'example.txt'
, { targets: [SS_Regex, PH_Regex] 
  , replacement: '@'  // If omitted, replacement defaults to an asterisk      
  }
, function(err, data) {
    if (err) return console.error(err)

    fs.writeFile('redacted.txt', data, function(err) {
      if (err) return console.error(err)
      console.log('Check yer directory...')
    })
  }
)

then you'd end up with this:

This is a US social security number sort of thing: @@@@@@@@@@@

This is a US phone number sort of thing: @@@@@@@@@@@@

Here is another US social security number sort of thing: @@@@@@@@@@@

And another US phone number sort of thing: @@@@@@@@@@@@

Here are some @@@@@@@@@@@@ interspersed @@@@@@@@@@@@ with random @@@@@@@@@@@ text @@@@@@@@@@@@ just
to see @@@@@@@@@@@ how @@@@@@@@@@@@ that @@@@@@@@@@@
sort of thing goes @@@@@@@@@@@...

Attention

  1. The effectiveness of this module hinges upon the accuracy of any regular expressions you provide.
  2. Be sure to thoroughly inspect program output to avoid potentially exposing any private data.

ISC License (ISC)

Copyright 2014, Instancetype

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.