/**
* 脱敏处理,加*号,只展示前preLen位和后subLen位
*/
function desensitize = (str = "", preLen, subLen = 0) => {
if (!str) {
return str || "";
}
str = str.toString();
const len = str.length;
const subIndex = len - subLen > preLen ? len - subLen : preLen;
return (
str.substr(0, preLen) +
Array(subIndex - preLen > 0 ? subIndex - preLen : 0)
.fill()
.map(() => "*")
.join("") +
str.substr(subIndex)
);
}
JS脱敏处理-只展示前x和后x位
最新推荐文章于 2024-07-24 10:37:01 发布