JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2050
  • Score
    100M100P100Q139497F
  • License MIT

Zeropad your integers with optional n-length padding.

Package Exports

  • zeropad

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 (zeropad) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

zeropad

Zeropad your integers with optional n-length padding.

Build Status

The default is to give you classic padding behavior where numbers less than 10 are padded with a single zero:
'9' → '09', but you can optionally pad to any length, for example: '9' → '0009'.

Note: Since version 1.1.0 you can also pad negative numbers.

Install

$ npm install --save zeropad

Usage

var zeropad = require('zeropad');

zeropad(5);
// => '05'

zeropad(10, 4);
// => '0010'

zeropad('11', 4);
// => '0011'

zeropad(4, 10);
// => '0000000004');

zeropad(9, 4);
// => '0009');

zeropad(-9, 4);
// => '-0009');

API

zeropad(number, [length])

number

Required
Type: Number String

The number you want to pad.

length

Type: Number
Default: 2

The length you want to pad to. The default is 2, which emulates classic padding behavior.

License

MIT @ Michael Wuergler