Created
June 10, 2019 14:53
-
-
Save malisbad/d8851fcf0657897ac5149bfc9d5012f4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sasazoxore
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const longTestStr = "1234123412341234"; | |
const shortTestStr = "12"; | |
const maskString = (str, numOfUnmasked = 4, totalLength = 12) => { | |
const unmasked = str.slice(numOfUnmasked * -1); // start from right and go left | |
return { | |
masked: unmasked.padStart(totalLength, '\u2022'), | |
unmasked: str, | |
} | |
} | |
console.log(maskString(longTestStr)); | |
console.log(maskString(shortTestStr)); | |
console.log(maskString(shortTestStr, 5)); | |
console.log(maskString(shortTestStr, 5, 5)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const longTestStr = "1234123412341234"; | |
const shortTestStr = "12"; | |
const maskString = (str, numOfUnmasked = 4, totalLength = 12) => { | |
const unmasked = str.slice(numOfUnmasked * -1); // start from right and go left | |
return { | |
masked: unmasked.padStart(totalLength, '\u2022'), | |
unmasked: str, | |
} | |
} | |
console.log(maskString(longTestStr)); | |
console.log(maskString(shortTestStr)); | |
console.log(maskString(shortTestStr, 5)); | |
console.log(maskString(shortTestStr, 5, 5));</script></body> | |
</html> |
This file contains hidden or 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
const longTestStr = "1234123412341234"; | |
const shortTestStr = "12"; | |
const maskString = (str, numOfUnmasked = 4, totalLength = 12) => { | |
const unmasked = str.slice(numOfUnmasked * -1); // start from right and go left | |
return { | |
masked: unmasked.padStart(totalLength, '\u2022'), | |
unmasked: str, | |
} | |
} | |
console.log(maskString(longTestStr)); | |
console.log(maskString(shortTestStr)); | |
console.log(maskString(shortTestStr, 5)); | |
console.log(maskString(shortTestStr, 5, 5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment