@darkobits/mask-string
v2.0.1
Published
Mask tokens in a string.
Downloads
3,354
Maintainers
Readme
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', '#') // => '###'