Skip to content

Instantly share code, notes, and snippets.

@azkadev
Created September 22, 2021 09:29
Show Gist options
  • Save azkadev/711ec1ae40b406a17f616af70739662c to your computer and use it in GitHub Desktop.
Save azkadev/711ec1ae40b406a17f616af70739662c to your computer and use it in GitHub Desktop.
hide data phone number / credit card / passsword / email node javascript
function hidedata(message, start = 4, end = 2) {
var array = [...String(message)];
var message = "";
var num_start = start;
var num_end = array.length - end;
for (var i = 0; i < array.length; i++) {
var loop_data = array[i];
if (i == num_end) {
num_end--;
message += loop_data
} else if (i == num_start) {
num_start++;
message += "*";
} else {
message += loop_data
}
}
return message;
}
console.log(hidedata(62788628121212)) // log 6278********12
console.log(hidedata("[email protected]", 2, 10) // log az***************@email.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment