const getStr = (str, startIndex, endIndex, code) => {
let sliceStr = str.slice(startIndex, endIndex)
let replaceStr = ''
let len = sliceStr.length
let i = -1
while(++i < len) {
replaceStr += code
}
return str.replace(sliceStr, replaceStr)
}
// 手机号
const getPhone = phone => getStr(phone, 3, 7, '*');
// 身份证号
const getIdCard = idCard => getStr(idCard, 6, 14, '*');
// 姓名
const getName = name => {
let startIndex = Math.floor(name.length / 2);
return getStr(name, startIndex, name.length, '*')
}
网友评论