Options
All
  • Public
  • Public/Protected
  • All
Menu

Module src/utils

the module containing utilities functions used across the whole project

Index

References

CancelablePromise

Re-exports CancelablePromise

GeneratedError

Re-exports GeneratedError

blockUnion

Re-exports blockUnion

calcOverlap

Re-exports calcOverlap

cancelablePromise

Re-exports cancelablePromise

errToStr

Re-exports errToStr

getReleaseNote

Re-exports getReleaseNote

hashCode

Re-exports hashCode

highlightMatch

Re-exports highlightMatch

hr12toInt

Re-exports hr12toInt

hr24toInt

Re-exports hr24toInt

intTo24hr

Re-exports intTo24hr

isNumberArray

Re-exports isNumberArray

isStringArray

Re-exports isStringArray

parseDate

Re-exports parseDate

parseTimeAll

Re-exports parseTimeAll

savePlain

Re-exports savePlain

timeout

Re-exports timeout

to12hr

Re-exports to12hr

to24hr

Re-exports to24hr

toICal

Re-exports toICal

Type aliases

Cancel

Cancel: (msg: any) => void

Type declaration

    • (msg: any): void
    • Parameters

      • msg: any

      Returns void

Functions

blockUnion

  • blockUnion(a: number, b: number, c: number, d: number): [number, number] | undefined
  • return the union of the blocks [a, b] and [c, d]

    author

    Hanzhi Zhou

    Parameters

    • a: number
    • b: number
    • c: number
    • d: number

    Returns [number, number] | undefined

calcOverlap

  • calcOverlap(a: number, b: number, c: number, d: number): number
  • calculate the overlap between time block [a, b] and [c, d].

    author

    Hanzhi Zhou

    Parameters

    • a: number
    • b: number
    • c: number
    • d: number

    Returns number

    • 0 if only end points touch
    • -1 if no overlap
    • the area of overlapping region if overlap

calcStartDate

  • calcStartDate(prevStart: Date, day: Day): Date

cancelablePromise

dateToICalString

  • dateToICalString(date: Date): string

errToStr

  • errToStr(err: string | AxiosError): string
  • convert an (axios request) error to string message

    author

    Hanzhi Zhou

    Parameters

    • err: string | AxiosError

    Returns string

getReleaseNote

  • getReleaseNote(): Promise<string>
  • Get release note for current version && render. Part of this function can be seen as an extremely-lightweight MarkDown renderer.

    author

    Kaiying Shan

    Returns Promise<string>

hashCode

  • hashCode(str: string): number

highlightMatch

  • highlightMatch<T>(str: string, expMatch: T, matches?: readonly Match<T>[]): string
  • highlight a matched part of a short string given that match is not undefined and match.match === expMatch

    author

    Hanzhi Zhou

    Type parameters

    • T: string

    Parameters

    • str: string

      the string to inject highlight

    • expMatch: T

      the expected matched field in match.match

    • Optional matches: readonly Match<T>[]

      an array of match objects, sorted in numeric order of their start property

    Returns string

hr12toInt

  • hr12toInt(time: string): number
  • convert 1:00AM style time to minutes starting from 00:00

    Parameters

    • time: string

    Returns number

hr24toInt

  • hr24toInt(time: string): number
  • convert 13:00 style time to minutes starting from 00:00

    Parameters

    • time: string

    Returns number

intTo24hr

  • intTo24hr(num: number): string

isNumberArray

  • isNumberArray(x: any): x is number[]

isStringArray

  • isStringArray(x: any): x is string[]

parseDate

  • parseDate(date: string): [number, number] | undefined
  • parse 08/27/2019 - 12/17/2019 style dates to a tuple of numbers

    Parameters

    • date: string

    Returns [number, number] | undefined

parseTimeAll

  • parseTimeAll(time: string): [Day[], [number, number]] | null
  • author

    Hanzhi Zhou

    Parameters

    • time: string

    Returns [Day[], [number, number]] | null

    null when fail to parse

    Example usage and return value:

    parseTimeAll('MoWeFr 10:00AM - 11:00AM') => [['Mo', 'We', 'Fr'], [600, 660]]
    

savePlain

  • savePlain(str: string, filename: string): void
  • save a string a as text file

    author

    Hanzhi Zhou

    Parameters

    • str: string

      the string to save as a file

    • filename: string

    Returns void

timeout

  • timeout<T>(promise: Promise<T>, time: number, msg?: string): Promise<T>
  • Apply timeout on a promise

    author

    Hanzhi Zhou

    Type parameters

    • T

    Parameters

    • promise: Promise<T>

      the promise to apply the timeout on

    • time: number

      time in millisecond

    • Default value msg: string = "Time out fetching data. Please try again later"

      the error message on time out

    Returns Promise<T>

to12hr

  • to12hr(time: string): string
  • convert 24 hour format time to 12 hour format.

    author

    Kaiying Shan

    Parameters

    • time: string

      the time in 24 hour format

      Example usage and return value:

      to12hr('17:00') => '5:00PM'
      

    Returns string

to24hr

  • to24hr(time: string): string
  • convert 12 hr to 24 hr

    author

    Hanzhi Zhou

    Parameters

    • time: string

      Example usage and return value:

      to12hr('5:00PM') => '17:00'
      

    Returns string

toICal

toICalEventString

  • toICalEventString(event: Event | Meeting, uid: string, startDate: Date, until: Date, summary: string, description: string, location: string): string
  • Parameters

    • event: Event | Meeting
    • uid: string
    • startDate: Date
    • until: Date
    • summary: string
    • description: string
    • location: string

    Returns string

Generated using TypeDoc