zerop
Pad a number with leading or trailing zeros. Currently it's the most efficient package available with this purpose.
Usage
const pad = // '00042' // '0002a'padright42 5 // '42000'
API
zerop(number, [length=2], [radix=10])
⇒ string
zerop.right(number, [length=2], [radix=10])
⇒ string
const pad = typeof pad === 'function' // pad leftpad === padleft // reference to the main exporttypeof padright === 'function' // pad righttypeof padversion === 'string' // version string from package manifest === '11' === '011' === '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