Package Exports
- zerop
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zerop) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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