BackgroundModule mahalo/expression/filters

This module exports the filters object.

Index

Object literals

Object literals

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

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