github-url-detection 9.0.0 → 9.0.2

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.
@@ -118,14 +118,19 @@ export declare const isActionRun: (url?: URL | HTMLAnchorElement | Location) =>
118
118
  export declare const isNewAction: (url?: URL | HTMLAnchorElement | Location) => boolean;
119
119
  export declare const isRepositoryActions: (url?: URL | HTMLAnchorElement | Location) => boolean;
120
120
  export declare const isUserTheOrganizationOwner: () => boolean;
121
+ export declare const canUserAdminRepo: () => boolean;
122
+ /** @deprecated Use `canUserAdminRepo` */
121
123
  export declare const canUserEditRepo: () => boolean;
122
124
  export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
123
125
  export declare const isNewRepoTemplate: (url?: URL | HTMLAnchorElement | Location) => boolean;
126
+ export type NameWithOwner = `${string}/${string}`;
124
127
  export type RepositoryInfo = {
128
+ /** The repo owner/user */
125
129
  owner: string;
130
+ /** The repo name */
126
131
  name: string;
127
132
  /** The 'user/repo' part from an URL */
128
- nameWithOwner: string;
133
+ nameWithOwner: NameWithOwner;
129
134
  /** A repo's subpage
130
135
  @example '/user/repo/issues/' -> 'issues'
131
136
  @example '/user/repo/' -> ''
@@ -137,7 +142,9 @@ export declare const utils: {
137
142
  name: string;
138
143
  path: string;
139
144
  } | undefined;
145
+ /** @deprecated Use `getLoggedInUser` */
140
146
  getUsername: () => string | undefined;
147
+ getLoggedInUser: () => string | undefined;
141
148
  getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string;
142
149
  getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined;
143
150
  getRepositoryInfo: (url?: URL | HTMLAnchorElement | Location | string) => RepositoryInfo | undefined;
@@ -31,7 +31,7 @@ var isNotifications = (url = location) => getCleanPathname(url) === "notificatio
31
31
  var isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
32
32
  var isOrganizationRepo = () => exists('.AppHeader-context-full [data-hovercard-type="organization"]');
33
33
  var isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams"));
34
- var isOwnUserProfile = () => getCleanPathname() === getUsername();
34
+ var isOwnUserProfile = () => getCleanPathname() === getLoggedInUser();
35
35
  var isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
36
36
  var isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path);
37
37
  var isProjects = (url = location) => getRepo(url)?.path === "projects";
@@ -48,10 +48,23 @@ var isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path
48
48
  var isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path);
49
49
  var isPRFiles = (url = location) => /^pull\/\d+\/files/.test(getRepo(url)?.path) || isPRCommit(url);
50
50
  var isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);
51
- var isDraftPR = () => exists("#partial-discussion-header .octicon-git-pull-request-draft");
52
- var isOpenPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)");
53
- var isMergedPR = () => exists("#partial-discussion-header .octicon-git-merge");
54
- var isClosedPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)");
51
+ var prStateSelector = [
52
+ ".State",
53
+ '[class^="StateLabel"]'
54
+ ].join(",");
55
+ var isDraftPR = () => $(prStateSelector).textContent.trim() === "Draft";
56
+ var isOpenPR = () => {
57
+ const status = $(prStateSelector).textContent.trim();
58
+ return status === "Open" || status === "Draft";
59
+ };
60
+ var isMergedPR = () => {
61
+ const status = $(prStateSelector).textContent.trim();
62
+ return status === "Merged";
63
+ };
64
+ var isClosedPR = () => {
65
+ const status = $(prStateSelector).textContent.trim();
66
+ return status === "Closed" || status === "Merged";
67
+ };
55
68
  var isClosedIssue = () => exists("#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)");
56
69
  var isReleases = (url = location) => getRepo(url)?.path === "releases";
57
70
  var isTags = (url = location) => getRepo(url)?.path === "tags";
@@ -64,7 +77,13 @@ var isEditingRelease = (url = location) => Boolean(getRepo(url)?.path.startsWith
64
77
  var hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
65
78
  var isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
66
79
  var hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);
