Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjarneo/zero-pad
Should prepend a 0 to whole numbers <= 9 and >= 0. Perfect use case for dates.
https://github.com/bjarneo/zero-pad
date dates pad padding
Last synced: 3 days ago
JSON representation
Should prepend a 0 to whole numbers <= 9 and >= 0. Perfect use case for dates.
- Host: GitHub
- URL: https://github.com/bjarneo/zero-pad
- Owner: bjarneo
- License: mit
- Created: 2016-04-14T17:07:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-20T09:32:56.000Z (over 6 years ago)
- Last Synced: 2024-09-18T05:49:45.225Z (about 2 months ago)
- Topics: date, dates, pad, padding
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
zero-pad
======
![Travis](https://travis-ci.org/bjarneo/zero-pad.svg?branch=master)Should prepend a 0 to whole numbers less than equal 9 and larger than equal 0. Perfect use case for dates.
Installation
------
```bash
$ npm i --save zero-pad
```Usage
------
```js
const zeroPad = require('zero-pad');console.log(zeroPad(7)); // 07
console.log(zeroPad(9)); // 09
console.log(zeroPad(-1)); // -1
console.log(zeroPad(0.1)); // 0.1// With an array as argument
const arr = zeroPad([1, 10, 7]);
console.log(arr); // [01, 10, 07]// Example with dates
const date = new Date(2016, 10, 5);
const pad = zeroPad([
date.getFullYear(),
date.getMonth(),
date.getDate()
]);console.log(pad.join('-')); // 2016-10-05
```Tests
------
```bash
$ npm test
```Contribution
------
Contributions are appreciated.License
------
MIT-licensed. See LICENSE.