Skip to content

Commit 99f0762

Browse files
committed
Extract into github-url-detection module
1 parent 2a8bc94 commit 99f0762

File tree

16 files changed

+455
-195
lines changed

16 files changed

+455
-195
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
jobs:
8+
Lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- run: npm install
13+
- run: npm run xo
14+
15+
Build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- run: npm install
20+
- run: npm run build
21+
22+
Test:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- run: npm install
27+
- run: npm run ava

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
.DS_Store
3+
Desktop.ini
4+
._*
5+
Thumbs.db
6+
*.tmp
7+
*.bak
8+
*.log
9+
logs
10+
*.map
11+
cjs
12+
esm

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

license

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.

package.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"name": "github-url-detection",
3+
"version": "1.0.0",
4+
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
5+
"keywords": [
6+
"github",
7+
"page",
8+
"routes",
9+
"detect",
10+
"test",
11+
"extension"
12+
],
13+
"repository": "fregante/github-url-detection",
14+
"license": "MIT",
15+
"author": "Federico Brigante <opensource@bfred.it> (bfred.it)",
16+
"main": "cjs/index.js",
17+
"module": "esm/index.js",
18+
"files": [
19+
"cjs/index.js",
20+
"cjs/index.d.ts",
21+
"esm/index.js",
22+
"esm/index.d.ts"
23+
],
24+
"scripts": {
25+
"ava": "TS_NODE_PROJECT=tsconfig.ava.json ava",
26+
"build": "rollup -c",
27+
"prepack": "rollup -c",
28+
"test": "run-p build ava xo",
29+
"watch": "rollup -c --watch",
30+
"xo": "xo"
31+
},
32+
"xo": {
33+
"envs": [
34+
"browser"
35+
],
36+
"rules": {
37+
"camelcase": "off",
38+
"@typescript-eslint/prefer-readonly-parameter-types": "off",
39+
"comma-dangle": [
40+
"error",
41+
"always-multiline"
42+
]
43+
}
44+
},
45+
"ava": {
46+
"extensions": [
47+
"ts"
48+
],
49+
"require": [
50+
"esm",
51+
"ts-node/register"
52+
]
53+
},
54+
"devDependencies": {
55+
"@rollup/plugin-json": "^4.0.3",
56+
"@rollup/plugin-node-resolve": "^7.1.3",
57+
"@rollup/plugin-typescript": "^4.1.1",
58+
"@sindresorhus/tsconfig": "^0.7.0",
59+
"@types/jsdom": "^16.2.1",
60+
"ava": "^3.8.1",
61+
"esm": "^3.2.25",
62+
"github-reserved-names": "^1.1.8",
63+
"jsdom": "^16.2.2",
64+
"npm-run-all": "^4.1.5",
65+
"rollup": "^2.7.6",
66+
"rollup-plugin-terser": "^5.3.0",
67+
"strip-indent": "^3.0.0",
68+
"ts-node": "^8.10.1",
69+
"tslib": "^1.11.2",
70+
"typescript": "^3.8.3",
71+
"xo": "^0.30.0"
72+
}
73+
}

readme.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# github-url-detection [![][badge-gzip]][link-bundlephobia]
2+
3+
[badge-gzip]: https://img.shields.io/bundlephobia/minzip/github-url-detection.svg?label=gzipped
4+
[link-bundlephobia]: https://bundlephobia.com/result?p=github-url-detection
5+
6+
> Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.
7+
8+
Battle-tested by and extracted from the [Refined GitHub](https://github.com/sindresorhus/refined-github) extension.
9+
10+
## Install
11+
12+
```sh
13+
npm install github-url-detection
14+
```
15+
16+
```js
17+
import * as pageDetect from 'github-url-detection';
18+
```
19+
20+
```js
21+
const pageDetect = require('github-url-detection');
22+
```
23+
24+
## Usage
25+
26+
```js
27+
if (pageDetect.isRepo()) {
28+
alert('You’re looking at a repo!')
29+
}
30+
31+
32+
if (pageDetect.isDiscussionList()) {
33+
alert('You’re looking at a issues and PRs list!')
34+
}
35+
```
36+
37+
In the source you can see the [full list of detections](https://www.unpkg.com/browse/github-url-detection@latest/esm/index.d.ts) and [their matching URLs.](https://github.com/fregante/github-url-detection/blob/master/source/index.ts)
38+
39+
Most tests are URL-based but a handful of them are DOM-based.
40+
41+
## License
42+
43+
MIT © [Federico Brigante](https://bfred.it)

rollup.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
import {terser} from 'rollup-plugin-terser';
3+
import json from '@rollup/plugin-json';
4+
5+
export default ['cjs', 'esm'].map(format => ({
6+
input: 'source/index.ts',
7+
output: {
8+
format,
9+
dir: format,
10+
},
11+
plugins: [
12+
typescript({
13+
outDir: format,
14+
}),
15+
json(),
16+
terser({
17+
toplevel: true,
18+
output: {
19+
comments: false,
20+
beautify: true,
21+
},
22+
mangle: false,
23+
compress: {
24+
join_vars: false,
25+
booleans: false,
26+
expression: false,
27+
sequences: false,
28+
pure_funcs: [
29+
'collect.set',
30+
'collect.get',
31+
'Map',
32+
],
33+
},
34+
},
35+
),
36+
],
37+
}));

source/collector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default new Map<string, string[] | 'combinedTestOnly'>();

source/globals.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'github-reserved-names/reserved-names.json' {
2+
const Names: string[];
3+
export default Names;
4+
}

0 commit comments

Comments
 (0)