zpad - Zero padding for Node.js
zpad is a tiny Node.js module for zero padding strings and numbers, because I got tired of copypasting a function for this in every other thing I've been writing.
Installation
zpad is available via npm:
$ npm install zpad
Usage
var zpad = ;; // -> "05", zpad pads to 2 digits by default; // -> "005", you can pass a second parameter to specify the amount of digitszpad; // change the default padding amount by calling zpad.amount with a numberzpad; // -> 3, returns the padding amount with no arguments; // -> "005"zpad; // change what is used for padding by calling zpad.character with a stringzpad; // -> "X", returns the padding character with no arguments; // -> "XX5"; // -> "ZZ5", you can also pass custom pad character as third parameter // .amount and .character can also be chained, allowing you to define them when loading the modulevar pad = ;; // -> "YYY5"
Legalese
No Rights Reserved, zpad has been released under CC0. Feel free to use it in any manner you want.