@@ -3,7 +3,7 @@ import { getProfile } from "../../rest/profile.ts";
3
3
4
4
/** cached user ID */
5
5
let userId : string | undefined ;
6
- export async function getUserId ( ) {
6
+ export const getUserId = async ( ) : Promise < string > => {
7
7
if ( userId !== undefined ) return userId ;
8
8
9
9
const user = await getProfile ( ) ;
@@ -12,11 +12,11 @@ export async function getUserId() {
12
12
}
13
13
userId = user . id ;
14
14
return userId ;
15
- }
15
+ } ;
16
16
17
17
/** cached pairs of project name and project id */
18
18
const projectMap = new Map < string , string > ( ) ;
19
- export async function getProjectId ( project : string ) {
19
+ export const getProjectId = async ( project : string ) : Promise < string > => {
20
20
const cachedId = projectMap . get ( project ) ;
21
21
if ( cachedId !== undefined ) return cachedId ;
22
22
@@ -28,22 +28,18 @@ export async function getProjectId(project: string) {
28
28
const { id } = result . value ;
29
29
projectMap . set ( project , id ) ;
30
30
return id ;
31
- }
31
+ } ;
32
32
33
- function zero ( n : string ) {
34
- return n . padStart ( 8 , "0" ) ;
35
- }
33
+ const zero = ( n : string ) => n . padStart ( 8 , "0" ) ;
36
34
37
- export function createNewLineId ( userId : string ) {
35
+ export const createNewLineId = ( userId : string ) : string => {
38
36
const time = Math . floor ( new Date ( ) . getTime ( ) / 1000 ) . toString ( 16 ) ;
39
37
const rand = Math . floor ( 0xFFFFFE * Math . random ( ) ) . toString ( 16 ) ;
40
38
return `${ zero ( time ) . slice ( - 8 ) } ${ userId . slice ( - 6 ) } 0000${ zero ( rand ) } ` ;
41
- }
42
- export function getUnixTimeFromId ( id : string ) {
39
+ } ;
40
+ export const getUnixTimeFromId = ( id : string ) : number => {
43
41
if ( ! isId ( id ) ) throw SyntaxError ( `"${ id } " is an invalid id.` ) ;
44
42
45
43
return parseInt ( `0x${ id . slice ( 0 , 8 ) } ` , 16 ) ;
46
- }
47
- export function isId ( id : string ) {
48
- return / ^ [ a - f \d ] { 24 , 32 } $ / . test ( id ) ;
49
- }
44
+ } ;
45
+ export const isId = ( id : string ) : boolean => / ^ [ a - f \d ] { 24 , 32 } $ / . test ( id ) ;
0 commit comments