forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
31 lines (27 loc) · 878 Bytes
/
common.ts
File metadata and controls
31 lines (27 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { findTarget, Gist } from "@api/gist"
import { exitWith } from "../util/process"
/**
* Validate the token from environment variables
*/
export function validateTokenFromEnv(): string {
const token = process.env.TIMER_USER_COUNT_GIST_TOKEN
if (!token) {
exitWith("Can't find token from env variable [TIMER_USER_COUNT_GIST_TOKEN]")
}
return token
}
/**
* Calculate the gist description of target browser
*/
export function descriptionOf(browser: Browser): string {
return `Timer_UserCount_4_${browser}`
}
/**
* Calculate the gist filename of target browser
*/
export function filenameOf(browser: Browser): string {
return descriptionOf(browser) + '.json'
}
export async function getExistGist(token: string, browser: Browser): Promise<Gist> {
return await findTarget(token, gist => gist.description === descriptionOf(browser))
}