@darkobits/mask-string
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Install

npm i @darkobits/mask-string

Use

This package's default export is a function with the following signature:

mask(pattern: string | RegExp | Array<string | RegExp>, str: string, maskChar = '*'): string

Example:

import mask from '@darkobits/mask-string';

const str = 'Colorless green ideas sleep furiously.';
const masked = mask('green', str);
// => 'Colorless ***** ideas sleep furiously.'
import mask from '@darkobits/mask-string';

const str = 'Twas bryllyg, and ye slythy toves did gyre and gymble in ye wabe.';
const masked = mask([/and/g, /gy/g], str, '#');
// => 'Twas bryllyg, ### ye slythy toves did ##re ### ##mble in ye wabe.'

maskAll

This package additionally exports a function maskAll which has the following signature:

maskAll(str: string, maskChar = '*'): string

This function accepts a string and returns a string of the same length consisting entirely of the provided mask character.

Example:

import { maskAll } from '@darkobits/mask-string';

maskAll('foo') // => '***'
maskAll('bar', '#') // => '###'

Package Sidebar

Install

npm i @darkobits/mask-string

Weekly Downloads

779

Version

2.0.1

License

WTFPL

Unpacked Size

11.1 kB

Total Files

12

Last publish

Collaborators

  • darkobits