Skip to content

快速开始

在线尝试

可以直接在 StackBlitz 上进行在线尝试。

安装

MaskIO 安装到项目中使用,以下方式安装它:

sh
$ npm add -D maskio
sh
$ pnpm add -D maskio
sh
$ yarn add -D maskio

使用

ts
import { maskText, maskObject } from 'maskio';

/** 字符串掩码 */
const text = maskText('1234567890123456', 'bankCard') // '************3456'


const sourceObject = {
  firstCode: '123456',
  otherCode: {
    resultCode: '123',
    name: '小明',
  },
};
const config = { '^.*Code$': 'all', '^otherCode\.name$': 'userName' }
/** 对象掩码 */
const object = maskObject(sourceObject, config) // '{"firstCode":"******","otherCode":{"resultCode":"***","name":"*明"}}'

TIP

需要对正则表达式有熟练的理解。