Lowdefy
v3.17.2/Operators/_format/

_format

Environment: Client Only

The _format operator converts objects to strings, using a specified format. It can only be used on the web-client (not in requests or connections).

Operator methods:

_format.intlDateTimeFormat

(arguments: {
  on: date,
  params?: {
    locale?: string,
    options?: object
  },
})

The _format.intlDateTimeFormat provides language-sensitive date and time formatting, based on Intl.DateTimeFormat. If no locale is provide, the users default locale will be used.

Arguments

object
  • on: date: The date object to format.
  • params: object:
    • locale: string: A string with a BCP 47 language tag, or an array of such strings.
    • options: object: Intl.DateTimeFormat options.

Examples

Format a date:
_format.intlDateTimeFormat:
  on:
    _date: 2019-06-13
  params:
    locale: en
    options:
      weekday: long
      year: numeric
      month: long
      day: numeric

Returns: "Thursday, June 13, 2019".

_format.intlListFormat

(arguments: {
  on: any[],
  params?: {
    locale?: string,
    options?: object
  },
})

The _format.intlListFormat provides language-sensitive list formatting, based on Intl.ListFormat. If no locale is provide, the users default locale will be used.

Arguments

object
  • on: any[]: The array to format.
  • params: object:
    • locale: string: A string with a BCP 47 language tag, or an array of such strings.
    • options: object: Intl.ListFormat options.

Examples

Format a list:
_format.intlListFormat:
  on:
    - Motorcycle
    - Bus
    - Car
  params:
    locale: fr

Returns: "Motorcycle, Bus et Car".

_format.intlNumberFormat

(arguments: {
  on: number,
  params?: {
    locale?: string,
    options?: object
  },
})

The _format.intlNumberFormat provides language-sensitive number formatting, based on Intl.NumberFormat. If no locale is provide, the users default locale will be used.

Arguments

object
  • on: number: The number to format.
  • params: object:
    • locale: string: A string with a BCP 47 language tag, or an array of such strings.
    • options: object: Intl.NumberFormat options.

Examples

Format a number:
_format.intlNumberFormat:
  on: 13182375813.47422
  params:
    locale: de

Returns: "13,18,23,75,813.474".

_format.intlRelativeTimeFormat

(arguments: {
  on: any,
  params: {
    locale?: string,
    unit: enum,
    options?: object
  },
})

The _format.intlRelativeTimeFormat provides language-sensitive relative time formatting, based on Intl.RelativeTimeFormat. If no locale is provide, the users default locale will be used.

Arguments

object
  • on: number: The number to format.
  • params: object:
    • locale: string: A string with a BCP 47 language tag, or an array of such strings.
    • unit: enum: Unit to use in the relative time internationalized message. Possible values are: year, quarter, month, week, day, hour, minute, second. Plural forms are also permitted.
    • options: object: Intl.RelativeTimeFormat options.

Examples

Format a number:
_format.intlRelativeTimeFormat:
  on: 4
  params:
    unit: 'days'
    locale: fr

Returns: "dans 4 jours".

_format.momentFormat

(arguments: {
  on: date | string,
  params?: {
    locale?: string,
    format?: string
  },
})

The _format.momentFormat formats dates using the moment.js library.

Arguments

object
  • on: date | string: The date to format.
  • params: object:
    • locale: string: A string with a locale name.
    • format: string: A date format string.

Examples

Format a date:
_format.momentFormat:
  on:
    _date: 2019-06-04
  params:
    format: 'd MMM YYYY'

Returns: "4 Jun 2019".

_format.momentHumanizeDuration

(arguments: {
  on: number,
  params?: {
    locale?: string,
    thresholds?: string,
    withSuffix?: boolean
  },
})

The _format.momentHumanizeDuration formats durations in milliseconds using the moment.js

Arguments

object
  • on: number: The duration in milliseconds to format.
  • params: object:
    • locale: string: A string with a locale name.
    • thresholds: object: Thresholds define when a unit is considered a minute, an hour and so on. For example, by default more than 45 seconds is considered a minute, more than 22 hours is considered a day and so on. See here
    • withSuffix: boolean: By default, the return string is describing a duration a month (suffix-less). If you want an oriented duration in a month, a month ago (with suffix), pass in true.

Examples

Format a date:
_format.momentHumanizeDuration:
  on: 245923000
  params:
    withSuffix: true

Returns: "in 3 days".