Strings, Numbers and Currency Functions
All the functions are in camel case. The following is the sample JSON will be used in the examples
The following is the sample JSON for all the examples
data = {
"company_name": "Nakatomi Trading Corp",
"total_amount": 82542.56,
"date": "2021-09-30",
"items": [
{
"name": "Brand Guide",
"man_hour": 2,
"unit": "hour",
"unit_price": 120.0,
"item_total": 240.0
},
{
"name": "Software Development",
"man_hour": 17,
"unit": "hour",
"unit_price": 20.0,
"item_total": 340.0
},
{
"name": "Landing Page Design",
"man_hour": 5,
"unit": "hour",
"unit_price": 20.0,
"item_total": 80.0
}
]
}
Number Functions
max
It returns the largest-valued number.
Usage
max(`field`, `array`)
Parameters
| Parameter | Type | Description |
field | string | Property name of the an object in an array |
array | array | An array |
Example
{{ max("man_hours", data.items) }}
Output
17
min
It returns the lowest-valued number.
Usage
min(`field`, `array`)
Parameters
| Parameter | Type | Description |
field | string | Property name of the an object in an array |
array | array | An array |
Example
{{ min("man_hours", data.items) }}
Output
2
sum
It returns the sum of values.
Usage
sum(`field`, `array`)
Parameters
| Parameter | Type | Description |
field | string | Property name of the an object in an array |
array | array | An array |
Example
{{ sum("man_hours", data.items) }}
Output
23
sumArray
It returns the sum of values.
Usage
sumArray(`numeric_array`)
Parameters
| Parameter | Type | Description |
numeric_array | array | Array of float values |
Example
{{ sumArray([1,2,3,4,5]) }}
Output
15
average
It returns the average value
Usage
average(`field`, `array`)
Parameters
| Parameter | Type | Description |
field | string | Property name of the an object in an array |
array | array | An array |
Example
{{ average("man_hours", data.items) }}
Output
8
asArray
It flattens the values of the field of array as a single-dimensional array.
Usage
asArray(`field`, `array`)
Parameters
| Parameter | Type | Description |
field | string | Property name of the an object in an array |
array | array | An array |
Example
{{ average("man_hours", data.items) }}
Output
[2, 17, 5]
count
It returns the size/length of an array.
Usage
count(`array`)
Parameters
| Parameter | Type | Description |
array | array | An array |
Example
{{ count(data.items) }}
Output
3
String Functions
upperCase
It converts the specified string to uppercase letters.
Usage
upperCase(`strval`)
Parameters
| Parameter | Type | Description |
strval | string | A string |
Example
{{ upperCase(data.company_name) }}
Output
NAKATOMI TRADING CORP
lowerCase
It converts the specified string to lowercase letters.
Usage
lowerCase(`strval`)
Parameters
| Parameter | Type | Description |
strval | string | A string |
Example
{{ lowerCase(data.company_name) }}
Output
nakatomi trading corp
isNullOrEmpty
It indicates whether the specified string is null or an empty string ("").
Usage
isNullOrEmpty(`strval`)
Parameters
| Parameter | Type | Description |
strval | string | A string |
Example
{{ isNullOrEmpty(data.company_name) }}
Output
false
ifNull
It returns a specified value(nullValueReplacement) if the input(val) is null, undefined or empty.
Otherwise, this function returns the original value(val).
Usage
ifNull(`val`, `nullValueReplacement`)
Parameters
| Parameter | Type | Description |
val | string | A string |
nullValueReplacement | string | if the input(val) is null nullValueReplacement will be return |
Example 1
{{ ifNull(data.unknownField, 'N/A') }}
Output
N/A
Example 2
{{ ifNull(data.company_name, 'N/A') }}
Output
Nakatomi Trading Corp
truncateString
It truncates a string to the specified length.
Usage
truncateString(`strval`, `length`, `ending`)
Parameters
| Parameter | Type | Description |
strval | string | A string |
length | integer | Max length of the string |
ending | string | Optional and default to ..., suffix that exceeds the length |
Example
{{ truncateString(data.company_name, 10) }}
Output
Nakatomi T...
Format number
format
It formats a number and returns a formatted string.
Usage
format(`number`, `type`, `format`)
Parameters
| Parameter | Type | Description |
number | number | A number |
type | string | use “number” |
format | string | Visit numeraljs for details |
Number format
| Number | Format | Output |
| 10000 | ‘0,0.0000’ | 10,000.0000 |
| 10000.23 | ‘0,0’ | 10,000 |
| 10000.23 | ‘+0,0’ | +10,000 |
| -10000 | ‘0,0.0’ | -10,000.0 |
| 10000.1234 | ‘0.000’ | 10000.123 |
| 100.1234 | ‘00000’ | 00100 |
| 1000.1234 | ‘000000,0’ | 001,000 |
| 10 | ‘000.00’ | 010.00 |
| 10000.1234 | ‘0[.]00000’ | 10000.12340 |
| -10000 | ‘(0,0.0000)’ | (10,000.0000) |
| -0.23 | ‘.00’ | -.23 |
| -0.23 | ‘(.00)’ | (.23) |
| 0.23 | ‘0.00000’ | 0.23000 |
| 0.23 | ‘0.0[0000]’ | 0.23 |
| 1230974 | ‘0.0a’ | 1.2m |
| 1460 | ‘0 a’ | 1 k |
| -104000 | ‘0a’ | -104k |
| 1 | ‘0o’ | 1st |
| 100 | ‘0o’ | 100th |
Currency format
| Number | Format | String |
| 1000.234 | ‘$0,0.00’ | $1,000.23 |
| 1000.2 | ‘0,0[.]00 $’ | 1,000.20 |
| -1000.234 | ‘($0,0)’ | ($1,000) |
| -1000.234 | ‘$0.00’ | -1000.23 |
Visit numeraljs for details
Example
{{ format(data.total_amount, "number", "$0,0.0000") }}
Output
$82,542.5600
Use Numeral library to format
Use Numeraljs in the expression
Visit numeraljs for details
Example
{{ numeral(1000).format('0,0') }}
Output
1,000
Format currency with locale
Usage
{{ Number(`numeric_value`).toLocaleString(`locale`, {minimumFractionDigits: 2}) }}
| Locale | Output |
| ar-BH ,ar-EG ,ar-IQ ,ar-JO ,ar-KW ,ar-LB ,ar-OM ,ar-QA ,ar-SA ,ar-SD ,ar-SY ,ar-YE | ١٨٬٩٢٣٬٤٠٠٫٨٩ |
| ar-DZ ,ar-LY ,ar-MA ,ar-TN ,az-Cyrl-AZ ,bs-Cyrl-BA ,ca-ES ,da-DK ,de-DE ,de-LU ,el-CY ,el-GR ,es-AR ,es-BO ,es-CL ,es-CO ,es-EC ,es-ES ,es-PY ,es-UY ,es-VE ,fr-LU ,hr-BA ,hr-HR ,id-ID ,in-ID ,es-ES ,it-IT ,ms-BN ,nl-BE ,nl-NL ,pt-BR ,ro-mo ,ro-RO ,sl-SI ,sr-BA ,sr-CS ,sr-Cyrl-BA ,sr-Cyrl-CS ,sr-Cyrl-ME ,sr-Cyrl-RS ,sr-Latn-BA ,sr-Latn-CS ,sr-Latn-ME ,sr-Latn-RS ,sr-ME ,sr-RS ,sr-sp ,tr-TR ,vi-VN | 18.923.400,89 |
| bg-BG ,cs-CZ ,de-AT ,en-ZA ,es-CR ,et-EE ,fi-FI ,fr-CA ,hu-HU ,lt-LT ,lv-LV ,nb-NO ,no-no ,pl-PL ,pt-PT ,ru-mo ,ru-RU ,sk-SK ,sv-FI ,sv-SE ,uk-UA ,uz-Cyrl-UZ | 18 923 400,89 |
| bn-BD ,bn-IN | ১,৮৯,২৩,৪০০.৮৯ |
| de-CH ,de-LI ,it-CH | 18’923’400.89 |
| en-IN ,gu-IN ,hi-IN ,ml-IN ,ta-IN ,te-IN | 1,89,23,400.89 |
| fa-IR ,prs-AF | ۱۸٬۹۲۳٬۴۰۰٫۸۹ |
| fr-BE ,fr-CH ,fr-FR ,fr-MC | 18 923 400,89 |
| mr-IN | १,८९,२३,४००.८९ |
Syntax
{{ Number(123400.89).toLocaleString('de-DE', {minimumFractionDigits: 2}) }}
Output
18.923.400,89