Created
September 22, 2021 09:29
-
-
Save azkadev/711ec1ae40b406a17f616af70739662c to your computer and use it in GitHub Desktop.
hide data phone number / credit card / passsword / email node javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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