Skip to content

Commit aa0cf6e

Browse files
committed
Require Node.js 12.20 and move to ESM
1 parent 7ff8f63 commit aa0cf6e

File tree

8 files changed

+115
-140
lines changed

8 files changed

+115
-140
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
15-
- 10
13+
- 16
1614
steps:
1715
- uses: actions/checkout@v2
18-
- uses: actions/setup-node@v1
16+
- uses: actions/setup-node@v2
1917
with:
2018
node-version: ${{ matrix.node-version }}
2119
- run: npm install

index.d.ts

Lines changed: 83 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,95 @@
1-
declare namespace newGithubIssueUrl {
2-
interface CommonOptions {
3-
/**
4-
The issue body.
5-
*/
6-
readonly body?: string;
7-
8-
/**
9-
The issue title.
10-
*/
11-
readonly title?: string;
12-
13-
/**
14-
Use an [issue template](https://help.github.com/articles/manually-creating-a-single-issue-template-for-your-repository/).
15-
16-
@example
17-
```
18-
'unicorn.md' // If you want to use a template at `ISSUE_TEMPLATE/unicorn.md`.
19-
```
20-
*/
21-
readonly template?: string;
22-
23-
/**
24-
The labels for the issue.
25-
26-
_Requires the user to have the permission to add labels._
27-
*/
28-
readonly labels?: string[];
29-
30-
/**
31-
The milestone for the issue.
32-
33-
_Requires the user to have the permission to add milestone._
34-
*/
35-
readonly milestone?: string;
36-
37-
/**
38-
The user to assign to the issue.
39-
40-
_Requires the user to have the permission to add assignee._
41-
*/
42-
readonly assignee?: string;
43-
44-
/**
45-
The projects to add the issue to.
46-
The project reference format is `user/<project-number>`, for example, if the URL to the project is `https://github.com/sindresorhus/some-repo/projects/3`, the project reference would be `some-repo/3`.
47-
48-
_Requires the user to have the permission to add projects._
49-
*/
50-
readonly projects?: string[];
51-
}
52-
53-
interface RepoUrlOptions extends CommonOptions {
54-
/**
55-
The full URL to the repo.
56-
*/
57-
readonly repoUrl: string;
58-
}
59-
60-
interface UserAndRepoOptions extends CommonOptions {
61-
/**
62-
GitHub username or organization.
63-
*/
64-
readonly user: string;
65-
66-
/**
67-
GitHub repo.
68-
*/
69-
readonly repo: string;
70-
}
1+
export interface CommonOptions {
2+
/**
3+
The issue body.
4+
*/
5+
readonly body?: string;
716

727
/**
73-
You are required to either specify the `repoUrl` option or both the `user` and `repo` options.
8+
The issue title.
749
*/
75-
type Options = RepoUrlOptions | UserAndRepoOptions;
76-
}
10+
readonly title?: string;
7711

78-
declare const newGithubIssueUrl: {
7912
/**
80-
Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields.
13+
Use an [issue template](https://help.github.com/articles/manually-creating-a-single-issue-template-for-your-repository/).
8114
8215
@example
8316
```
84-
import newGithubIssueUrl = require('new-github-issue-url');
85-
import open = require('open');
86-
87-
const url = newGithubIssueUrl({
88-
user: 'sindresorhus',
89-
repo: 'new-github-issue-url',
90-
body: '\n\n\n---\nI\'m a human. Please be nice.'
91-
});
92-
//=> 'https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.'
93-
94-
// Then open it
95-
(async () => {
96-
await open(url);
97-
}}();
17+
'unicorn.md' // If you want to use a template at `ISSUE_TEMPLATE/unicorn.md`.
9818
```
9919
*/
100-
(options: newGithubIssueUrl.Options): string;
20+
readonly template?: string;
21+
22+
/**
23+
The labels for the issue.
24+
25+
_Requires the user to have the permission to add labels._
26+
*/
27+
readonly labels?: string[];
28+
29+
/**
30+
The milestone for the issue.
31+
32+
_Requires the user to have the permission to add milestone._
33+
*/
34+
readonly milestone?: string;
35+
36+
/**
37+
The user to assign to the issue.
38+
39+
_Requires the user to have the permission to add assignee._
40+
*/
41+
readonly assignee?: string;
10142

102-
// TODO: Remove this for the next major release, refactor the whole definition to:
103-
// declare function newGithubIssueUrl(options: newGithubIssueUrl.Options): string;
104-
// export = newGithubIssueUrl;
105-
default: typeof newGithubIssueUrl;
106-
};
43+
/**
44+
The projects to add the issue to.
45+
The project reference format is `user/<project-number>`, for example, if the URL to the project is `https://github.com/sindresorhus/some-repo/projects/3`, the project reference would be `some-repo/3`.
46+
47+
_Requires the user to have the permission to add projects._
48+
*/
49+
readonly projects?: string[];
50+
}
51+
52+
export interface RepoUrlOptions extends CommonOptions {
53+
/**
54+
The full URL to the repo.
55+
*/
56+
readonly repoUrl: string;
57+
}
58+
59+
export interface UserAndRepoOptions extends CommonOptions {
60+
/**
61+
GitHub username or organization.
62+
*/
63+
readonly user: string;
64+
65+
/**
66+
GitHub repo.
67+
*/
68+
readonly repo: string;
69+
}
10770

