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-info

v1.1.2

Published

The package clean out of string chains all sensitive data. It also allows you to pass new regex expressions.

Downloads

34

Readme

Mask Sensitive Info

This package provides a utility to mask sensitive information in text, such as email domains, based on predefined regular expression patterns. It can be used to replace specific email provider domains with a masked string like xxxx.

Table of Contents

Installation

To install the package, use npm:

npm install mask-sensitive-info

Or with Yarn:

yarn add mask-sensitive-info

Usage

Basic Usage

First, require the package in your project:

const maskSensitiveInfo = require('mask-sensitive-info');

Then, you can use the maskSensitiveInfo function to mask specific email domains in a text:

const sampleText = "Contact us at [email protected] or [email protected].";
const masker = maskSensitiveInfo(); 
const result = masker.filter(sampleText);
console.log(result);  // Output: "Contact us at john.doe xxxx or jane.doe xxxx."

Parameters

  • replaceText: The text that will replace the matched patterns. Defaults to 'xxxx'. Default: xxxx
  • patternNames: An array of pattern names to specify which email domains should be masked. The names correspond to the keys in the patterns.json configuration file. Defaults to all patterns in patterns.json. Default: all filters will be applied.
  • customExpressions: An array of custom regular expressions (as strings) that you want to apply in addition to the predefined patterns. Default: empty.

Example

To mask all occurrences of gmail.com and yahoo.com in a string:

const text = "Send an email to [email protected] or [email protected] for details.";
const masker = maskSensitiveInfo({ patternNames: ['gmail', 'yahoo'] });
const maskedText = masker.filter(text);
console.log(maskedText);  // "Send an email to user xxxx or anotheruser xxxx for details."

To include a custom regular expression:

const text = "Send an email to [email protected] or [email protected] for details.";
const customExpression = "\bexample\.com\b";
const masker = maskSensitiveInfo({ patternNames: ['gmail'], customExpressions: [customExpression] });
const maskedText = masker.filter(text);
console.log(maskedText);  // "Send an email to user xxxx or anotheruser xxxx for details."

Then, use it in your code:

const customExpression = "\bexample\.com\b";
const masker = maskSensitiveInfo({ patternNames: ['example'], customExpressions: [customExpression] });
const maskedText = masker.filter(text);

Examples

Masking Multiple Providers

const text = "Contact us at [email protected], [email protected], or [email protected].";
const masker = maskSensitiveInfo({ patternNames: ['gmail', 'yahoo', 'outlook'] });
const maskedText = masker.filter(text);
console.log(maskedText);  // "Contact us at john.doe xxxx, jane.doe xxxx, or user xxxx."

Masking a Single Provider

const text = "For support, contact [email protected].";
const masker = maskSensitiveInfo({ patternNames: ['icloud'] });
const maskedText = masker.filter(text);
console.log(maskedText);  // "For support, contact help xxxx."

Testing

This package includes a set of automated tests using Jest. To run the tests, use the following command:

npm test

The tests will verify that the masking function works correctly for various email domains.

Example Test

describe('maskSensitiveInfo for gmail.com', () => {
    const sampleText = "Contact us at [email protected] or [email protected].";

    test('masks Gmail domain', () => {
        const masker = maskSensitiveInfo({ patternNames: ['gmail'] });
        const result = masker.filter(sampleText);
        expect(result).toBe("Contact us at john.doe xxxx or jane.doe xxxx.");
    });
});

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue with any improvements or suggestions.

Steps to Contribute

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature-branch).
  5. Open a pull request.