Last active
September 14, 2023 18:49
-
-
Save Arlen22/db6d65812dc4e7237bb3cf14983d8848 to your computer and use it in GitHub Desktop.
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
function leftpad(content, length, pad){ | |
// make sure this is a proper string | |
content = String(content); | |
// get the pad character if set (or if zero) | |
pad = String(pad || pad === 0 ? pad : '')[0]; | |
// get the extra length we need to add, but not less than zero if it's already longer | |
var left = Math.max(length-content.length, 0); | |
// voila! | |
return pad.repeat(left) + content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment