github-url-detection 9.0.0 → 9.0.1

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.
@@ -121,11 +121,14 @@ export declare const isUserTheOrganizationOwner: () => boolean;
121
121
  export declare const canUserEditRepo: () => boolean;
122
122
  export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
123
123
  export declare const isNewRepoTemplate: (url?: URL | HTMLAnchorElement | Location) => boolean;
124
+ export type NameWithOwner = `${string}/${string}`;
124
125
  export type RepositoryInfo = {
126
+ /** The repo owner/user */
125
127
  owner: string;
128
+ /** The repo name */
126
129
  name: string;
127
130
  /** The 'user/repo' part from an URL */
128
- nameWithOwner: string;
131
+ nameWithOwner: NameWithOwner;
129
132
  /** A repo's subpage
130
133
  @example '/user/repo/issues/' -> 'issues'
131
134
  @example '/user/repo/' -> ''
@@ -137,7 +140,9 @@ export declare const utils: {
137
140
  name: string;
138
141
  path: string;
139
142
  } | undefined;
143
+ /** @deprecated Use `getLoggedInUser` */
140
144
  getUsername: () => string | undefined;
145
+ getLoggedInUser: () => string | undefined;
141
146
  getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string;
142
147
  getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined;
143
148
  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";
@@ -64,7 +64,13 @@ var isEditingRelease = (url = location) => Boolean(getRepo(url)?.path.startsWith
64
64
  var hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
65
65
  var isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
66
66
  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);
67
+ var isRepo = (url = location) => {
68
+ const [user, repo, extra] = getCleanPathname(url).split("/");
69
+ return Boolean(
70
+ user && repo && !reservedNames.includes(user) && !url.hostname.startsWith("gist.") && extra !== "generate"
71
+ // Like isNewRepoTemplate but inlined for performance
72
+ );
73
+ };
68
74
  var hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url);
69
75
  var isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
70
76
  var isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
@@ -136,8 +142,8 @@ var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-
136
142
  var canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
137
143
  var isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
138
144
  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);
145
+ var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
146
+ var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/\/+/g, "/").replace(/\/$/, "").slice(1);
141
147
  var getCleanGistPathname = (url = location) => {
142
148
  const pathname = getCleanPathname(url);
143
149
  if (url.hostname.startsWith("gist.")) {
@@ -147,7 +153,7 @@ var getCleanGistPathname = (url = location) => {
147
153
  return gist === "gist" ? parts.join("/") : void 0;
148
154
  };
149
155
  var getOrg = (url = location) => {
150
- const [, orgs, name, ...path] = url.pathname.split("/");
156
+ const [orgs, name, ...path] = getCleanPathname(url).split("/");
151
157
  if (orgs === "orgs" && name) {
152
158
  return { name, path: path.join("/") };
153
159
  }
@@ -173,13 +179,15 @@ var getRepo = (url) => {
173
179
  return {
174
180
  owner,
175
181
  name,
176
- nameWithOwner: owner + "/" + name,
182
+ nameWithOwner: `${owner}/${name}`,
177
183
  path: path.join("/")
178
184
  };
179
185
  };
180
186
  var utils = {
181
187
  getOrg,
182
- getUsername,
188
+ /** @deprecated Use `getLoggedInUser` */
189
+ getUsername: getLoggedInUser,
190
+ getLoggedInUser,
183
191
  getCleanPathname,
184
192
  getCleanGistPathname,
185
193
  getRepositoryInfo: getRepo
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.1",
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"