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

log-masker

v1.0.11

Published

A library to mask data

Downloads

21

Readme

Log Masker Library

This library intelligently checks for all occurrences of the specified fields to be masked within a nested object and caches the path for later use. Customize the code to fit your project's specific requirements.

npm i log-masker

Example Usage

Import the Library

const {
  logMaskerMaskData,
  logMaskerSetMaskConfig,
  logMaskerSetMaskingFields,
  logMaskerMaskDataSetDebugMode,
  logMaskerSetCacheUpdateEndTime
} = require('log-masker');

Set Debug Mode

// Enable debug mode to show required logs and errors
logMaskerMaskDataSetDebugMode(true);

Set Cache Update Time

// Set the time for when to stop updating cache (in milliseconds)
// Adjust according to your requirements based on how long your code will be ready with cached data
// fine tune this time to work best for your usecase
logMaskerSetCacheUpdateEndTime(60000);

Set Masking Configuration

// Set the masking configuration
// Customize the masking configuration according to your specific needs
// The following configuration is just an example
// DOCS: https://www.npmjs.com/package/maskdata
// please ensure that the config is valid, else it will not work as expected
const maskingConfig = {
    cardMaskOptions: {
        maskWith: "*",
        unmaskedStartDigits: 4,
        unmaskedEndDigits: 1
    },

    emailMaskOptions: {
        maskWith: "*",
        unmaskedStartCharactersBeforeAt: 3,
        unmaskedEndCharactersAfterAt: 2,
        maskAtTheRate: false
    },

    passwordMaskOptions: {
        maskWith: "*",
        maxMaskedCharacters: 16,
        unmaskedStartCharacters: 0,
        unmaskedEndCharacters: 0
    },

    phoneMaskOptions: {
        maskWith: "*",
        unmaskedStartDigits: 4,
        unmaskedEndDigits: 1
    },

    stringMaskOptions: {
        maskWith: "*",
        maskOnlyFirstOccurance: false,
        maskAll: true,
        maskSpace: false
    },

    uuidMaskOptions: {
        maskWith: "*",
        unmaskedStartCharacters: 0,
        unmaskedEndCharacters: 0
    },

    jwtMaskOptions: {
        maskWith: '*',
        maxMaskedCharacters: 512,
        maskDot: true,
        maskHeader: true,
        maskPayload: true,
        maskSignature: true
    },
    // To extend the mask function to other types of data. 
    genericStrings: [
        {
            config: {
                maskWith: "*",
                maxMaskedCharacters: 256,
                unmaskedStartDigits: 0,
                unmaskedEndDigits: 0
            },
        }
    ]
}
logMaskerSetMaskConfig(maskingConfig);

Set Masking Fields

// Define the fields to be masked based on sensitivity
const mapFieldsToFindToGenericMaskingFields = {
  stringFields: ['name', 'customer_name', 'address'],
  phoneFields: ['phone', 'mobile'],
  emailFields: ['email'],
  passwordFields: ['password'],
  cardFields: ['card'],
  uuidFields: ['uuid'],
};

// Set the masking fields
logMaskerSetMaskingFields(mapFieldsToFindToGenericMaskingFields);

Mask Data

/**
 * Mask the data
 * 
 * @param {Object} data - The data object to be masked
 * @param {string} cacheKey - The cache key for the data object
 * @param {boolean} cacheKeyInData - Whether the cache key is in the data object or not
 * @returns {Object} - The masked data object
 */
// Mask the data (no error thrown if the data is not a valid JSON)

const data = {
    inner: {
        name: "Arpit",
        fields: {
            email: "[email protected]",
            customer: [{name: "pandey"}, {address: "address"}]
        }
    },
    phone: "1234567890"
}

const cacheKey = 'data'; // used for caching same object masking paths
// cacheKeyInData? not required, pass true if your data object contains the cacheKey, for example api_path
const maskedData = logMaskerMaskData({data}, cacheKey, cacheKeyInData?);

output:
{
  "data": {
    "inner": {
      "name": "*****",
      "fields": {
        "email": "arr**@*******om",
        "customer": [
          {
            "name": "******"
          },
          {
            "address": "*******"
          }
        ]
      }
    },
    "phone": "1234*****0"
  }
}

Feel free to customize the code according to your specific needs and integrate it seamlessly into your project.