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

maskify-sense

v1.0.0

Published

Mask sensitive data for loggers

Downloads

12

Readme

maskify-sense

Mask sensitive data for loggers

Created this tiny library as a way to log data objects in loggers even if they contained JSON stringify values

Install

yarn add maskify-sense
npm install maskify-sense

Usage

To use it we need to create a mask instance using the creator with a configuration object

// import MaskifySense from 'maskify-sense';
const MaskifySense = require('maskify-sense');

const mask = MaskifySense({
  ssn: {
    mask: (str) => `+++_++_${str.slice(-4)}`,
    fields: ['ssn', 'taxId', 'sin'],
  },
  accounts: {
    fields: ['account', 'routing'],
  },
  password: {
    mask: '[redacted]',
    fields: ['password'],
  },
});

The configuration object is an object with categories of masking... each category will have a mask field which can be a String or a Function and a fields field which will be an array of targeted fields to mask (transform).

The category names (keys of the configuration object) are only to have an organization of the different mask strategies for all your fields. They are not used in any other place so you can name them whatever you want.

If the mask field is empty a default mask function will take place (can be override later on).

(str) => `*****${str.slice(-4)}`;

If the mask is a String it will override completely the value of the field in the data object with that mask string value.

const MaskifySense = require('maskify-sense');
const mask = MaskifySense({
  simple: {
    mask: '[redacted]',
    fields: ['password'],
  },
});

console.log(mask({ password: 'mySecretPassword' }));
// logs => { password: '[redacted]' }

If the mask is a Function it will transform the value accordingly with the masked function.

const MaskifySense = require('maskify-sense');
const mask = MaskifySense({
  simple: {
    mask: (v) => `*****${str.slice(-4)}`,
    fields: ['password'],
  },
});

console.log(mask({ password: 'mySecretPassword' }));
// logs => { password: '*****word' }

The masked function accepts only one argument which would be the value that is being evaluated.

The mask can evaluate also stringified json strings

const MaskifySense = require('maskify-sense');
const mask = MaskifySense({
  passwords: {
    mask: '***',
    fields: ['password', 'secret'],
  },
  accounts: {
    mask: (v) => `*****${str.slice(-4)}`,
    fields: ['routing', 'bankAccount'],
  },
});

console.log(
  mask({
    name: 'John Doe',
    bankData: '{"bankAccount":12345678,"routing":9876543}',
    credentials: '{"username":"UA","password":"12345","secret":"ABC"}',
  }),
);
// logs =>
// {
//   name: 'John Doe',
//   bankData: '{"bankAccount":"*****5678","routing":"*****6543"}',
//   credentials: '{"username":"UA","password":"***","secret":"***"}',
// }

You can check also the test/script.js file for more examples.