Comparing version 2.0.0 to 2.1.0
14
index.js
'use strict'; | ||
const isDefined = x => x !== null && x !== undefined; | ||
module.exports = (month, year) => { | ||
if (isDefined(month) && typeof month !== 'number') { | ||
throw new TypeError(`Expected \`month\` to be of type \`number\`, got \`${typeof month}\``); | ||
} | ||
if (isDefined(year) && typeof year !== 'number') { | ||
throw new TypeError(`Expected \`year\` to be of type \`number\`, got \`${typeof year}\``); | ||
} | ||
const now = new Date(); | ||
month = (month === null || month === undefined) ? now.getUTCMonth() : month; | ||
year = (year === null || year === undefined) ? now.getUTCFullYear() : year; | ||
month = isDefined(month) ? month : now.getUTCMonth(); | ||
year = isDefined(year) ? year : now.getUTCFullYear(); | ||
return new Date(Date.UTC(year, month + 1, 0)).getUTCDate(); | ||
}; |
{ | ||
"name": "month-days", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Get the number of days in a month", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
2951
14
0