github-url-detection 5.2.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distribution/index.d.ts +10 -5
- package/distribution/index.js +24 -10
- package/package.json +16 -15
- package/readme.md +0 -3
package/distribution/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const isMilestoneList: (url?: URL | HTMLAnchorElement | Location)
|
|
|
20
20
|
export declare const isNewFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
21
21
|
export declare const isNewIssue: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
22
22
|
export declare const isNewRelease: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
23
|
+
export declare const isNewWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
23
24
|
export declare const isNotifications: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
24
25
|
export declare const isOrganizationProfile: () => boolean;
|
|
25
26
|
export declare const isOrganizationRepo: () => boolean;
|
|
@@ -47,6 +48,7 @@ export declare const isClosedPR: () => boolean;
|
|
|
47
48
|
export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
48
49
|
export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
49
50
|
export declare const isEditingRelease: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
51
|
+
export declare const isEditingWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
50
52
|
export declare const isRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
51
53
|
export declare const isEmptyRepoRoot: () => boolean;
|
|
52
54
|
export declare const isEmptyRepo: () => boolean;
|
|
@@ -72,12 +74,13 @@ export declare const isForkedRepo: () => boolean;
|
|
|
72
74
|
export declare const isSingleGist: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
73
75
|
export declare const isTrending: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
74
76
|
export declare const isBranches: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
77
|
+
export declare const isProfile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
75
78
|
export declare const isUserProfile: () => boolean;
|
|
76
79
|
export declare const isUserProfileMainTab: () => boolean;
|
|
77
|
-
export declare const isUserProfileRepoTab: () => boolean;
|
|
78
|
-
export declare const isUserProfileStarsTab: () => boolean;
|
|
79
|
-
export declare const isUserProfileFollowersTab: () => boolean;
|
|
80
|
-
export declare const isUserProfileFollowingTab: () => boolean;
|
|
80
|
+
export declare const isUserProfileRepoTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
81
|
+
export declare const isUserProfileStarsTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
82
|
+
export declare const isUserProfileFollowersTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
83
|
+
export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
81
84
|
export declare const isSingleTag: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
82
85
|
export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
83
86
|
export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -87,6 +90,8 @@ export declare const isActionJobRun: (url?: URL | HTMLAnchorElement | Location)
|
|
|
87
90
|
export declare const isActionRun: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
88
91
|
export declare const isNewAction: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
89
92
|
export declare const isRepositoryActions: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
93
|
+
export declare const isUserTheOrganizationOwner: () => boolean;
|
|
94
|
+
/** @deprecated use isUserTheOrganizationOwner instead */
|
|
90
95
|
export declare const canUserEditOrganization: () => boolean;
|
|
91
96
|
export declare const canUserEditRepo: () => boolean;
|
|
92
97
|
export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -103,7 +108,7 @@ export interface RepositoryInfo {
|
|
|
103
108
|
path: string;
|
|
104
109
|
}
|
|
105
110
|
export declare const utils: {
|
|
106
|
-
getUsername: () => string;
|
|
111
|
+
getUsername: () => string | undefined;
|
|
107
112
|
getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string;
|
|
108
113
|
getRepositoryInfo: (url?: string | URL | HTMLAnchorElement | Location | undefined) => RepositoryInfo | undefined;
|
|
109
114
|
};
|
package/distribution/index.js
CHANGED
|
@@ -76,6 +76,8 @@ const isNewRelease = (url = location) => {
|
|
|
76
76
|
return "releases/new" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
+
const isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new");
|
|
80
|
+
|
|
79
81
|
const isNotifications = (url = location) => "notifications" === getCleanPathname(url);
|
|
80
82
|
|
|
81
83
|
const isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
|
|
@@ -170,6 +172,8 @@ const isEditingRelease = (url = location) => {
|
|
|
170
172
|
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("releases/edit"));
|
|
171
173
|
};
|
|
172
174
|
|
|
175
|
+
const isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
|
|
176
|
+
|
|
173
177
|
const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isRepoSearch(url) && !isNewRepoTemplate(url);
|
|
174
178
|
|
|
175
179
|
const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
|
|
@@ -265,17 +269,22 @@ const isBranches = (url = location) => {
|
|
|
265
269
|
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("branches"));
|
|
266
270
|
};
|
|
267
271
|
|
|
268
|
-
const
|
|
272
|
+
const isProfile = (url = location) => {
|
|
273
|
+
const pathname = getCleanPathname(url);
|
|
274
|
+
return pathname.length > 0 && !pathname.includes("/") && !reservedNames.includes(pathname);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const isUserProfile = () => isProfile() && !isOrganizationProfile();
|
|
269
278
|
|
|
270
|
-
const isUserProfileMainTab = () =>
|
|
279
|
+
const isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab");
|
|
271
280
|
|
|
272
|
-
const isUserProfileRepoTab = () =>
|
|
281
|
+
const isUserProfileRepoTab = (url = location) => isProfile(url) && "repositories" === new URLSearchParams(url.search).get("tab");
|
|
273
282
|
|
|
274
|
-
const isUserProfileStarsTab = () =>
|
|
283
|
+
const isUserProfileStarsTab = (url = location) => isProfile(url) && "stars" === new URLSearchParams(url.search).get("tab");
|
|
275
284
|
|
|
276
|
-
const isUserProfileFollowersTab = () =>
|
|
285
|
+
const isUserProfileFollowersTab = (url = location) => isProfile(url) && "followers" === new URLSearchParams(url.search).get("tab");
|
|
277
286
|
|
|
278
|
-
const isUserProfileFollowingTab = () =>
|
|
287
|
+
const isUserProfileFollowingTab = (url = location) => isProfile(url) && "following" === new URLSearchParams(url.search).get("tab");
|
|
279
288
|
|
|
280
289
|
const isSingleTag = (url = location) => {
|
|
281
290
|
var _a;
|
|
@@ -284,7 +293,7 @@ const isSingleTag = (url = location) => {
|
|
|
284
293
|
|
|
285
294
|
const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isOrganizationDiscussion(url) || isSingleGist(url);
|
|
286
295
|
|
|
287
|
-
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || isDiscussion(url);
|
|
296
|
+
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || isNewRelease(url) || isDiscussion(url);
|
|
288
297
|
|
|
289
298
|
const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isBlame(url);
|
|
290
299
|
|
|
@@ -310,7 +319,9 @@ const isRepositoryActions = (url = location) => {
|
|
|
310
319
|
return /^actions(\/workflows\/.+\.ya?ml)?$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
311
320
|
};
|
|
312
321
|
|
|
313
|
-
const
|
|
322
|
+
const isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
|
|
323
|
+
|
|
324
|
+
const canUserEditOrganization = isUserTheOrganizationOwner;
|
|
314
325
|
|
|
315
326
|
const canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
|
|
316
327
|
|
|
@@ -318,7 +329,10 @@ const isNewRepo = (url = location) => "/new" === url.pathname || /^organizations
|
|
|
318
329
|
|
|
319
330
|
const isNewRepoTemplate = (url = location) => Boolean("generate" === url.pathname.split("/")[3]);
|
|
320
331
|
|
|
321
|
-
const getUsername = () =>
|
|
332
|
+
const getUsername = () => {
|
|
333
|
+
var _a;
|
|
334
|
+
return null === (_a = document.querySelector('meta[name="user-login"]')) || void 0 === _a ? void 0 : _a.getAttribute("content");
|
|
335
|
+
};
|
|
322
336
|
|
|
323
337
|
const getCleanPathname = (url = location) => url.pathname.slice(1, url.pathname.endsWith("/") ? -1 : void 0);
|
|
324
338
|
|
|
@@ -347,4 +361,4 @@ const utils = {
|
|
|
347
361
|
getRepositoryInfo: getRepo
|
|
348
362
|
};
|
|
349
363
|
|
|
350
|
-
export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasRichTextEditor, is404, is500, isActionJobRun, isActionRun, isBlame, isBranches, isClosedPR, isCommit, isCommitList, isCompare, isConversation, isConversationList, isDashboard, isDiscussion, isDiscussionList, isDraftPR, isEditingFile, isEditingRelease, isEmptyRepo, isEmptyRepoRoot, isEnterprise, isFileFinder, isForkedRepo, isGist, isGlobalConversationList, isGlobalSearchResults, isIssue, isLabelList, isMarketplaceAction, isMergedPR, isMilestone, isMilestoneList, isNewAction, isNewFile, isNewIssue, isNewRelease, isNewRepo, isNewRepoTemplate, isNotifications, isOpenPR, isOrganizationDiscussion, isOrganizationProfile, isOrganizationRepo, isOwnOrganizationProfile, isOwnUserProfile, isPR, isPRCommit, isPRCommit404, isPRCommitList, isPRConflicts, isPRConversation, isPRFile404, isPRFiles, isPRList, isPasswordConfirmation, isProject, isQuickPR, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTrending, isUserProfile, isUserProfileFollowersTab, isUserProfileFollowingTab, isUserProfileMainTab, isUserProfileRepoTab, isUserProfileStarsTab, isUserSettings, utils };
|
|
364
|
+
export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasRichTextEditor, is404, is500, isActionJobRun, isActionRun, isBlame, isBranches, isClosedPR, isCommit, isCommitList, isCompare, isConversation, isConversationList, isDashboard, isDiscussion, isDiscussionList, isDraftPR, isEditingFile, isEditingRelease, isEditingWikiPage, isEmptyRepo, isEmptyRepoRoot, isEnterprise, isFileFinder, isForkedRepo, isGist, isGlobalConversationList, isGlobalSearchResults, isIssue, isLabelList, isMarketplaceAction, isMergedPR, isMilestone, isMilestoneList, isNewAction, isNewFile, isNewIssue, isNewRelease, isNewRepo, isNewRepoTemplate, isNewWikiPage, isNotifications, isOpenPR, isOrganizationDiscussion, isOrganizationProfile, isOrganizationRepo, isOwnOrganizationProfile, isOwnUserProfile, isPR, isPRCommit, isPRCommit404, isPRCommitList, isPRConflicts, isPRConversation, isPRFile404, isPRFiles, isPRList, isPasswordConfirmation, isProfile, isProject, isQuickPR, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTrending, isUserProfile, isUserProfileFollowersTab, isUserProfileFollowingTab, isUserProfileMainTab, isUserProfileRepoTab, isUserProfileStarsTab, isUserSettings, isUserTheOrganizationOwner, utils };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-url-detection",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"ava/assertion-arguments": "off",
|
|
53
53
|
"@typescript-eslint/dot-notation": "off",
|
|
54
54
|
"@typescript-eslint/no-non-null-assertion": "off",
|
|
55
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
55
56
|
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
|
|
56
57
|
"@typescript-eslint/comma-dangle": [
|
|
57
58
|
"error",
|
|
@@ -89,25 +90,25 @@
|
|
|
89
90
|
},
|
|
90
91
|
"devDependencies": {
|
|
91
92
|
"@rollup/plugin-json": "^4.1.0",
|
|
92
|
-
"@rollup/plugin-node-resolve": "^
|
|
93
|
-
"@rollup/plugin-typescript": "^8.2.
|
|
94
|
-
"@sindresorhus/tsconfig": "^
|
|
95
|
-
"@types/jsdom": "^16.2.
|
|
93
|
+
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
94
|
+
"@rollup/plugin-typescript": "^8.2.5",
|
|
95
|
+
"@sindresorhus/tsconfig": "^2.0.0",
|
|
96
|
+
"@types/jsdom": "^16.2.13",
|
|
96
97
|
"ava": "^3.15.0",
|
|
97
98
|
"github-reserved-names": "^2.0.4",
|
|
98
|
-
"jsdom": "^
|
|
99
|
+
"jsdom": "^17.0.0",
|
|
99
100
|
"npm-run-all": "^4.1.5",
|
|
100
101
|
"parcel-bundler": "^1.12.4",
|
|
101
|
-
"parcel-plugin-svelte": "^4.0.
|
|
102
|
-
"rollup": "^2.
|
|
102
|
+
"parcel-plugin-svelte": "^4.0.9",
|
|
103
|
+
"rollup": "^2.57.0",
|
|
103
104
|
"rollup-plugin-terser": "^7.0.2",
|
|
104
|
-
"strip-indent": "^
|
|
105
|
-
"svelte": "^3.
|
|
106
|
-
"svelte-check": "^
|
|
107
|
-
"ts-node": "^
|
|
108
|
-
"tslib": "^2.
|
|
109
|
-
"typescript": "^4.
|
|
110
|
-
"xo": "^0.
|
|
105
|
+
"strip-indent": "^4.0.0",
|
|
106
|
+
"svelte": "^3.43.0",
|
|
107
|
+
"svelte-check": "^2.2.6",
|
|
108
|
+
"ts-node": "^10.2.1",
|
|
109
|
+
"tslib": "^2.3.1",
|
|
110
|
+
"typescript": "^4.4.3",
|
|
111
|
+
"xo": "^0.44.0"
|
|
111
112
|
},
|
|
112
113
|
"engines": {
|
|
113
114
|
"node": ">=12"
|
package/readme.md
CHANGED
|
@@ -37,8 +37,6 @@ if (pageDetect.isConversationList()) {
|
|
|
37
37
|
|
|
38
38
|
## API
|
|
39
39
|
|
|
40
|
-
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/index.ts)
|
|
41
|
-
|
|
42
40
|
Most detections are URL-based while others need access to the current `document`. You can determine which ones are URL-based by looking at their signature: URL-based functions have a `url` parameter.
|
|
43
41
|
|
|
44
42
|
### URL-based detections
|
|
@@ -63,7 +61,6 @@ Notice that the `url` parameter is not a plain string but it has to be a proper
|
|
|
63
61
|
|
|
64
62
|
By default, `document`-based detections use the `document` global, which means they can only be used if you have the whole page, you can't just test any random URL string.
|
|
65
63
|
|
|
66
|
-
|
|
67
64
|
```js
|
|
68
65
|
if (pageDetect.isOrganizationProfile()) {
|
|
69
66
|
alert('You’re on an organization profile, like https://github.com/babel')
|