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

mask-sensitive-data

v0.11.5

Published

Mask sensitive data, eg. credit card numbers, phone numbers, emails, UUIDs, JWT tokens.

Downloads

1,096

Readme

mask-sensitive-data

Mask sensitive data eg. write debugging data to log files, etc. Supports the below-mentioned items:

  • credit card numbers
  • emails
  • JWT tokens
  • phone numbers
  • UUIDs

Install

npm install mask-sensitive-data

Usage

import maskSensitiveData, { maskString } from 'mask-sensitive-data'

const objectToBeMasked = {
  email: '[email protected]',
  creditCard: '1234 5678 9000 9876',
  id: '3f8a43fd-6489-4ec7-bd55-7a1ba172d77b',
  name: 'John',
  surname: 'Doe',
  phone: '+358 40 1234567',
  token: 'eyJhbGciOiJIUzI1NiJ9.ew0KICAic3ViIjogIjEyMzQ1Njc4OTAiLA0KICAibmFtZSI6ICJBbGV4IEtvemxvdiIsDQogICJpYXQiOiAxNTE2MjM5MDIyDQp9.PNKysYFTCenU5bekHCmwIxCUXoYG41H_xc3uN3ZF_b8',
  subuser: {
    email: '[email protected]',
    creditCard: '0987 6543 2100 1234',
    id: '7c942511-969b-4363-af11-9667bf756733',
    name: 'John',
    surname: 'Smith',
    phone: '+358 (0)40 1234567',
    token: 'eyJraWQiOiJlOTRmODk4Mi02YWI1LTQxZjQtODlkYS03MTYxYmFjZDUzM2UiLCJhbGciOiJFUzI1NiJ9.ew0KICAic3ViIjogIjEyMzQ1Njc4OTAiLA0KICAibmFtZSI6ICJBbGV4IEtvemxvdiIsDQogICJpYXQiOiAxNTE2MjM5MDIyDQp9.CtiBkSYbhs5hEvMA7w4_Dbs3S5IHnxJgRo-fI8UhunY9BCUxBcb9vTRB4uRKLbhCL8MRYR90rzdzE7EcllyyDw',
    subuser: {
      email: '[email protected]',
      creditCard: '1234-0987-6543-0000',
      id: '12882e75-a726-4615-8631-6ee428e07592',
      name: 'Don',
      surname: 'Johnson',
      phone: '040-1234567',
      token: 'eyJraWQiOiIxNDQzZWU0NS01ZGY4LTRlZmYtYmU2Yi1jYjRmMWI3MDA5YjMiLCJhbGciOiJFUzUxMiJ9.ew0KICAic3ViIjogIjEyMzQ1Njc4OTAiLA0KICAibmFtZSI6ICJBbGV4IEtvemxvdiIsDQogICJpYXQiOiAxNTE2MjM5MDIyDQp9.AB0kMsJ1wGlLG-Z89O-a1eZH0RJf3VYO7uoW3otcqV-xF6THYK3v14yppzv10sQ-HZWyUek6MW8-UzB-uq5Pm917ANZUXIw0XVY794W-u1JYrl36rKRi_DqSEEQ9X-hz9BhVFQEaGyNGZSDdKiVdix6MEMgN_4Nt5O-GXwGk6SLFdpBI',
    },
  },
}

// Mask object properties with default options
maskSensitiveData(objectToBeMasked)
// -> {
//      creditCard: '1234 5#########9876',
//      email: 'john.d#############.com',
//      id: '3f8a43##########################d77b',
//      name: 'John',
//      surname: 'Doe',
//      phone: '+358 4#####4567',
//      token: 'eyJhbG###################################F_b8',
//      subuser: {
//        creditCard: '0987 6#########1234',
//        email: 'john.s###############.com',
//        id: '7c9425##########################6733',
//        name: 'John',
//        surname: 'Smith',
//        phone: '+358 (########4567',
//        token: "eyJraW###################################yyDw",
//        subuser: {
//          creditCard: '1234-0#########0000',
//          email: 'don.jo################.com',
//          id: '12882e##########################7592',
//          name: 'Don',
//          surname: 'Johnson',
//          phone: '040-12#4567',
//          token: 'eyJraW###################################dpBI',
//        },
//      },
//    }

