Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyxla/zeroise
Add leading zeros to fill a certain number to the given size.
https://github.com/tyxla/zeroise
Last synced: about 1 month ago
JSON representation
Add leading zeros to fill a certain number to the given size.
- Host: GitHub
- URL: https://github.com/tyxla/zeroise
- Owner: tyxla
- License: mit
- Created: 2016-01-16T20:51:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-16T22:31:47.000Z (almost 9 years ago)
- Last Synced: 2024-11-20T09:07:17.849Z (about 2 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zeroise
Add leading zeros to fill a certain number to the given size.
```
npm install zeroise
```[![Build Status](https://travis-ci.org/tyxla/zeroise.svg?branch=master)](https://travis-ci.org/tyxla/zeroise)
## About
This will fill a number with leading zeros to reach a specified digit threshold.
If you set the threshold to '4' and the number is '17', then you will get back '0017'.
If you set the threshold to '4' and the number is '1400', then you will get back '1400'.
Optionally, you can specify your preferred string to pad the number with (instead of the default '0').
## Syntax
``` js
zeroise(12, 5, 0);
```#### number
This is the number you wish to pad with leading zeros.
#### threshold
This is the target number of digits you wish to reach.
#### pad
Optional. This is the string you wish to pad by. Default: '0'.
## Usage
Pass the number you wish to pad with zeros, and the number of digits, and you will receive the padded number.
``` js
var zeroise = require('zeroise');var result = zeroise(12, 4);
console.log(result); // 0012
```
## License
MIT