Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 18, 2021
1 parent 2297c4b commit fe05598
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 49 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
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;
}

/**
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;
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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}\``);
}
Expand All @@ -15,4 +14,4 @@ module.exports = ({month, year} = {}) => {
year = isDefined(year) ? year : now.getUTCFullYear();

return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import monthDays = require('.');
import monthDays from './index.js';

expectType<number>(monthDays());
expectType<number>(monthDays({month: 1}));
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (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:

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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"
Expand All @@ -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"
}
}
20 changes: 6 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,37 @@

> 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

Type: `object`

##### month

Type: `number`<br>
Type: `number`\
Default: Current UTC month

Note that the month is zero-index to be consistent with the native date methods.

##### year

Type: `number`<br>
Type: `number`\
Default: Current UTC year


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
14 changes: 10 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit fe05598

Please sign in to comment.