// Mask uuid string with default options
maskSensitiveData(objectToBeMasked.id)
// -> 3f8a43##########################d77b

// Mask credit card number string with custom options
maskSensitiveData(
  objectToBeMasked.creditCard,
  {
    ...defaultMaskOptions,
    visibleCharsFromStart: 0,
  }
)
// -> ###############9876

// Mask array of UUIDs with default options
maskSensitiveData([
  '439a02e5-390e-49f3-a0a3-80d8def9ace4',
  '43982692-386c-42dc-8837-93f479503c56'
])
// -> [
//      '439a02##########################ace4',
//      '439826##########################3c56'
//    ]

// Mask object properties with custom options (skip UUID strings from masking)
maskSensitiveData(
  objectToBeMasked,
  {
    ...defaultMaskOptions,
    uuidPattern: undefined,
  }
)
// -> {
//      creditCard: '1234 5#########9876',
//      email: 'john.d#############.com',
//      id: '3f8a43fd-6489-4ec7-bd55-7a1ba172d77b',
//      name: 'John',
//      surname: 'Smith',
//      phone: '+358 4#####4567',
//      token: 'eyJhbG###################################F_b8',
//      subuser: {
//        creditCard: '0987 6#########1234',
//        email: 'john.s###############.com',
//        id: '7c942511-969b-4363-af11-9667bf756733',
//        name: 'John',
//        surname: 'Doe',
//        phone: '+358 (########4567',
//        token: "eyJraW###################################yyDw",
//        subuser: {
//          creditCard: '1234-0#########0000',
//          email: 'don.jo################.com',
//          id: '12882e75-a726-46#####31-6ee428e07592',
//          name: 'Don',
//          surname: 'Johnson',
//          phone: '040-12#4567',
//          token: 'eyJraW###################################dpBI',
//        },
//      },
//    }

// Mask plain string
maskString('[email protected]')
// -> john.d##########.com

// Mask plain string with custom configuration
maskString(
  '[email protected]',
  {
    maskSymbol: '#',
    maxCharsToMask: '[email protected]'.length,
    visibleCharsFromStart: 0,
    visibleCharsFromEnd: 0,
  }
)
// -> ####################

API

  • Usage

    maskSensitiveData(objectToBeMasked, options)
  • objectToBeMasked

    Object, Array of strings, or just string to be masked

  • options

    bankCardNumberPattern: RegExp|undefined - RegExp pattern to recognize bank card numbers

    emailPattern: RegExp|undefined - RegExp pattern to recognize email addresses

    jwtPattern: RegExp|undefined - RegExp pattern to recognize JWT tokens

    phoneNumberPattern: RegExp|undefined - RegExp pattern to recognize phone numbers

    uuidPattern: RegExp|undefined - RegExp pattern to recognize UUID identificators

    maskSymbol: string - Symbol to replace masked chars

    maxCharsToMask: string - Maximal length on masking chars

    visibleCharsFromEnd: number - Amount of chars visible from the end of the string

    visibleCharsFromStart: number - Amount of chars visible from the beginning of the string

  • Default options

    {
      bankCardNumberPattern: /([\d]{4}\W){3}[\d]{4}/g,
      emailPattern: /[\w+\.+\-]+@+[\w+\.+\-]+[\.\w]{2,}/g,
      jwtPattern: /[\w-]#\.[\w-]#\.[\w-]#/g,
      phoneNumberPattern: /[\+]?[\d]{1,3}?[-\s\.]?[(]?[\d]{1,3}[)]?[-\s\.]?([\d-\s\.]){7,12}/g,
      uuidPattern: /[\w]{8}\b-[\w]{4}\b-[\w]{4}\b-[\w]{4}\b-[\w]{12}/g,
      maskSymbol: '#',
      maxCharsToMask: 35,
      visibleCharsFromEnd: 4,
      visibleCharsFromStart: 6,
    }