67
- var isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isNewRepoTemplate(url);
80
+ var isRepo = (url = location) => {
81
+ const [user, repo, extra] = getCleanPathname(url).split("/");
82
+ return Boolean(
83
+ user && repo && !reservedNames.includes(user) && !url.hostname.startsWith("gist.") && extra !== "generate"
84
+ // Like isNewRepoTemplate but inlined for performance
85
+ );
86
+ };
68
87
  var hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url);
69
88
  var isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
70
89
  var isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
@@ -133,11 +152,12 @@ var isActionRun = (url = location) => /^(actions\/)?runs/.test(getRepo(url)?.pat
133
152
  var isNewAction = (url = location) => getRepo(url)?.path === "actions/new";
134
153
  var isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path);
135
154
  var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
136
- var canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
155
+ var canUserAdminRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
156
+ var canUserEditRepo = canUserAdminRepo;
137
157
  var isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
138
158
  var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
139
- var getUsername = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
140
- var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);
159
+ var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
160
+ var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/\/+/g, "/").replace(/\/$/, "").slice(1);
141
161
  var getCleanGistPathname = (url = location) => {
142
162
  const pathname = getCleanPathname(url);
143
163
  if (url.hostname.startsWith("gist.")) {
@@ -147,7 +167,7 @@ var getCleanGistPathname = (url = location) => {
147
167
  return gist === "gist" ? parts.join("/") : void 0;
148
168
  };
149
169
  var getOrg = (url = location) => {
150
- const [, orgs, name, ...path] = url.pathname.split("/");
170
+ const [orgs, name, ...path] = getCleanPathname(url).split("/");
151
171
  if (orgs === "orgs" && name) {
152
172
  return { name, path: path.join("/") };
153
173
  }
@@ -173,18 +193,21 @@ var getRepo = (url) => {
173
193
  return {
174
194
  owner,
175
195
  name,
176
- nameWithOwner: owner + "/" + name,
196
+ nameWithOwner: `${owner}/${name}`,
177
197
  path: path.join("/")
178
198
  };
179
199
  };
180
200
  var utils = {
181
201
  getOrg,
182
- getUsername,
202
+ /** @deprecated Use `getLoggedInUser` */
203
+ getUsername: getLoggedInUser,
204
+ getLoggedInUser,
183
205
  getCleanPathname,
184
206
  getCleanGistPathname,
185
207
  getRepositoryInfo: getRepo
186
208
  };
187
209
  export {
210
+ canUserAdminRepo,
188
211
  canUserEditRepo,
189
212
  hasCode,
190
213
  hasComments,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-url-detection",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
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",
@@ -57,20 +57,20 @@
57
57
  ]
58
58
  },
59
59
  "dependencies": {
60
- "github-reserved-names": "^2.0.5"
60
+ "github-reserved-names": "^2.0.7"
61
61
  },
62
62
  "devDependencies": {
63
- "@sindresorhus/tsconfig": "^5.0.0",
63
+ "@sindresorhus/tsconfig": "^6.0.0",
64
64
  "@sveltejs/vite-plugin-svelte": "^3.1.1",
65
- "esbuild": "^0.21.5",
65
+ "esbuild": "^0.23.1",
66
66
  "npm-run-all": "^4.1.5",
67
67
  "strip-indent": "^4.0.0",
68
- "svelte": "^4.2.17",
69
- "svelte-check": "^3.8.0",
70
- "typescript": "^5.4.5",
71
- "vite": "^5.2.12",
72
- "vitest": "^1.6.0",
73
- "xo": "^0.58.0"
68
+ "svelte": "^4.2.18",
69
+ "svelte-check": "^3.8.5",
70
+ "typescript": "^5.5.4",
71
+ "vite": "^5.4.2",
72
+ "vitest": "^2.0.5",
73
+ "xo": "^0.59.3"
74
74
  },
75
75
  "engines": {
76
76
  "node": ">=20.10"