Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Jun 28, 2016
0 parents commit 968f36d
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bower_components
coverage
node_modules
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
git:
depth: 1
branches:
except: /^v\d/
language: node_js
node_js: node
script: npm run-script pretest && npm run-script coverage
after_script:
- npm install istanbul-coveralls
- node node_modules/.bin/istanbul-coveralls
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2016 Shinnosuke Watanabe

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# count-days-in-month

[![NPM version](https://img.shields.io/npm/v/count-days-in-month.svg)](https://www.npmjs.com/package/count-days-in-month)
[![Bower version](https://img.shields.io/bower/v/count-days-in-month.svg)](https://github.com/shinnn/count-days-in-month/releases)
[![Build Status](https://travis-ci.org/shinnn/count-days-in-month.svg?branch=master)](https://travis-ci.org/shinnn/count-days-in-month)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/count-days-in-month.svg)](https://coveralls.io/r/shinnn/count-days-in-month)
[![Dependency Status](https://david-dm.org/shinnn/count-days-in-month.svg)](https://david-dm.org/shinnn/count-days-in-month)
[![devDependency Status](https://david-dm.org/shinnn/count-days-in-month/dev-status.svg)](https://david-dm.org/shinnn/count-days-in-month#info=devDependencies)

Get the number of days in a given month

```javascript
countDaysInMonth(2016, 11); //=> 31
countDaysInMonth(2016, 8); //=> 30
```

## Installation

### Package managers

#### [npm](https://www.npmjs.com/)

```
npm install count-days-in-month
```

#### [bower](https://bower.io/)

```
bower install count-days-in-month
```

## API

### countDaysInMonth(*fullYear*, *zerBasedMonth*)

*fullYear*: `Number` of [full year](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear), for example `2016`
*zeroBasedMonth*: `Number` of month, zero based (`0`, `1`, ... `11`)
Return: `Number` of days

It returns a number of days in the month, considering the year is whether a leap year or not.

```javascript
countDaysInMonth(2015, 1); //=> 28
countDaysInMonth(2016, 1); //=> 29
```

## License

Copyright (c) 2016 [Shinnosuke Watanabe](https://github.com/shinnn)

Licensed under [the MIT License](./LICENSE).
34 changes: 34 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "count-days-in-month",
"description": "Get the number of days in a given month",
"keywords": [
"count",
"day",
"days",
"number",
"month",
"date"
],
"main": "browser.js",
"moduleType": "globals",
"homepage": "https://github.com/shinnn/count-days-in-month",
"repository": {
"type": "git",
"url": "git://github.com/shinnn/count-days-in-month.git"
},
"authors": [
"Shinnosuke Watanabe (https://github.com/shinnn)"
],
"dependencies": {
"is-natural-number": "^4.0.1"
},
"license": "MIT",
"ignore": [
"**/.*",
"*.js",
"*.json",
"*.yml",
"coverage",
"node_modules"
]
}
44 changes: 44 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*!
* count-days-in-month | MIT (c) Shinnosuke Watanabe
* https://github.com/shinnn/count-days-in-month
*/
(function() {
'use strict';

var EXPECTED_YEAR_ARG = ' Expected a number of full year, for example `2016`.';
var EXPECTED_MONTH_ARG = ' Expected a zero-based number of month (0-11).';

window.countDaysInMonth = function countDaysInMonth(fullYear, zeroBasedMonth) {
if (typeof fullYear !== 'number') {
throw new TypeError(String(fullYear) + ' is not a number.' + EXPECTED_YEAR_ARG);
}

if (!window.isNaturalNumber(fullYear, {includeZero: true})) {
throw new RangeError(String(fullYear) + ' is a number, but not a natural number.' + EXPECTED_YEAR_ARG);
}

if (typeof zeroBasedMonth !== 'number') {
throw new TypeError(String(zeroBasedMonth) + ' is not a number.' + EXPECTED_MONTH_ARG);
}

if (!window.isNaturalNumber(zeroBasedMonth, {includeZero: true})) {
throw new RangeError(String(zeroBasedMonth) + ' is a number, but not a natural number.' + EXPECTED_MONTH_ARG);
}

if (zeroBasedMonth > 11) {
throw new RangeError(String(zeroBasedMonth) + ' is larger than 11.' + EXPECTED_MONTH_ARG);
}

var date = new Date();
date.setFullYear(fullYear, zeroBasedMonth + 1, 0);

if (isNaN(date.getTime())) {
throw new RangeError(
String(fullYear) +
' is too large for JavaScript year. Expected a valid number of full year.'
);
}

return date.getDate();
};
})();
44 changes: 44 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*!
* count-days-in-month | MIT (c) Shinnosuke Watanabe
* https://github.com/shinnn/count-days-in-month
*/
'use strict';

var isNaturalNumber = require('is-natural-number');

var EXPECTED_YEAR_ARG = ' Expected a number of full year, for example `2016`.';
var EXPECTED_MONTH_ARG = ' Expected a zero-based number of month (0-11).';

module.exports = function countDaysInMonth(fullYear, zeroBasedMonth) {
if (typeof fullYear !== 'number') {
throw new TypeError(String(fullYear) + ' is not a number.' + EXPECTED_YEAR_ARG);
}

if (!isNaturalNumber(fullYear, {includeZero: true})) {
throw new RangeError(String(fullYear) + ' is a number, but not a natural number.' + EXPECTED_YEAR_ARG);
}

if (typeof zeroBasedMonth !== 'number') {
throw new TypeError(String(zeroBasedMonth) + ' is not a number.' + EXPECTED_MONTH_ARG);
}

if (!isNaturalNumber(zeroBasedMonth, {includeZero: true})) {
throw new RangeError(String(zeroBasedMonth) + ' is a number, but not a natural number.' + EXPECTED_MONTH_ARG);
}

if (zeroBasedMonth > 11) {
throw new RangeError(String(zeroBasedMonth) + ' is larger than 11.' + EXPECTED_MONTH_ARG);
}

var date = new Date();
date.setFullYear(fullYear, zeroBasedMonth + 1, 0);

if (isNaN(date.getTime())) {
throw new RangeError(
String(fullYear) +
' is too large for JavaScript year. Expected a valid number of full year.'
);
}

return date.getDate();
};
42 changes: 42 additions & 0 deletions index.jsnext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*!
* count-days-in-month | MIT (c) Shinnosuke Watanabe
* https://github.com/shinnn/count-days-in-month
*/
import isNaturalNumber from 'is-natural-number';

var EXPECTED_YEAR_ARG = ' Expected a number of full year, for example `2016`.';
var EXPECTED_MONTH_ARG = ' Expected a zero-based number of month (0-11).';

export default function countDaysInMonth(fullYear, zeroBasedMonth) {
if (typeof fullYear !== 'number') {
throw new TypeError(String(fullYear) + ' is not a number.' + EXPECTED_YEAR_ARG);
}

if (!isNaturalNumber(fullYear, {includeZero: true})) {
throw new RangeError(String(fullYear) + ' is a number, but not a natural number.' + EXPECTED_YEAR_ARG);
}

if (typeof zeroBasedMonth !== 'number') {
throw new TypeError(String(zeroBasedMonth) + ' is not a number.' + EXPECTED_MONTH_ARG);
}

if (!isNaturalNumber(zeroBasedMonth, {includeZero: true})) {
throw new RangeError(String(zeroBasedMonth) + ' is a number, but not a natural number.' + EXPECTED_MONTH_ARG);
}

if (zeroBasedMonth > 11) {
throw new RangeError(String(zeroBasedMonth) + ' is larger than 11.' + EXPECTED_MONTH_ARG);
}

var date = new Date();
date.setFullYear(fullYear, zeroBasedMonth + 1, 0);

if (isNaN(date.getTime())) {
throw new RangeError(
String(fullYear) +
' is too large for JavaScript year. Expected a valid number of full year.'
);
}

return date.getDate();
}
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "count-days-in-month",
"version": "1.0.0",
"description": "Get the number of days in a given month",
"repository": "shinnn/count-days-in-month",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"pretest": "bower i --production && eslint --fix --config @shinnn --ignore-path .gitignore .",
"test": "node --strong_mode --throw-deprecation --track-heap-objects test.js | tap-spec",
"coverage": "node --strong_mode node_modules/.bin/istanbul cover -x=bower_components/** test.js"
},
"license": "MIT",
"jsnext:main": "index.jsnext.js",
"files": [
"index.js",
"index.jsnext.js"
],
"keywords": [
"count",
"day",
"days",
"number",
"month",
"date",
"browser",
"client-side"
],
"dependencies": {
"is-natural-number": "^4.0.1"
},
"devDependencies": {
"@shinnn/eslint-config": "^2.4.0",
"bower": "^1.7.9",
"eslint": "^2.13.1",
"istanbul": "^0.4.4",
"last-leap-year": "^1.1.1",
"require-bower-files": "^3.0.0",
"require-from-string": "^1.2.0",
"rollup": "^0.33.0",
"rollup-plugin-node-resolve": "^1.7.1",
"tap-spec": "^4.1.1",
"tape": "^4.6.0"
}
}

0 comments on commit 968f36d

Please sign in to comment.