Reference Source

Function

Static Public Summary
public

abbreviateNumber(number: Integer): String

The abbreviateNumber utility converts a number to a shorter localized form.

public

affixSidebar(element: DOMElement, isInitialized: Boolean)

Setup the sidebar DOM element to be affixed to the top of the viewport using Bootstrap's affix plugin.

public

anchorScroll(element: DOMElement, callback: Function)

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

public

avatar(user: User, attrs: Object): Object

The avatar helper displays a user's avatar.

public

boot(app: ForumApp)

The boot initializer boots up the admin app.

public

boot(app: ForumApp)

The boot initializer boots up the forum app.

public

classList(classes: Object): String

The classList utility creates a list of class names by joining an object's keys, but only for values which are truthy.

public

The components initializer registers components to display the default post types, activity types, and notifications type with the application.

public

computed(dependentKeys: ...String, compute: function): Function

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

public

extend(object: Object, method: String, callback: function)

Extend an object's method by running its output through a mutating callback every time it is called.

The callback accepts the method's return value and should perform any mutations directly on this value.

public

extract(object: Object, property: String): *

The extract utility deletes a property from an object and returns its value.

public

extractText(vdom: VirtualElement): String

Extract the text nodes from a virtual element.

public

The formatNumber utility localizes a number into a string with the appropriate punctuation.

public

fullTime(time: Date): Object

The fullTime helper displays a formatted time string wrapped in a <time> tag.

public

Strip HTML tags and quotes out of the given string, replacing them with meaningful punctuation.

public

highlight(string: String, phrase: String | RegExp, length: Integer): Object

The highlight helper searches for a word phrase in a string, and wraps matches with the <mark> tag.

public

The humanTime utility converts a date to a localized, human-readable time- ago string.

public

The humanTime initializer sets up a loop every 1 second to update timestamps rendered with the humanTime helper.

public

