Skip to content

Instantly share code, notes, and snippets.

@data-miner00
Created January 30, 2024 05:49
Show Gist options
  • Save data-miner00/f9ad9c80b625d2e0d5a08b7996e20e43 to your computer and use it in GitHub Desktop.
Save data-miner00/f9ad9c80b625d2e0d5a08b7996e20e43 to your computer and use it in GitHub Desktop.
leftpad

Leftpad

To install, run

npm i gist:<the hash on url>
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;
}
{
"name": "leftpad",
"version": "1.0.0",
"description": "for leftpad a string",
"main": "index.js",
"author": "Shaun Chong <mumk0313@gmail.com>",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment