-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcommon.ts
More file actions
38 lines (32 loc) · 1006 Bytes
/
common.ts
File metadata and controls
38 lines (32 loc) · 1006 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
32
33
34
35
36
37
38
import { findTarget, type Gist } from "@api/gist"
import { exitWith } from "../util/process"
export type Browser =
| 'chrome'
| 'firefox'
| 'edge'
export type UserCount = Record<string, number>
/**
* 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 | null> {
return await findTarget(token, gist => gist.description === descriptionOf(browser))
}