summaryrefslogtreecommitdiff
path: root/source/libs/utils.ts
diff options
context:
space:
mode:
authorGravatar Nick Taylor <nick@iamdeveloper.com> 2019-04-21 01:48:07 -0400
committerGravatar Federico Brigante <github@bfred.it> 2019-04-21 13:48:07 +0800
commit9cdb7b377fef47e621a0a0cf5c1df321f1060605 (patch)
treec4c7eea04da66d38ebbf0b8509e4cd2a17c34023 /source/libs/utils.ts
parentdea7e47bcf61640f4dee9e195fed0ad1ae938781 (diff)
downloadrefined-github-9cdb7b377fef47e621a0a0cf5c1df321f1060605.tar.gz
refined-github-9cdb7b377fef47e621a0a0cf5c1df321f1060605.tar.zst
refined-github-9cdb7b377fef47e621a0a0cf5c1df321f1060605.zip
Meta: Add explicit return types on all functions (#1943)
Co-authored-by: Federico Brigante <github@bfred.it>
Diffstat (limited to 'source/libs/utils.ts')
-rw-r--r--source/libs/utils.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/source/libs/utils.ts b/source/libs/utils.ts
index b4908bbb..a3dea51a 100644
--- a/source/libs/utils.ts
+++ b/source/libs/utils.ts
@@ -4,16 +4,16 @@ import {isRepo, isPR, isIssue} from './page-detect';
export const getUsername = onetime(() => select('meta[name="user-login"]')!.getAttribute('content')!);
-export const getDiscussionNumber = () => (isPR() || isIssue()) && getCleanPathname().split('/')[3];
+export const getDiscussionNumber = (): string | false => (isPR() || isIssue()) && getCleanPathname().split('/')[3];
// Drops leading and trailing slash to avoid /\/?/ everywhere
-export const getCleanPathname = () => location.pathname.replace(/^[/]|[/]$/g, '');
+export const getCleanPathname = (): string => location.pathname.replace(/^[/]|[/]$/g, '');
// Parses a repo's subpage, e.g.
// '/user/repo/issues/' -> 'issues'
// '/user/repo/' -> ''
// returns undefined if the path is not a repo
-export const getRepoPath = () => {
+export const getRepoPath = (): string | undefined => {
if (isRepo()) {
return getCleanPathname().split('/').slice(2).join('/');
}
@@ -21,7 +21,7 @@ export const getRepoPath = () => {
return undefined;
};
-export const getRepoBranch = () => {
+export const getRepoBranch = (): string | false => {
const [type, branch] = getCleanPathname().split('/').slice(2);
if (isRepo() && type === 'tree') {
return branch;
@@ -30,14 +30,17 @@ export const getRepoBranch = () => {
return false;
};
-export const getRepoURL = () => location.pathname.slice(1).split('/', 2).join('/');
+export const getRepoURL = (): string => location.pathname.slice(1).split('/', 2).join('/');
-export const getOwnerAndRepo = () => {
+export const getOwnerAndRepo = (): {
+ ownerName: string;
+ repoName: string;
+} => {
const [, ownerName, repoName] = location.pathname.split('/', 3);
return {ownerName, repoName};
};
-export const groupBy = (iterable: Iterable<string>, grouper: (item: string) => string) => {
+export const groupBy = (iterable: Iterable<string>, grouper: (item: string) => string): Record<string, string[]> => {
const map: Record<string, string[]> = {};
for (const item of iterable) {
@@ -52,7 +55,7 @@ export const groupBy = (iterable: Iterable<string>, grouper: (item: string) => s
// Concats arrays but does so like a zipper instead of appending them
// [[0, 1, 2], [0, 1]] => [0, 0, 1, 1, 2]
// Like lodash.zip
-export const flatZip = <T>(table: T[][], limit = Infinity) => {
+export const flatZip = <T>(table: T[][], limit = Infinity): T[] => {
const maxColumns = Math.max(...table.map(row => row.length));
const zipped = [];
for (let col = 0; col < maxColumns; col++) {