App Connect Data Formatters - Generic

Intro

Below is a comprehensive list of generic data formatters available in App Connect (client-side), accompanied by explanations outlining the purpose and functionality of each.

Generic Formatters

Default:

  • Returns the given value, but if it is null or undefined, it returns the provided default value.
  • Example: (null).default('N/A') returns 'N/A'

Is Defined:

  • Checks if the given value is not null and not undefined.
  • Example: (0).isDefined() returns true

Is Empty:

  • Checks if the given value is considered empty.
  • Rules:
    • undefined => empty
    • '' (empty string) => empty
    • 0 (number) => empty
    • false (boolean) => empty
    • [] (empty array) => empty
    • {} (object with no own properties) => empty
  • Example: ([]).isEmpty() returns true

To Bool:

  • Converts the given value to a boolean using JavaScript truthy/falsey rules.
  • Example: ('hello').toBool() returns true

To JSON:

  • Converts the given value to a JSON string.
  • Example: ({a: 1}).toJSON() returns '{"a":1}'

To Number:

  • Converts the given value to a number using Number(...).
  • Example: ('42').toNumber() returns 42

To BigInt:

  • Converts the given value to a BigInt using BigInt(...).
  • Example: ('9007199254740993').toBigInt() returns 9007199254740993n

To String:

  • Converts the given value to a string. If the value is null or undefined, returns an empty string.
  • Example: (null).toString() returns ''

To Timestamp:

  • Converts the given date/time value to a UNIX timestamp (seconds).
  • Returns undefined if the value cannot be parsed as a valid date.
  • Example: ('2021-08-04 00:00:00').toTimestamp() returns 1628035200

To Date:

  • Parses the given value as a date and formats it using the default App Connect date formatter.
  • Returns undefined if the value cannot be parsed as a valid date.
  • Example: ('2021-08-04').toDate() returns a formatted date string

To UTC Date:

  • Parses the given value as a date and returns an ISO UTC string (toISOString()).
  • Returns undefined if the value cannot be parsed as a valid date.
  • Example: ('2021-08-04 12:00:00').toUTCDate() returns '2021-08-04T09:00:00.000Z' (depending on input/timezone)

To ISO Date:

  • Parses the given value as a date and returns a local date string in YYYY-MM-DD format.
  • Returns undefined if the value cannot be parsed as a valid date.
  • Example: ('2021-08-04').toISODate() returns '2021-08-04'

To ISO Time:

  • Parses the given value as a date and returns a local time string in HH:mm:ss format.
  • If incMilliseconds is true, appends milliseconds as .SSS.
  • Returns undefined if the value cannot be parsed as a valid date.
  • Example: ('2021-08-04 12:34:56').toISOTime(false) returns '12:34:56'
  • Example: ('2021-08-04 12:34:56.789').toISOTime(true) returns '12:34:56.789'
2 Likes