The idea of nexl expressions was taken from Bash where you can perform simple
operations with Bash variables like
uppercasing characters:
MY_BASH_STR="Hello, World"
echo "${MY_BASH_STR^^}"
In this example Bash performs single uppercase operation on MY_BASH_STR
variable.
nexl expression language allows to chain multiple operations in a
single expression.
Operations in nexl are "piped" like Bash does ( but without a pipe chain
character ).
Let's say we have
a
fruits array and
we need to sort this array and join its elements with comma.
The expression will be:
${fruits#S&,}
Let's take a closer look on each operation performed in this
expression:
As we can see there are 3 operations performed in this expression:
Resolution of a fruits variable
Array sort
Array elements concatenation with comma
The following operations are available in nexl:
JavaScript variables resolution
Default value operation
Type casting operation
Object property resolution operation
Inverted object property resolution operation
Object operations
Object key(s) resolution operation
Array operations
Joining array elements operation
"Add" operation
"Eliminate" operation
String operations
Slicing arrays and strings
Miscellaneous operations
Mandatory value operation
Functions call and stack operation
Operations separator
Assign variables operation
All those operations can be chained and combined in any order in nexl
expressions
depending on your needs.
Each operation represented by special character and value followed by
that character ( in certain cases value is optional ).
Let's consider a sorting array operation from the last example:
#S
The
# character represents a group of different
array operations and the
S string followed
by that character is a value of that operation.
Another example. The
#LEN operation calculates
array length ( see more about array operations
here
).
Depending on operation type, operation value must either predefined or
free styled string ( or even nexl expression ).
Returning again to the first example we have the following operation:
&,
The
& operation joins array element
with a delimited provided as a string followed by the
&
character which is
comma. But
you can use any other string or nexl expression instead of comma.
If you are not interested in learning nexl expression language you can always
write a JavaScript function and make
all
data
aggregations inside:
function sortAndJoin() {
// sorting array
fruits.sort();
// joining array elements with comma
return fruits.join(',');
}
And then to call that function from nexl expression:
${sortAndJoin()}
But nexl expression language gives certain flexibility and adds extra features.
Mixing both methods is better solution.