1.0.1 • Published 8 years ago

zerop v1.0.1

Weekly downloads
260
License
MIT
Repository
github
Last release
8 years ago

view on npm downloads per month node version build status test coverage license

zerop

Pad a number with leading or trailing zeros. Currently it's the most efficient package available with this purpose.

Usage

const pad = require('zerop')

pad(42, 5) // '00042'
pad(42, 5, 16) // '0002a'
pad.right(42, 5) // '42000'

API

zerop(number, [length=2], [radix=10])string zerop.right(number, [length=2], [radix=10])string

const pad = require('zerop')

typeof pad === 'function' // pad left
pad === pad.left // reference to the main export
typeof pad.right === 'function' // pad right
typeof pad.version === 'string' // version string from package manifest

pad(11) === '11'
pad(11, 3) === '011'
pad(11, 3, 16) === '00b'

Benchmark

The benchmark measures elapsed time it takes to perform 5000000 calls. (Which means that lower values are better.) Here are the results of popular zero-pad packages:

zerop: 420.415ms
pad: 996.018ms
zpad: 841.704ms
npad: 487.840ms
zeroise: 4690.073ms
padster: 1749.308ms
zerofill: 820.477ms
zero-fill: 5270.587ms

Installation

With npm:

npm install zerop

License

MIT