zpa

zpad

Zero padding for numbers.

Showing:

Popularity

Downloads/wk

1.1K

Maintenance

No Maintenance Data Available

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

CC0-1.0

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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 = require('zpad');
zpad(5);             // -> "05", zpad pads to 2 digits by default
zpad(5, 3);          // -> "005", you can pass a second parameter to specify the amount of digits
zpad.amount(3);      // change the default padding amount by calling zpad.amount with a number
zpad.amount();       // -> 3, returns the padding amount with no arguments
zpad(5);             // -> "005"
zpad.character('X'); // change what is used for padding by calling zpad.character with a string
zpad.character();    // -> "X", returns the padding character with no arguments
zpad(5);             // -> "XX5"
zpad(5, 3, 'Z');     // -> "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 module
var pad = require('zpad').amount(4).character('Y');
pad(5);              // -> "YYY5"

Legalese

No Rights Reserved, zpad has been released under CC0. Feel free to use it in any manner you want.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial