@@ -3,7 +3,7 @@ import { getProfile } from "../../rest/profile.ts";
33
44/** cached user ID */
55let userId : string | undefined ;
6- export async function getUserId ( ) {
6+ export const getUserId = async ( ) : Promise < string > => {
77 if ( userId !== undefined ) return userId ;
88
99 const user = await getProfile ( ) ;
@@ -12,11 +12,11 @@ export async function getUserId() {
1212 }
1313 userId = user . id ;
1414 return userId ;
15- }
15+ } ;
1616
1717/** cached pairs of project name and project id */
1818const projectMap = new Map < string , string > ( ) ;
19- export async function getProjectId ( project : string ) {
19+ export const getProjectId = async ( project : string ) : Promise < string > => {
2020 const cachedId = projectMap . get ( project ) ;
2121 if ( cachedId !== undefined ) return cachedId ;
2222
@@ -28,22 +28,18 @@ export async function getProjectId(project: string) {
2828 const { id } = result . value ;
2929 projectMap . set ( project , id ) ;
3030 return id ;
31- }
31+ } ;
3232
33- function zero ( n : string ) {
34- return n . padStart ( 8 , "0" ) ;
35- }
33+ const zero = ( n : string ) => n . padStart ( 8 , "0" ) ;
3634
37- export function createNewLineId ( userId : string ) {
35+ export const createNewLineId = ( userId : string ) : string => {
3836 const time = Math . floor ( new Date ( ) . getTime ( ) / 1000 ) . toString ( 16 ) ;
3937 const rand = Math . floor ( 0xFFFFFE * Math . random ( ) ) . toString ( 16 ) ;
4038 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 => {
4341 if ( ! isId ( id ) ) throw SyntaxError ( `"${ id } " is an invalid id.` ) ;
4442
4543 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