Created
May 8, 2019 09:16
-
-
Save sagarkbhatt/446f7808ae977a36222cddf7d51f906f to your computer and use it in GitHub Desktop.
Add pad character JS
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
export function pad(type = "right", width = 2, padchar = "0") { | |
return function(value = '0') { | |
value = value.toString(); | |
while (value.length < width) { | |
if ("left" === type) { | |
value = `${padchar}${value}`; | |
} else { | |
value = `${value}${padchar}`; | |
} | |
} | |
return value; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment