SOURCE

function hideSensitiveInfo(prefixLength, suffixLength, optionalInfix, info) {
  if (!info) {
    return '';
  }
  // info 长度不足时加安全判断
  const prefix = info.slice(0, prefixLength);
  const suffix = info.length - prefixLength - suffixLength > 0 ?
    info.slice(-suffixLength) : '';
  // 保证 Array 用正整数
  const infixLength = info.length - prefixLength - suffixLength < 2 ?
    2 :
    info.length - prefixLength - suffixLength + 1;
  const infix = optionalInfix === null ?
  // 如没设置 `infix`,则把需要脱敏的部份替换为实际位数个 `*`
    Array(infixLength).join('*') :
    optionalInfix;
  return prefix + infix + suffix;
}

hideSensitiveInfo('崔宇浩'', 1, 1, '*')
console 命令行工具 X clear

                    
>
console