安装
npm i @darkobits/mask-string
使用
此包的默认导出是以下签名的函数:
mask(pattern: string | RegExp | Array<string | RegExp>, str: string, maskChar = '*'): string
示例
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
此套件额外导出一个函数 maskAll 其签名如下:
maskAll(str: string, maskChar = '*'): string
此函数接受一个字符串并返回一个完全由所提供的口罩字符组成的相同长度的字符串.
示例
import { maskAll } from '@darkobits/mask-string';
maskAll('foo') // => '***'
maskAll('bar', '#') // => '###'