Options
All
  • Public
  • Public/Protected
  • All
Menu

Module src/common/utils

Index

Type aliases

InternalFlarumRequestOptions

InternalFlarumRequestOptions<ResponseType>: Mithril.RequestOptions<ResponseType> & { url: string }

Type parameters

  • ResponseType

Properties

default

default: { handlers: Record<string, unknown>; getHandlers: any; off: any; on: any; one: any; trigger: any }

Type declaration

  • handlers: Record<string, unknown>
  • getHandlers:function
  • off:function
    • off(event: string, handler: Function): void
    • Unregister an event handler.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • handler: Function

        The function that handles the event.

      Returns void

  • on:function
    • on(event: string, handler: Function): void
    • Register an event handler.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • handler: Function

        The function to handle the event.

      Returns void

  • one:function
    • one(event: string, handler: Function): void
    • Register an event handler so that it will run only once, and then unregister itself.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • handler: Function

        The function to handle the event.

      Returns void

  • trigger:function
    • trigger(event: string, ...args: any[]): void
    • Trigger an event.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • Rest ...args: any[]

        Arguments to pass to event handlers.

      Returns void

default

default: (key: string, cb: Function) => () => void

Type declaration

Functions

abbreviateNumber

  • abbreviateNumber(number: number): string
  • The abbreviateNumber utility converts a number to a shorter localized form.

    example

    abbreviateNumber(1234); // "1.2K"

    Parameters

    • number: number

    Returns string

anchorScroll

  • The anchorScroll utility saves the scroll position relative to an element, and then restores it after a callback has been run.

    This is useful if a redraw will change the page's content above the viewport. Normally doing this will result in the content in the viewport being pushed down or pulled up. By wrapping the redraw with this utility, the scroll position can be anchor to an element that is in or below the viewport, so the content in the viewport will stay the same.

    Parameters

    • element: string | HTMLElement | Element | SVGElement

      The element to anchor the scroll position to.

    • callback: () => void

      The callback to run that will change page content.

        • (): void
        • Returns void

    Returns void

bidi

  • bidi(node: any, prop: any): any

Const classList

  • classList(...classes: ClassValue[]): string

computed

  • computed<T, M>(...args: [...string[], (...args: unknown[]) => T]): () => T
  • The computed utility creates a function that will cache its output until any of the dependent values are dirty.

    Type parameters

    Parameters

    • Rest ...args: [...string[], (...args: unknown[]) => T]

    Returns () => T

      • (): T
      • The computed utility creates a function that will cache its output until any of the dependent values are dirty.

        Returns T

createFocusTrap

escapeRegExp

  • escapeRegExp(input: string): string

extract

  • extract<T, K>(object: T, property: K): T[K]
  • The extract utility deletes a property from an object and returns its value.

    Type parameters

    • T

    • K: string | number | symbol

    Parameters

    • object: T

      The object that owns the property

    • property: K

      The name of the property to extract

    Returns T[K]

    The value of the property

extractText

  • extractText(vdom: Children): string

formatNumber

  • formatNumber(number: number, locale?: string): string
  • The formatNumber utility localizes a number into a string with the appropriate punctuation based on the provided locale otherwise will default to the users locale.

    example

    formatNumber(1234); // 1,234

    Parameters

    • number: number
    • locale: string = app.data.locale

    Returns string

getPlainContent

  • getPlainContent(string: string): string
  • Strip HTML tags and quotes out of the given string, replacing them with meaningful punctuation.

    Parameters

    • string: string

    Returns string

humanTime

  • humanTime(time: undefined | null | string | number | Date | Dayjs): string
  • The humanTime utility converts a date to a localized, human-readable time- ago string.

    Parameters

    • time: undefined | null | string | number | Date | Dayjs

    Returns string

insertText

isObject

  • isObject(obj: unknown): obj is object

liveHumanTimes

  • liveHumanTimes(): void

mapRoutes

mixin

  • mixin(Parent: object, ...mixins: Record<string, any>[]): object
  • The mixin utility assigns the properties of a set of 'mixin' objects to the prototype of a parent object.

    example

    class MyClass extends mixin(ExistingClass, evented, etc) {}

    Parameters

    • Parent: object

      The class to extend the new class from.

    • Rest ...mixins: Record<string, any>[]

      The objects to mix in.

    Returns object

    A new class that extends Parent and contains the mixins.

patchMithril

  • patchMithril(global: any): void

proxifyCompat

  • proxifyCompat(compat: Record<string, unknown>, namespace: string): Record<string, unknown>

setRouteWithForcedRefresh

  • setRouteWithForcedRefresh(route: string, params?: null, options?: RouteOptions): void

slug

  • slug(string: string): string
  • Create a slug out of the given string. Non-alphanumeric characters are converted to hyphens.

    NOTE: This method does not use the comparably sophisticated transliteration mechanism that is employed in the backend. Therefore, it should only be used to suggest slugs that can be overridden by the user.

    Parameters

    • string: string

    Returns string

stringToColor

  • stringToColor(string: string): string

styleSelectedText

subclassOf

  • subclassOf(A: any, B: any): any

truncate

  • truncate(string: string, length: number, start?: number): string
  • Truncate a string to the given length, appending ellipses if necessary.

    Parameters

    • string: string
    • length: number
    • start: number = 0

    Returns string

ucfirst

  • ucfirst(string: string): string

Type literals

__type

__type

handlers

handlers: Record<string, unknown> = null

Protected getHandlers

off

  • off(event: string, handler: Function): void
  • Unregister an event handler.

    deprecated

    Parameters

    • event: string

      The name of the event.

    • handler: Function

      The function that handles the event.

    Returns void

on

  • on(event: string, handler: Function): void
  • Register an event handler.

    deprecated

    Parameters

    • event: string

      The name of the event.

    • handler: Function

      The function to handle the event.

    Returns void

one

  • one(event: string, handler: Function): void
  • Register an event handler so that it will run only once, and then unregister itself.

    deprecated

    Parameters

    • event: string

      The name of the event.

    • handler: Function

      The function to handle the event.

    Returns void

trigger

  • trigger(event: string, ...args: any[]): void
  • Trigger an event.

    deprecated

    Parameters

    • event: string

      The name of the event.

    • Rest ...args: any[]

      Arguments to pass to event handlers.

    Returns void

__type

  • __type(key: string, cb: Function): () => void

Generated using TypeDoc version 0.22.10