Skip to content

Commit 757d4c2

Browse files
committed
Fix utils export
1 parent 12e2597 commit 757d4c2

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

source/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import reservedNames from 'github-reserved-names/reserved-names.json';
2-
import {getUsername, getCleanPathname, getRepoPath} from './utils';
32
import collect from './collector';
4-
export * as utils from './utils';
53

64
const exists = (selector: string) => Boolean(document.querySelector(selector));
75

@@ -397,3 +395,25 @@ collect.set('isActionJobRun', [
397395
'https://github.com/sindresorhus/refined-github/runs/639481849',
398396
]);
399397

398+
const getUsername = () => document.querySelector('meta[name="user-login"]')!.getAttribute('content')!;
399+
400+
// Drops leading and trailing slash to avoid /\/?/ everywhere
401+
const getCleanPathname = (url: URL | Location = location): string => url.pathname.replace(/^\/|\/$/g, '');
402+
403+
// Parses a repo's subpage, e.g.
404+
// '/user/repo/issues/' -> 'issues'
405+
// '/user/repo/' -> ''
406+
// returns undefined if the path is not a repo
407+
const getRepoPath = (url: URL | Location = location): string | undefined => {
408+
if (isRepo(url)) {
409+
return getCleanPathname(url).split('/').slice(2).join('/');
410+
}
411+
412+
return undefined;
413+
};
414+
415+
export const utils = {
416+
getUsername,
417+
getCleanPathname,
418+
getRepoPath,
419+
};

source/utils.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)