File tree Expand file tree Collapse file tree 2 files changed +22
-22
lines changed
Expand file tree Collapse file tree 2 files changed +22
-22
lines changed Original file line number Diff line number Diff line change 11import reservedNames from 'github-reserved-names/reserved-names.json' ;
2- import { getUsername , getCleanPathname , getRepoPath } from './utils' ;
32import collect from './collector' ;
4- export * as utils from './utils' ;
53
64const 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+ } ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments