Skip to content

Instantly share code, notes, and snippets.

@sagarkbhatt
Created May 8, 2019 09:16
Show Gist options
  • Save sagarkbhatt/446f7808ae977a36222cddf7d51f906f to your computer and use it in GitHub Desktop.
Save sagarkbhatt/446f7808ae977a36222cddf7d51f906f to your computer and use it in GitHub Desktop.
Add pad character JS
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