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 🙏

© 2026 – Pkg Stats / Ryan Hefner

string-masking

v1.2.1

Published

Mask strings while optionally preserving formatting characters

Readme

string-masking

This package masks strings in two ways:

  1. Legacy digit mode for the original package behavior.
  2. Options-based mode for cleaner masking with support for formatted strings.

What This Repository Does

The repository exports a single function from index.js:

const stringMask = require("string-masking");

It returns a model in this shape:

{
  status: "success" | "failure",
  response: "masked output or error message"
}

Failures also include a NOTE field.

Legacy API

Keep the last N characters visible

const stringMask = require("string-masking");

const output = stringMask("1234567890", 3);
console.log(output);

// { status: 'success', response: 'XXXXXXX890' }

Keep the first N characters visible

const stringMask = require("string-masking");

const output = stringMask("1234567890", -3);
console.log(output);

// { status: 'success', response: '123XXXXXXX' }

Mask the middle portion

const stringMask = require("string-masking");

const output = stringMask("1234567890", 0);
console.log(output);

// { status: 'success', response: '12XXXXXX90' }

Improved API

Use an options object when you want more control.

Keep a custom number of characters at the start and end

const stringMask = require("string-masking");

const output = stringMask("ABCD1234EFGH", {
  visibleStart: 2,
  visibleEnd: 2
});

console.log(output);

// { status: 'success', response: 'ABXXXXXXXXGH' }

Preserve separators such as spaces, dashes, and symbols

const stringMask = require("string-masking");

const output = stringMask("4111-1111-1111-1111", {
  visibleEnd: 4,
  preserveFormat: true
});

console.log(output);

// { status: 'success', response: 'XXXX-XXXX-XXXX-1111' }

Mask alternate characters

const stringMask = require("string-masking");

const output = stringMask("ABCDEFGH", {
  alternateMask: true
});

console.log(output);

// { status: 'success', response: 'XBXDXFXH' }

Use the legacy digit argument with formatting support

const stringMask = require("string-masking");

const output = stringMask("ABHA-9988-XY12", 4, {
  preserveFormat: true,
  maskChar: "*"
});

console.log(output);

// { status: 'success', response: '****-****-XY12' }

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | visibleStart | integer | 0 | Number of maskable characters to keep visible at the start | | visibleEnd | integer | 0 | Number of maskable characters to keep visible at the end | | preserveFormat | boolean | false | Preserves non-alphanumeric separators while masking | | maskChar | string | "X" | Single character used for masking | | alternateMask | boolean | false | Masks every other eligible character inside the maskable region |

When preserveFormat is true, letters and numbers are masked, while characters such as spaces, -, ., @, and + stay in place.

When alternateMask is true, alternating starts from the first character that would otherwise be masked after visibleStart and visibleEnd are applied.

Suggestions For Further Improvement

  1. Add TypeScript definitions so the options API is easier to consume in editors.
  2. Publish a major version when you want to formalize the new options-based API.
  3. Add a maskPattern option later if you want different masking rules for emails, phones, or IDs.
  4. Add CI to run npm test automatically before publishing.

Contribution

Rohan Solse
Suggestions and recommendations are welcome.
Contact: [email protected]