1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| const pwdFields = ['password','pwd'];
function filterPwdField(obj) { return lodash.mapValues(obj, (value, key) => { if (lodash.isPlainObject(value)) return filterPwdField(value);
if (typeof value === 'string') { if (pwdFields.some(field => value.toLowerCase().includes(field.toLowerCase()))) { pwdFields.forEach(field => value = value.replace(new RegExp(`(${field})=(.+?)(&|$)`, 'gi'), (match, $1, $2, $3) => `${$1}=${$2.slice(0, -5) + '*****'}${$3 || ''}` )); }
if (pwdFields.some(field => key.toLowerCase().includes(field.toLowerCase()))) value = value.slice(0, -5) + '*****'; } return value; }); }
|