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
nullorundefined, it returns the provided default value. - Example:
(null).default('N/A')returns'N/A'
Is Defined:
- Checks if the given value is not
nulland notundefined. - Example:
(0).isDefined()returnstrue
Is Empty:
- Checks if the given value is considered empty.
- Rules:
undefined=> empty''(empty string) => empty0(number) => emptyfalse(boolean) => empty[](empty array) => empty{}(object with no own properties) => empty
- Example:
([]).isEmpty()returnstrue
To Bool:
- Converts the given value to a boolean using JavaScript truthy/falsey rules.
- Example:
('hello').toBool()returnstrue
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()returns42
To BigInt:
- Converts the given value to a BigInt using
BigInt(...). - Example:
('9007199254740993').toBigInt()returns9007199254740993n
To String:
- Converts the given value to a string. If the value is
nullorundefined, returns an empty string. - Example:
(null).toString()returns''
To Timestamp:
- Converts the given date/time value to a UNIX timestamp (seconds).
- Returns
undefinedif the value cannot be parsed as a valid date. - Example:
('2021-08-04 00:00:00').toTimestamp()returns1628035200
To Date:
- Parses the given value as a date and formats it using the default App Connect date formatter.
- Returns
undefinedif 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
undefinedif 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-DDformat. - Returns
undefinedif 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:ssformat. - If
incMillisecondsistrue, appends milliseconds as.SSS. - Returns
undefinedif 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'