The humanTime helper displays a time in a human-friendly time-ago format (e.g.

public

icon(name: String, attrs: Object): Object

The icon helper displays a FontAwesome icon.

public

listItems(items: Array): Array

The listItems helper wraps a collection of components in

  • tags, stripping out any unnecessary Separator components.
  • public

    mapRoutes(routes: Object, basePath: String): Object

    The mapRoutes utility converts a map of named application routes into a format that can be understood by Mithril.

    public

    mixin(Parent: Class, mixins: ...Object): Class

    The mixin utility assigns the properties of a set of 'mixin' objects to the prototype of a parent object.

    public

    override(object: Object, method: String, newMethod: function)

    Override an object's method by replacing it with a new function, so that the new function will be run every time the object's method is called.

    public

    patchMithril(global: *)

    public

    preload(app: App)

    The preload initializer creates the application session and preloads it with data that has been set on the application's preload property. It also preloads any data on the application's preload property into the store.

    public

    punctuate(items: Array): Array

    The punctuate helper formats a list of strings (e.g.

    public

    routes(app: App)

    The routes initializer defines the admin app's routes.

    public

    routes(app: App)

    The routes initializer defines the forum app's routes.

    public

    saveConfig(config: *): *

    public

    slidable(element: DOMElement): Object

    The slidable utility adds touch gestures to an element so that it can be slid away to reveal controls underneath, and then released to activate those controls.

    public

    slug(string: String): String

    Create a slug out of the given string.

    public

    store(app: App)

    The store initializer creates the application's data store and registers the default resource types to their models.

    public

    Convert the given string to a unique color.

    public

    truncate(string: String, length: Number, start: Number): String

    Truncate a string to the given length, appending ellipses if necessary.

    public

    ucfirst(string: String): String

    Make a string's first character uppercase.

    public

    username(user: User): Object

    The username helper displays a user's username in a tag. If the user doesn't exist, the username will be displayed as [deleted].

    Static Public

    public abbreviateNumber(number: Integer): String source

    import abbreviateNumber from 'flarum/utils/abbreviateNumber.js'

    The abbreviateNumber utility converts a number to a shorter localized form.

    Params:

    NameTypeAttributeDescription
    number Integer

    Return:

    String

    Example:

    abbreviateNumber(1234);
    // "1.2K"

    public affixSidebar(element: DOMElement, isInitialized: Boolean) source

    import affixSidebar from 'flarum/utils/affixSidebar.js'

    Setup the sidebar DOM element to be affixed to the top of the viewport using Bootstrap's affix plugin.

    Params:

    NameTypeAttributeDescription
    element DOMElement
    isInitialized Boolean

    public anchorScroll(element: DOMElement, callback: Function) source

    import anchorScroll from 'flarum/utils/anchorScroll.js'

    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.

    Params:

    NameTypeAttributeDescription
    element DOMElement

    The element to anchor the scroll position to.

    callback Function

    The callback to run that will change page content.

    public avatar(user: User, attrs: Object): Object source

    import avatar from 'flarum/helpers/avatar.js'

    The avatar helper displays a user's avatar.

    Params:

    NameTypeAttributeDescription
    user User
    attrs Object

    Attributes to apply to the avatar element

    Return:

    Object

    public boot(app: ForumApp) source

    import boot from 'flarum/initializers/boot.js'

    The boot initializer boots up the admin app. It initializes some app globals, mounts components to the page, and begins routing.

    Params:

    NameTypeAttributeDescription
    app ForumApp

    public boot(app: ForumApp) source

    import boot from 'flarum/initializers/boot.js'

    The boot initializer boots up the forum app. It initializes some app globals, mounts components to the page, and begins routing.

    Params:

    NameTypeAttributeDescription
    app ForumApp

    public classList(classes: Object): String source

    import classList from 'flarum/utils/classList.js'

    The classList utility creates a list of class names by joining an object's keys, but only for values which are truthy.

    Params:

    NameTypeAttributeDescription
    classes Object

    Return:

    String

    Example:

    classList({ foo: true, bar: false, qux: 'qaz' });
    // "foo qux"

    public components(app: ForumApp) source

    import components from 'flarum/initializers/components.js'

    The components initializer registers components to display the default post types, activity types, and notifications type with the application.

    Params:

    NameTypeAttributeDescription
    app ForumApp

    public computed(dependentKeys: ...String, compute: function): Function source

    import computed from 'flarum/utils/computed.js'

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

    Params:

    NameTypeAttributeDescription
    dependentKeys ...String

    The keys of the dependent values.

    compute function

    The function which computes the value using the dependent values.

    Return:

    Function

    public extend(object: Object, method: String, callback: function) source

    import {extend} from 'flarum/extend.js'

    Extend an object's method by running its output through a mutating callback every time it is called.

    The callback accepts the method's return value and should perform any mutations directly on this value. For this reason, this function will not be effective on methods which return scalar values (numbers, strings, booleans).

    Care should be taken to extend the correct object – in most cases, a class' prototype will be the desired target of extension, not the class itself.

    Params:

    NameTypeAttributeDescription
    object Object

    The object that owns the method

    method String

    The name of the method to extend

    callback function

    A callback which mutates the method's output

    Example:

    extend(Discussion.prototype, 'badges', function(badges) {
      // do something with `badges`
    });

    public extract(object: Object, property: String): * source

    import extract from 'flarum/utils/extract.js'

    The extract utility deletes a property from an object and returns its value.

    Params:

    NameTypeAttributeDescription
    object Object

    The object that owns the property

    property String

    The name of the property to extract

    Return:

    *

    The value of the property

    public extractText(vdom: VirtualElement): String source

    import extractText from 'flarum/utils/extractText.js'

    Extract the text nodes from a virtual element.

    Params:

    NameTypeAttributeDescription
    vdom VirtualElement

    Return:

    String

    public formatNumber(number: Number): String source

    import formatNumber from 'flarum/utils/formatNumber.js'

    The formatNumber utility localizes a number into a string with the appropriate punctuation.

    Params:

    NameTypeAttributeDescription
    number Number

    Return:

    String

    Example:

    formatNumber(1234);
    // 1,234

    public fullTime(time: Date): Object source

    import fullTime from 'flarum/helpers/fullTime.js'

    The fullTime helper displays a formatted time string wrapped in a <time> tag.

    Params:

    NameTypeAttributeDescription
    time Date

    Return:

    Object

    public getPlainContent(string: String): String source

    import {getPlainContent} from 'flarum/utils/string.js'

    Strip HTML tags and quotes out of the given string, replacing them with meaningful punctuation.

    Params:

    NameTypeAttributeDescription
    string String

    Return:

    String

    public highlight(string: String, phrase: String | RegExp, length: Integer): Object source

    import highlight from 'flarum/helpers/highlight.js'

    The highlight helper searches for a word phrase in a string, and wraps matches with the <mark> tag.

    Params:

    NameTypeAttributeDescription
    string String

    The string to highlight.

    phrase String | RegExp

    The word or words to highlight.

    length Integer
    • optional

    The number of characters to truncate the string to. The string will be truncated surrounding the first match.

    Return:

    Object

    public humanTime(time: Date): String source

    import humanTime from 'flarum/utils/humanTime.js'

    The humanTime utility converts a date to a localized, human-readable time- ago string.

    Params:

    NameTypeAttributeDescription
    time Date

    Return:

    String

    public humanTime() source

    import humanTime from 'flarum/initializers/humanTime.js'

    The humanTime initializer sets up a loop every 1 second to update timestamps rendered with the humanTime helper.

    public humanTime(time: Date): Object source

    import humanTime from 'flarum/helpers/humanTime.js'

    The humanTime helper displays a time in a human-friendly time-ago format (e.g. '12 days ago'), wrapped in a <time> tag with other information about the time.

    Params:

    NameTypeAttributeDescription
    time Date

    Return:

    Object

    public icon(name: String, attrs: Object): Object source

    import icon from 'flarum/helpers/icon.js'

    The icon helper displays a FontAwesome icon. The fa-fw class is applied.

    Params:

    NameTypeAttributeDescription
    name String

    The name of the icon class, without the fa- prefix.

    attrs Object

    Any other attributes to apply.

    Return:

    Object

    public listItems(items: Array): Array source

    import listItems from 'flarum/helpers/listItems.js'

    The listItems helper wraps a collection of components in

  • tags, stripping out any unnecessary Separator components.
  • Params:

    NameTypeAttributeDescription
    items Array

    Return:

    Array

    public mapRoutes(routes: Object, basePath: String): Object source

    import mapRoutes from 'flarum/utils/mapRoutes.js'

    The mapRoutes utility converts a map of named application routes into a format that can be understood by Mithril.

    Params:

    NameTypeAttributeDescription
    routes Object
    basePath String
    • optional

    Return:

    Object

    See:

    public mixin(Parent: Class, mixins: ...Object): Class source

    import mixin from 'flarum/utils/mixin.js'

    The mixin utility assigns the properties of a set of 'mixin' objects to the prototype of a parent object.

    Params:

    NameTypeAttributeDescription
    Parent Class

    The class to extend the new class from.

    mixins ...Object

    The objects to mix in.

    Return:

    Class

    A new class that extends Parent and contains the mixins.

    Example:

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

    public override(object: Object, method: String, newMethod: function) source

    import {override} from 'flarum/extend.js'

    Override an object's method by replacing it with a new function, so that the new function will be run every time the object's method is called.

    The replacement function accepts the original method as its first argument, which is like a call to 'super'. Any arguments passed to the original method are also passed to the replacement.

    Care should be taken to extend the correct object – in most cases, a class' prototype will be the desired target of extension, not the class itself.

    Params:

    NameTypeAttributeDescription
    object Object

    The object that owns the method

    method String

    The name of the method to override

    newMethod function

    The method to replace it with

    Example:

    override(Discussion.prototype, 'badges', function(original) {
      const badges = original();
      // do something with badges
      return badges;
    });

    public patchMithril(global: *) source

    import patchMithril from 'flarum/utils/patchMithril.js'

    Params:

    NameTypeAttributeDescription
    global *

    public preload(app: App) source

    import preload from 'flarum/initializers/preload.js'

    The preload initializer creates the application session and preloads it with data that has been set on the application's preload property. It also preloads any data on the application's preload property into the store. Finally, it sets the application's forum instance to the one that was preloaded.

    app.preload.session should be the same as the response from the /api/token endpoint: it should contain token and userId keys.

    Params:

    NameTypeAttributeDescription
    app App

    public punctuate(items: Array): Array source

    import punctuate from 'flarum/helpers/punctuate.js'

    The punctuate helper formats a list of strings (e.g. names) to read fluently in the application's locale.

    Params:

    NameTypeAttributeDescription
    items Array

    Return:

    Array

    Example:

    punctuate(['Toby', 'Franz', 'Dominion'])
    // Toby, Franz, and Dominion

    public routes(app: App) source

    import routes from 'flarum/initializers/routes.js'

    The routes initializer defines the admin app's routes.

    Params:

    NameTypeAttributeDescription
    app App

    public routes(app: App) source

    import routes from 'flarum/initializers/routes.js'

    The routes initializer defines the forum app's routes.

    Params:

    NameTypeAttributeDescription
    app App

    public saveConfig(config: *): * source

    import saveConfig from 'flarum/utils/saveConfig.js'

    Params:

    NameTypeAttributeDescription
    config *

    Return:

    *

    public slidable(element: DOMElement): Object source

    import slidable from 'flarum/utils/slidable.js'

    The slidable utility adds touch gestures to an element so that it can be slid away to reveal controls underneath, and then released to activate those controls.

    It relies on the element having children with particular CSS classes. TODO: document

    Params:

    NameTypeAttributeDescription
    element DOMElement

    Return:

    Object

    Return Properties:

    NameTypeAttributeDescription
    reset function

    Revert the slider to its original position. This should be called, for example, when a controls dropdown is closed.

    public slug(string: String): String source

    import {slug} from 'flarum/utils/string.js'

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

    Params:

    NameTypeAttributeDescription
    string String

    Return:

    String

    public store(app: App) source

    import store from 'flarum/initializers/store.js'

    The store initializer creates the application's data store and registers the default resource types to their models.

    Params:

    NameTypeAttributeDescription
    app App

    public stringToColor(string: String): String source

    import stringToColor from 'flarum/utils/stringToColor.js'

    Convert the given string to a unique color.

    Params:

    NameTypeAttributeDescription
    string String

    Return:

    String

    public truncate(string: String, length: Number, start: Number): String source

    import {truncate} from 'flarum/utils/string.js'

    Truncate a string to the given length, appending ellipses if necessary.

    Params:

    NameTypeAttributeDescription
    string String
    length Number
    start Number
    • optional
    • default: 0

    Return:

    String

    public ucfirst(string: String): String source

    import {ucfirst} from 'flarum/utils/string.js'

    Make a string's first character uppercase.

    Params:

    NameTypeAttributeDescription
    string String

    Return:

    String

    public username(user: User): Object source

    import username from 'flarum/helpers/username.js'

    The username helper displays a user's username in a tag. If the user doesn't exist, the username will be displayed as [deleted].

    Params:

    NameTypeAttributeDescription
    user User

    Return:

    Object