import { regex } from 'funtool';
// 基础替换
const masked = regex.replacer('信用卡: 1234-5678-9012-3456')
.use(/\d{4}-\d{4}-\d{4}-\d{4}/)
.with('****-****-****-****')
.result();
// masked => '信用卡: ****-****-****-****'
// 使用注册规则
const formatted = regex.replacer('20230523')
.use('dateRule')
.with((match) => `${match.slice(0,4)}/${match.slice(4,6)}/${match.slice(6)}`)
.result();
// formatted => '2023/05/23'
// 链式替换
const clean = regex.replacer('移除 多余 空格')
.use(/\s+/g)
.with(' ')
.result();
// clean => '移除 多余 空格'