Skip to content

Instantly share code, notes, and snippets.

@yyssjj33
Created April 6, 2016 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyssjj33/63288e19188059ce619d00f3eb3343eb to your computer and use it in GitHub Desktop.
Save yyssjj33/63288e19188059ce619d00f3eb3343eb to your computer and use it in GitHub Desktop.
A 11 lines important npm module, left-pad
module.exports = leftpad;
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment