1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
const encryption = (str = "", start = 3, end = 2, maskChar = "*") => { if (!str) return str; let toStr = str.toString(); toStr = toStr.replace(/\s*/g, ""); start = Math.max(start, 0); end = toStr.length - Math.min(end, toStr.length); const maskedPart = maskChar.repeat(end - start); return toStr.substring(0, start) + maskedPart + toStr.substring(end); };
const space4 = value => { if (!value) return ""; let target = value.replace(/\s*/g, "").replace(/(.{4})(?=.)/g, "$1 "); return target; };
const space_idCard = value => { if (!value) return value; let target = value.replace(/\s*/g, "").replace(/(.{6})(.{4})(.{4})/, "$1 $2 $3 "); return target; };
const encry_idCard = value => { if (!value) return value; let target = encryption(value, 6, 4); return target; };
const spaceEncry_idCard = value => { if (!value) return value; let target = value.replace(/\s*/g, "").replace(/^([a-zA-Z0-9]{6})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/, "$1 **** **** $2"); return target; };
const space_phone = value => { if (!value) return value; let target = value.replace(/\s*/g, "").replace(/(.{3})(.{4})/, "$1 $2 "); return target; };
const encry_phone = value => { if (!value) return value; let target = encryption(value, 3, 4); return target; };
const spaceEncry_phone = value => { if (!value) return value; let target = value.replace(/\s*/g, "").replace(/^(\d{3})\d+(\d{4})$/, "$1 **** $2"); return target; };
const space_bankCard = value => { if (!value) return ""; let target = value.replace(/\s*/g, "").replace(/(\d{4})(?=\d)/g, "$1 "); return target; };
const encry_bankCard = value => { if (!value) return ""; let target = encryption(value, 4, 4); return target; };
const spaceEncry_bankCard = value => { if (!value) return ""; let target = value.replace(/\s*/g, "").replace(/^(\d{4})\d+(\d{4})$/, "$1 **** **** $2"); return target; };
const encry_endNameA = value => { let target = encryption(value, 1, value.length > 2 ? 1 : 0); return target; };
const encry_endNameB = value => { let target = encryption(value, 1, 0); return target; };
const encry_startName = value => { if (!value) return ""; let target = value.replace(/.(?=.)/g, "*"); return target; };
const encry = { encryption, space4, space_idCard, encry_idCard, spaceEncry_idCard, space_phone, encry_phone, spaceEncry_phone, space_bankCard, encry_bankCard, spaceEncry_bankCard, encry_endNameA, encry_endNameB, encry_startName }; export default encry;
|