Skip to content

Instantly share code, notes, and snippets.

@erikjung
Last active March 24, 2016 19:12
Show Gist options
  • Save erikjung/d2e6dc2c33c61b0ccfde to your computer and use it in GitHub Desktop.
Save erikjung/d2e6dc2c33c61b0ccfde to your computer and use it in GitHub Desktop.
module.exports = function leftpad (str, len, ch) {
const val = String(str);
const pad = ch === undefined ? ' ' : String(ch);
return pad.repeat(Math.max(0, len - val.length), pad) + val;
};
{
"name": "left-pad",
"main": "left-pad.js",
"version": "0.0.1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment