BackgroundModule mahalo

The main module of Mahalo. In general everything you need towork with when creating Mahalo applications can be importedfrom here.

All exports of mahalo can be considered public. You mightfind more goodies in other places of Mahalo's source theycould change in the future.

Index

Functions

assign

  • assign(obj?: Object, key?: string | number, val?: any): any
  • The assign function triggers Mahalo's change detection. Howeverwhen writing your application in TypeScript you don't have to takecare of this yourself and won't need to use this function at all.

    Example

    In the following examples you can see different assignments an theircounterparts using assign.

    let foo = 0;let bar = 0;let baz = {x: 0};// Variable assignments are just wrapped++foo; // 1assign(++foo); // 2foo + (bar = 10); // bar 12foo + assign(bar = 10); // 12// Member assignments must be explicitfoo + baz.x++; // 2foo + assign(baz, 'x', baz.x + 1); // 3
    alias

    { default } from mahalo/change-detection/assign

    Parameters
    • Optional obj: Object
    • Optional key: string | number
    • Optional val: any
    Returns any

bootstrap

  • Bootstraps a Mahalo application

    Parameters
    Returns void

keyPath

  • keyPath(obj: Object, path: string, val?: any): any
  • Finds a value along a given path or sets a value in the given pathwhen called with a third argument.

    A key path is a chain of keys to follow inside of an object. They aresepareted by a dot. If your key actually contains a dot you canescape it with the ^ symbol. If you need an actual ^ symbolin a key you can use ^^. You get the idea.

    alias

    { default } from mahalo/utils/key-path

    Parameters
    • obj: Object
    • path: string
    • Optional val: any
    Returns any

unwatch

  • unwatch(obj: Object, path?: string, callback?: Function): void
  • Remove a callback for a key path, remove all callbacks for a key pathinside of an object or unwatch the object entirely.

    See keyPath for more information about valid key paths.

    alias

    { unwatch } from mahalo/change-detection/key-path

    Parameters
    • obj: Object
    • Optional path: string
    • Optional callback: Function
    Returns void

watch

  • watch(obj: Object, path: string, callback: Function): void
  • Watch a key path inside of an object and execute a givencallback when the value changes.

    See keyPath for more information about valid key paths.

    alias

    { watch } from mahalo/change-detection/key-path

    Parameters
    • obj: Object
    • path: string
    • callback: Function
    Returns void

Object literals

config

config:object

Mahalo's configuration object. It's a simple map thatyou can read from but also write to.

alias

{ config } from mahalo/config

basePath

basePath:string = "/"

The path to your application where '/' is the web root.

classesAttribute

classesAttribute:string = "classes"

The attribute name that will be used to attach the Classesbehavior to elements with that attribute.

contentAttribute

contentAttribute:string = "content"

The attribute name that will be used to attach the Contentbehavior to elements with that attribute.

dateFormat

dateFormat:string = "MM/DD/YYYY hh:mm"

The default format for dates if no other is specified.

environment

environment:string = "development"

forSelector

forSelector:string = "for"

The selector that will be used to select elements thatshould use the For component.

linkAttribute

linkAttribute:string = "link"

The attribute name that will be used to attach the Linkbehavior to elements with that attribute.

modelAttribute

modelAttribute:string = "model"

The attribute name that will be used to attach the Modelbehavior to elements with that attribute.

numberFormat

numberFormat:string = "1,000.00"

The default format for numbers.

routeSelector

routeSelector:string = "route"

The selector that will be used to select elements thatshould represent a Route.

showSelector

showSelector:string = "show"

The selector that will be used to select elements thatshould use the Show component.

stylesAttribute

stylesAttribute:string = "styles"

The attribute name that will be used to attach the Stylesbehavior to elements with that attribute.

filters

filters:object

This is the filters object that will be used to lookfor filters in expressions. It's a plain JS object soyou can just import it, use its methods as you see fit,add custom filters to it or even overwrite the defaultones.

alias

{ filters } from mahalo/expression/filters

camel

  • camel(value: string, first?: boolean): string
  • Converts a hyphenated or underscored string to camel-case.

    Parameters
    • value: string
    • Optional first: boolean
    Returns string

date

  • date(value: string, format?: string): string
  • Converts a given value to a date in a givenformat orthe default one from the config.

    Currently the following tokens are supported:

    • D: 1 or 2 digit day of the month (1-31)
    • DD: 2 digit day of the month (01-31)
    • M: 1 or 2 digit month (1-12)
    • MM: 2 digit month (01-12)
    • YY: 2 digit year (00-99)
    • YYYY: 4 digit year (0000-9999)
    • h: Hour (1-12)
    • hh: Hour (00-23)
    • mm: Minutes (00-59)
    • ss: Seconds (00-59)
    Parameters
    • value: string
    • Optional format: string
    Returns string

filter

  • filter(arr: any[], value?: any, key?: string): Array<any>
  • Filters an array by a given value or undefined. If an optional key isgiven as third argument it will try to use that key fromtha array's values.

    Parameters
    • arr: any[]
    • Optional value: any
    • Optional key: string
    Returns Array<any>

hyphen

  • hyphen(value: string): string
  • Converts a camel-cased string to a hyphenated one.

    Parameters
    • value: string
    Returns string

lower

  • lower(value: string): string
  • Converts a string to lower-case letters.

    Parameters
    • value: string
    Returns string

number

  • number(value: any, format?: string): string
  • Converts a value to number in a optionally give format orthe default one from the config.

    The format will be parsed from one of the following orfallback to an integer:

    • 1000
    • 1000.00
    • 1,000.00
    • 1.000,00

    Basically the algorithm is to use any non numeric characterfrom the 2 position in the string as thousands separator ifavailable. The last non numeric character from the end willbe used the decimal point and the number of numeric charactersat the end of the string will be used as precision.

    Parameters
    • value: any
    • Optional format: string
    Returns string

pad

  • pad(value: string | number, length: number, char?: string): string
  • Pads a string on its left side with an optional givencharacter or 0.

    Parameters
    • value: string | number
    • length: number
    • Default value char: string = "0"
    Returns string

sort

  • sort(arr: any[], key?: string, desc?: boolean): Array<any>
  • Sorts an array. An optional key can be given as second parameterthat will be looked up on the array's values for comparison.A third argument allows for changing the sort order to descending.

    Parameters
    • arr: any[]
    • Optional key: string
    • Optional desc: boolean
    Returns Array<any>

underscore

  • underscore(value: string): string
  • Converts a camel-cased string to a underscored one.

    Parameters
    • value: string
    Returns string

upper

  • upper(value: string): string
  • Converts a string to upper-case letters.

    Parameters
    • value: string
    Returns string