From fe05598c52898865f2aa820bc20473094a7192ba Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Oct 2021 17:53:03 +0700 Subject: [PATCH] Require Node.js 12.20 and move to ESM --- .github/workflows/main.yml | 7 ++----- index.d.ts | 28 ++++++++++++---------------- index.js | 5 ++--- index.test-d.ts | 2 +- license | 2 +- package.json | 13 ++++++++----- readme.md | 20 ++++++-------------- test.js | 14 ++++++++++---- 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..441975c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,13 +10,10 @@ jobs: fail-fast: false matrix: node-version: - - 14 - - 12 - - 10 - - 8 + - 16 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index b1f6b71..7084de3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,17 +1,15 @@ -declare namespace monthDays { - interface Options { - /** - Note that the month is zero-index to be consistent with the native date methods. +export interface Options { + /** + Note that the month is zero-index to be consistent with the native date methods. - @default (new Date()).getUTCMonth() - */ - readonly month?: number; + @default (new Date()).getUTCMonth() + */ + readonly month?: number; - /** - @default (new Date).getUTCFullYear() - */ - readonly year?: number; - } + /** + @default (new Date).getUTCFullYear() + */ + readonly year?: number; } /** @@ -19,12 +17,10 @@ Get the number of days in a month. @example ``` -import monthDays = require('month-days'); +import monthDays from 'month-days'; monthDays({month: 1, year: 2016}); //=> 29 ``` */ -declare function monthDays(options?: monthDays.Options): number; - -export = monthDays; +export default function monthDays(options?: Options): number; diff --git a/index.js b/index.js index 97529af..21b5264 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ -'use strict'; const isDefined = value => value !== undefined; -module.exports = ({month, year} = {}) => { +export default function monthDays({month, year} = {}) { if (isDefined(month) && typeof month !== 'number') { throw new TypeError(`Expected \`month\` to be of type \`number\`, got \`${typeof month}\``); } @@ -15,4 +14,4 @@ module.exports = ({month, year} = {}) => { year = isDefined(year) ? year : now.getUTCFullYear(); return new Date(Date.UTC(year, month + 1, 0)).getUTCDate(); -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index 7cbe3ee..3211263 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import monthDays = require('.'); +import monthDays from './index.js'; expectType(monthDays()); expectType(monthDays({month: 1})); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) 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: diff --git a/package.json b/package.json index ffd0a0c..988f49a 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,16 @@ "description": "Get the number of days in a month", "license": "MIT", "repository": "sindresorhus/month-days", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" @@ -29,8 +32,8 @@ "count" ], "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "ava": "^3.15.0", + "tsd": "^0.18.0", + "xo": "^0.45.0" } } diff --git a/readme.md b/readme.md index cc0025d..4d750a6 100644 --- a/readme.md +++ b/readme.md @@ -2,27 +2,24 @@ > Get the number of days in a month - ## Install -``` -$ npm install month-days +```sh +npm install month-days ``` - ## Usage ```js -const monthDays = require('month-days'); +import monthDays from 'month-days'; monthDays({month: 1, year: 2016}); //=> 29 ``` - ## API -### monthDays([options]) +### monthDays(options?) #### options @@ -30,17 +27,12 @@ Type: `object` ##### month -Type: `number`
+Type: `number`\ Default: Current UTC month Note that the month is zero-index to be consistent with the native date methods. ##### year -Type: `number`
+Type: `number`\ Default: Current UTC year - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/test.js b/test.js index 5358639..a16b546 100644 --- a/test.js +++ b/test.js @@ -1,18 +1,24 @@ import test from 'ava'; -import monthDays from '.'; +import monthDays from './index.js'; test('main', t => { t.throws(() => { monthDays({month: '5'}); - }, TypeError); + }, { + instanceOf: TypeError, + }); t.throws(() => { monthDays({month: false}); - }, TypeError); + }, { + instanceOf: TypeError, + }); t.throws(() => { monthDays({month: 5, year: true}); - }, TypeError); + }, { + instanceOf: TypeError, + }); t.is(monthDays({month: 5, year: 2014}), 30); t.is(monthDays({month: 5}), 30);