Options
All
  • Public
  • Public/Protected
  • All
Menu

@vjscc/utils

Index

Type aliases

AnimationFnOptions: { callback?: AnyFunction; duration?: number; timingFunction?: TimingFunction }

Type declaration

AnyFunction: (...args: any[]) => any

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

FadeFnOptions: AnimationFnOptions & { endDisplay?: string; endOpacity?: number; startDisplay?: string; startOpacity?: number }
StringOrHTMLElement: string | HTMLElement
TimingFunction: (x: number) => number

Type declaration

    • (x: number): number
    • Parameters

      • x: number

      Returns number

Functions

  • cancelRAF(id: number): void
  • Cancel raf by id.

    Parameters

    • id: number

      Raf id created by raf.

    Returns void

  • convertNumberToMoney(number: string | number, fractionDigits?: number): string
  • Convert number to money with thousand mark.

    Parameters

    • number: string | number

      Money number.

    • fractionDigits: number = 2

      Decimal digits.

    Returns string

    Money with thousand mark.

  • createRAF(callback: AnyFunction, delayFrames?: number): number
  • Use RAF to do somthing. When there's no left frames, exec callback function.

    Parameters

    • callback: AnyFunction

      Callback when animation is over.

    • delayFrames: number = 1

      Frames before fn executing.

    Returns number

    Return id of this RAF.

  • createRandomInteger(range: number): number
  • Generator a random number in [0, range].

    Parameters

    • range: number

      Max number of random number, round down.

    Returns number

    Random integer.

  • createRandomString(length: number): string
  • Generaotr random string.

    Parameters

    • length: number

      Length of string.

    Returns string

    Random string.

  • createRandomStringWidthDivider(format?: string, divdier?: string): string
  • Generaotr random string with dividers.

    Parameters

    • format: string = 'xxxx-xxxx-xxxx'

      Format of string.

    • divdier: string = '-'

      Divider of string chunks.

    Returns string

    Random String with dividers.

  • debounce<T>(fn: T, delay: number): (this: ThisParameterType<T>, ...args: Parameters<T>) => void
  • Get function with debounce.

    Type parameters

    Parameters

    • fn: T

      Function need to be debounce.

    • delay: number

      Delay time before excuting.

    Returns (this: ThisParameterType<T>, ...args: Parameters<T>) => void

    Function with debounce.

      • (this: ThisParameterType<T>, ...args: Parameters<T>): void
      • Get function with debounce.

        Parameters

        • this: ThisParameterType<T>
        • Rest ...args: Parameters<T>

        Returns void

        Function with debounce.

  • easeInBack(x: number): number
  • easeInBounce(x: number): number
  • easeInCirc(x: number): number
  • easeInCubic(x: number): number
  • easeInElastic(x: number): number
  • easeInExpo(x: number): number
  • easeInOutBack(x: number): number
  • easeInOutBounce(x: number): number
  • easeInOutCirc(x: number): number
  • easeInOutCubic(x: number): number
  • easeInOutElastic(x: number): number
  • easeInOutExpo(x: number): number
  • easeInOutQuad(x: number): number
  • easeInOutQuart(x: number): number
  • easeInOutQuint(x: number): number
  • easeInOutSine(x: number): number
  • easeInQuad(x: number): number
  • easeInQuart(x: number): number
  • easeInQuint(x: number): number
  • easeInSine(x: number): number
  • easeOutBack(x: number): number
  • easeOutBounce(x: number): number
  • easeOutCirc(x: number): number
  • easeOutCubic(x: number): number
  • easeOutElastic(x: number): number
  • easeOutExpo(x: number): number
  • easeOutQuad(x: number): number
  • easeOutQuart(x: number): number
  • easeOutQuint(x: number): number
  • easeOutSine(x: number): number
  • getBase64(file: File): Promise<FileReader["result"] | ProgressEvent<FileReader>>
  • Convert file to base64 by FileReader.

    Parameters

    • file: File

      File object.

    Returns Promise<FileReader["result"] | ProgressEvent<FileReader>>

    Promise of result.

  • getElementViaStringOrHTMLElement(stringOrHTMLElement: StringOrHTMLElement, container?: HTMLElement | Document): HTMLElement | null
  • Get element via string or HTMLElement.

    Parameters

    • stringOrHTMLElement: StringOrHTMLElement

      String or HTMLElement.

    • container: HTMLElement | Document = document

      Where to find, default is document.

    Returns HTMLElement | null

    HTMLElement or null if not found or fail.

  • isArray(value: unknown): value is any[]
  • Checks if value is an array.

    Parameters

    • value: unknown

      The value to check.

    Returns value is any[]

    true if the argument appears to be an array.

  • isBigInt(value: unknown): value is bigint
  • Checks if value is a BigInt.

    Parameters

    • value: unknown

      The value to check.

    Returns value is bigint

    true if the argument appears to be a BigInt.

  • isBoolean(value: unknown): value is boolean
  • Checks if value is a boolean.

    Parameters

    • value: unknown

      The value to check.

    Returns value is boolean

    true if value is a boolean, otherwise false.

  • Checks if value is classified as a Function object.

    Parameters

    • value: unknown

      The value to check.

    Returns value is AnyFunction

    true if value is a function, otherwise false.

  • isHTMLElement(value: unknown): value is HTMLElement
  • Check if value is a HTML element.

    Parameters

    • value: unknown

      The value to check.

    Returns value is HTMLElement

    True if it is, false if it isn't.

  • isHTMLElementOrDocument(value: unknown): value is HTMLElement | Document
  • Check if value is a HTML element or document.

    Parameters

    • value: unknown

      The value to check.

    Returns value is HTMLElement | Document

    true if it is, otherwise false.

  • isNull(value: unknown): value is null
  • Checks if value is null.

    Parameters

    • value: unknown

      The value to check.

    Returns value is null

    true if the argument appears to be null.

  • isNumber(value: unknown): value is number
  • Checks if value is a number.

    Parameters

    • value: unknown

      The value to check.

    Returns value is number

    true if value is a number, otherwise false.

  • isObject(value: unknown): value is Record<string, unknown>
  • Checks if value is a object.

    Parameters

    • value: unknown

      The value to check.

    Returns value is Record<string, unknown>

    true if the argument appears to be a object.

  • isPlainObject(value: unknown): value is Record<string, unknown>
  • Checks if value is a plain object.

    Parameters

    • value: unknown

      The value to check.

    Returns value is Record<string, unknown>

    true if the argument appears to be a plain object.

  • isString(value: unknown): value is string
  • Checks if value is a string.

    Parameters

    • value: unknown

      The value to check.

    Returns value is string

    true if value is a string, otherwise false.

  • Check if value is a string or HTMLELement.

    Parameters

    • value: unknown

      Target value to check.

    Returns value is StringOrHTMLElement

    True if it is string or HTMLELement, false otherwise.

  • isSymbol(value: unknown): value is symbol
  • Checks if value is a symbol.

    Parameters

    • value: unknown

      The value to check.

    Returns value is symbol

    true if the argument appears to be a symbol.

  • isUndefined(value: unknown): value is undefined
  • Checks if value is undefined.

    Parameters

    • value: unknown

      The value to check.

    Returns value is undefined

    true if the argument appears to be undefined.

  • isWindow(value: unknown): boolean
  • Check if value is window.

    Parameters

    • value: unknown

      The value to check.

    Returns boolean

    true if it's window, otherwise return false.

  • linear(x: number): number
  • swing(x: number): number
  • throttle<T>(fn: T, interval: number): (this: ThisParameterType<T>, ...args: Parameters<T>) => void
  • Get function with throttle.

    Type parameters

    Parameters

    • fn: T

      Function need to be throttle.

    • interval: number

      Interval time before each excuting.

    Returns (this: ThisParameterType<T>, ...args: Parameters<T>) => void

    Function with throttle.

      • (this: ThisParameterType<T>, ...args: Parameters<T>): void
      • Get function with throttle.

        Parameters

        • this: ThisParameterType<T>
        • Rest ...args: Parameters<T>

        Returns void

        Function with throttle.

  • useTimingFunction(currentTime: number, duration: number, startValue: number, targetValue: number, fn?: TimingFunction): number
  • Use timing function to calculate value in progress.

    Parameters

    • currentTime: number

      Current time.

    • duration: number

      Duration.

    • startValue: number

      Start value.

    • targetValue: number

      Target value.

    • fn: TimingFunction = linear

      Timing function.

    Returns number

    Current value.

Generated using TypeDoc