108-
export = newGithubIssueUrl;
71+
/**
72+
You are required to either specify the `repoUrl` option or both the `user` and `repo` options.
73+
*/
74+
export type Options = RepoUrlOptions | UserAndRepoOptions;
75+
76+
/**
77+
Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields.
78+
79+
@example
80+
```
81+
import newGithubIssueUrl from 'new-github-issue-url';
82+
import open from 'open';
83+
84+
const url = newGithubIssueUrl({
85+
user: 'sindresorhus',
86+
repo: 'new-github-issue-url',
87+
body: '\n\n\n---\nI\'m a human. Please be nice.'
88+
});
89+
//=> 'https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.'
90+
91+
// Then open it
92+
await open(url);
93+
```
94+
*/
95+
export default function newGithubIssueUrl(options: Options): string;

index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
module.exports = (options = {}) => {
1+
export default function newGithubIssueUrl(options = {}) {
42
let repoUrl;
53
if (options.repoUrl) {
64
repoUrl = options.repoUrl;
@@ -19,7 +17,7 @@ module.exports = (options = {}) => {
1917
'template',
2018
'milestone',
2119
'assignee',
22-
'projects'
20+
'projects',
2321
];
2422

2523
for (const type of types) {
@@ -40,7 +38,4 @@ module.exports = (options = {}) => {
4038
}
4139

4240
return url.toString();
43-
};
44-
45-
// TODO: Remove this for the next major release
46-
module.exports.default = module.exports;
41+
}

index.test-d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {expectType} from 'tsd';
2-
import newGithubIssueUrl = require('.');
2+
import newGithubIssueUrl from './index.js';
33

44
expectType<string>(
55
newGithubIssueUrl({
66
repoUrl: 'https://github.com/sindresorhus/new-github-issue-url',
7-
body: 'test'
8-
})
7+
body: 'test',
8+
}),
99
);
1010

1111
expectType<string>(
1212
newGithubIssueUrl({
1313
user: 'sindresorhus',
14-
repo: 'new-github-issue-url'
15-
})
14+
repo: 'new-github-issue-url',
15+
}),
1616
);

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
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:
66

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields",
55
"license": "MIT",
66
"repository": "sindresorhus/new-github-issue-url",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=10"
16+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -32,8 +35,8 @@
3235
"params"
3336
],
3437
"devDependencies": {
35-
"ava": "^1.4.1",
36-
"tsd": "^0.7.2",
37-
"xo": "^0.24.0"
38+
"ava": "^3.15.0",
39+
"tsd": "^0.18.0",
40+
"xo": "^0.45.0"
3841
}
3942
}

readme.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
55
GitHub supports prefilling a new issue by setting [certain search parameters](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue#creating-an-issue-from-a-url-query). This package simplifies generating such URL.
66

7-
87
## Install
98

10-
```
11-
$ npm install new-github-issue-url
9+
```sh
10+
npm install new-github-issue-url
1211
```
1312

14-
1513
## Usage
1614

1715
```js
18-
const newGithubIssueUrl = require('new-github-issue-url');
19-
const open = require('open');
16+
import newGithubIssueUrl from 'new-github-issue-url';
17+
import open from 'open';
2018

2119
const url = newGithubIssueUrl({
2220
user: 'sindresorhus',
@@ -26,16 +24,14 @@ const url = newGithubIssueUrl({
2624
//=> 'https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.'
2725

2826
// Then open it
29-
(async () => {
30-
await open(url);
31-
})();
27+
await open(url);
3228
```
3329

34-
[Try the URL](https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.)<br>*(Don't click the "Submit new issue" button!)*
30+
[Try the URL](https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.)\
31+
*(Don't click the "Submit new issue" button!)*
3532

3633
If you use Electron, check out `electron-util`'s [`openNewGitHubIssue()` method](https://github.com/sindresorhus/electron-util#opennewgithubissueoptions).
3734

38-
3935
## API
4036

4137
### newGithubIssueUrl(options)
@@ -120,12 +116,6 @@ The project reference format is `user/repo/<project-number>`, for example, if th
120116

121117
*Requires the user to have the permission to add projects.*
122118

123-
124119
## Related
125120

126121
- [new-github-release-url](https://github.com/sindresorhus/new-github-release-url) - Generate a URL for opening a new GitHub release with prefilled tag, body, and other fields
127-
128-
129-
## License
130-
131-
MIT © [Sindre Sorhus](https://sindresorhus.com)

test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import newGithubIssueUrl from '.';
2+
import newGithubIssueUrl from './index.js';
33

44
test('main', t => {
55
const user = 'sindresorhus';
@@ -11,7 +11,7 @@ test('main', t => {
1111
user,
1212
repo,
1313
body,
14-
title
14+
title,
1515
});
1616

1717
const {searchParams} = new URL(urlString);
@@ -30,7 +30,7 @@ test('repoUrl option', t => {
3030
const urlString = newGithubIssueUrl({
3131
repoUrl,
3232
body,
33-
title
33+
title,
3434
});
3535

3636
const {searchParams} = new URL(urlString);
@@ -43,5 +43,7 @@ test('repoUrl option', t => {
4343
test('throws when required options are not specified', t => {
4444
t.throws(() => {
4545
newGithubIssueUrl();
46-
}, /need to specify either/);
46+
}, {
47+
message: /need to specify either/,
48+
});
4749
});

0 commit comments

Comments
 (0)