core
append(array arr, any val)
Given arr
and val
, appends val
to the end of arr
.
Example
[ 2, 3, 5, 7 ]
ds.append(payload, 11)
[ 2, 3, 5, 7, 11 ]
combine(any first, any second)
Combines first
and second
. Some values will auto-coerce, e.g. the number 5 will auto coerce to the string "5."
Example
{ string: ds.combine("Hello ", "World"), number: ds.combine(5, 7), auto1: ds.combine("Hello ", 5), auto2: ds.combine(5, "10"), array: ds.combine([1,2], [3,4]), obj: ds.combine({a:1}, {b:2}) }
{ "string": "Hello World", "number": "57", "auto1": "Hello 5", "auto2": "510", "array": [ 1, 2, 3, 4 ], "obj": { "a": 1, "b": 2 } }
contains(array|string item, any val)
If item
is an array, returns true if item
contains val
.
If item
is a string, returns true if item
contains the sub string val
.
Example
[ 2, 3, 5, 7 ]
ds.contains(payload, 2)
true
distinctBy(array|object item, function discriminator)
Returns a new object containing only the items that are a unique result from discriminator
.
The function discriminator
is expected to take the value as the first parameter (required) and the index as the second (optional).
Example
{ "array": [ 1, 1, 2, 2, 3, 3, 4, 4, 5 ], "obj": { "a": 1, "b": 2, "c": 1 } }
{ array: ds.distinctBy(payload.array, function(item,index) item), obj: ds.distinctBy(payload.obj, function(value,key) value) }
{ "array": [ 1, 2, 3, 4, 5 ], "obj": { "a": 1, "b": 2 } }
endsWith(string str, string subStr)
Returns true if str
ends with subStr
. Ignores casing.
Example
{ "name": "Scala", "version": "1.0" }
ds.endsWith(payload.version, ".0")
true
entriesOf(object obj)
Returns an array of objects describing each key value pair of obj
.
Example
{ "name": "Scala", "version": "1.0" }
ds.entriesOf(payload)
[ { "value": "Scala", "key": "name" }, { "value": "1.0", "key": "version" } ]
filter(array arr, function func)
Filters arr
depending on the result of func
.
The function func
is expected to take the value as the first parameter (required) and the index as the second (optional).
Example
[ 1, 2, 3, 4 ]
ds.filter(payload, function(value, index) value < 3)
[ 1, 2 ]
filterObject(object obj, function func)
Filters obj
depending on the result of func
.
The function func
is expected to take the property value as the first parameter (required), the property key as the second (optional) and the index as the third (optional).
Example
{ "version": 1.7 }
ds.filterObject(payload, function(value, key, index) value > 1.5)
{ "version": 1.7 }
find(string|array item, any val)
Returns an array containing the location where val
occurs in item
.
Example
{ "string": "Hello World", "array": [1,2,3,4] }
{ string: ds.find(payload.string, "World"), array: ds.find(payload.array, 3) }
{ "string": [6], "array": [2] }
flatten(array arr)
Given arr
, which contains one level arrays, creates a flat array.
Example
[ [ 1, 2 ], [ 3, 4 ] ]
ds.flatten(payload)
[ 1, 2, 3, 4 ]
flatMap(array arr, function func)
Given an array of arrays arr
, creates a flat array using the outcome of func
.
The function func
is expected to take the value as the first parameter (required) and the index as the second (optional).
Example
[ [ 2, 3, 5, 7 ], [ 11, 13, 17, 19 ] ]
ds.flatMap(payload, function(value, index) value)
[ 2, 3, 5, 7, 11, 13, 17, 19 ]
foldLeft(array arr, any initVal, function func)
Iterates over arr
, applying func
to the previous result. Starts with the value provided in initVal
.
The function func
is expected to take the current value as the first parameter (required) and the previous value as the second parameter (required).
Example
[ 1, 2, 3, 4 ]
ds.foldLeft(payload, 1, function(curr, prev) curr * prev)
24 /* 1 * 1 = 1 2 * 1 = 2 3 * 2 = 6 4 * 6 = 24 */
foldRight(array arr, any initVal, function func)
Iterates backwards over an array, applying func
to the previous result. Starts with the value provided in initVal
.
The function func
is expected to take the current value as the first parameter (required) and the previous value as the second parameter (required).
Example
[ 1, 2, 3, 4 ]
ds.foldRight(payload, 1, function(curr, prev) curr * prev)
24 /* 4 * 1 = 4 // 1 in this case is the initial value 3 * 4 = 12 2 * 12 = 24 1 * 24 = 24 */
groupBy(array|object items, function discriminator)
Groups the provided items
into an object based on the result of discriminator
.
The function discriminator
is expected to take the value as the first parameter (required) and the index as the second (optional).
Example
{ "array": [ "a", "b", "a" ], "obj": { "a":"Alpha", "b":"Bravo", "c": "Alpha" } }
{ array: ds.groupBy(payload.array, function(item,index) item ), obj: ds.groupBy(payload.obj, function(value,key) value) }
{ "array": { "a": [ "a", "a" ], "b": [ "b" ] }, "obj": { "Alpha": { "a": "Alpha", "c": "Alpha" }, "Bravo": { "b": "Bravo" } } }
isArray(any valToCheck)
Accepts any given value as valToCheck
and checks if it is of type array.
Example
[ 1, 2, 3, 4 ]
ds.isArray(payload)
true
isBlank(string strToCheck)
Checks if strToCheck
is blank. Also returns true if null.
Example
{ str1: ds.isBlank(" "), str2: ds.isBlank(""), 'null': ds.isBlank(null) }
{ "str1": true, "str2": true, "null": true }
isBoolean(any valToCheck)
Accepts any given value as valToCheck
and checks if it is of type bool.
Example
{ "name": "Java", "isObjectOriented": true }
ds.isBoolean(payload.isObjectOriented)
true
isDecimal(num numToCheck)
Checks that the input number numToCheck
is a decimal number. Trailing zeros are ignored.
Example
{ a: ds.isDecimal(2), b: ds.isDecimal(2.0), c: ds.isDecimal(2.1), }
{ "a": false, "b": false, "c": true }
isEmpty(any valToCheck)
Checks if valToCheck
is empty. Does not ignore white space if string. Returns true if null.
Example
{ "null": ds.isEmpty(null), str: ds.isEmpty(" "), array: ds.isEmpty([]), obj: ds.isEmpty({}) }
{ "null": true, "str": false, "array": true, "obj": true }
isEven(num numToCheck)
Checks that the input number numToCheck
is an even number.
Example
{ "version": 2.0 }
ds.isEven(payload.version)
true
isFunction(any valToCheck)
Accepts any given value valToCheck
and checks if it is of type function.
Example
ds.isFunction(function() "5")
true
isInteger(num numToCheck)
Checks that the input number numToCheck
is an integer. Trailing zeros are ignored.
Example
{ "version": 2.0 }
ds.isInteger(payload.version)
true
isNumber(any valToCheck)
Accepts any given value valToCheck
and checks if it is of type number.
Example
{ "age": 5 }
ds.isNumber(payload.age)
true
isObject(any valToCheck)
Accepts any given value valToCheck
and checks if it is of type object.
Example
{ "language": "Java" }
ds.isObject(payload)
true
isOdd(num numToCheck)
Checks that numToCheck
is an odd number.
Example
{ "age": 5 }
ds.isOdd(payload.age)
true
isString(any valToCheck)
Accepts any given value valToCheck
and checks if it is of type string.
Example
{ "language":"Java" }
ds.isString(payload.language)
true
joinBy(array arr, string separator)
Joins arr
into a string with the provided separator
.
Example
{ "versions": [1.0, 1.2, 1.7, 1.8] }
ds.joinBy(payload.versions, ", ")
"1, 1.2, 1.7, 1.8"
keysOf(object obj)
Returns an array of all the key names in obj
.
Example
{ "departureDate": "01/20/2019", "origin": "PHX", "destination": "SEA" }
ds.keysOf(payload)
[ "departureDate", "origin", "destination" ]
lower(string str)
Converts str
to all lower case characters.
Example
{ "origin": "PHX", "destination": "SEA" }
ds.lower(payload.origin)
"phx"
map(array arr, function func)
Loops through all items in arr
, applies func
to each, and returns a new array containing each result. Returns null if arr
is null.
The function func
is expected to take the value as the first parameter (required) and the index as the second (optional).
Example
{ "versions": [1.0, 1.2, 1.7, 1.8] }
ds.map(payload.versions, function(value, index) value > 1.2)
[ false, false, true, true ]
mapEntries(object obj, function func)
Loops through all properties in obj
, applies func
to each, and returns a new array containing each result.
The function func
is expected to take the property value as the first parameter (required), the property key as the second (optional) and the index as the third (optional).
Example
{ "origin": "PHX", "destination": "SEA" }
ds.mapEntries(payload, function(value, key, index) value)
[ "PHX", "SEA" ]
mapObject(object obj, function func)
Loops through all properties in obj
, applies func
to each, and returns a new object containing each result.
The function func
is expected to take the property value as the first parameter (required), the property key as the second (optional) and the index as the third (optional).
Example
{ "origin": "PHX", "destination": "SEA" }
ds.mapObject(payload, function(value, key, index) {[key]:value})
{ "origin": "PHX", "destination": "SEA" }
match(string str, string regex)
Executes the regex expression regex
against str
and returns an array with the match groups.
Example
{ "email": "test@server.com" }
ds.match(payload.email, "(.*)@(.*)(.com)")
[ "test@server.com", "test", "server", ".com" ]
matches(string str, string regex)
Executes the regex expression regex
against str
and returns true
or false
if the expression matches the input.
Example
{ "email": "test@server.com" }
ds.matches(payload.email, "(.*)@(.*)(.com)")
true
max(array arr)
Returns the max value in arr
.
Example
[ 5, 2, 7, 3 ]
ds.max(payload)
7
maxBy(array arr, function func)
Returns the max result of func
in arr
.
The function func
is expected to take the value as the first parameter (required).
Example
[ {"age": 5}, {"age": 7}, {"age": 3} ]
ds.maxBy(payload, function(value) value.age)
{ "age": 7 }
min(array arr)
Returns the min value in arr
.
Example
[ 5, 2, 7, 3 ]
ds.min(payload)
2
minBy(array arr, function func)
Returns the max result of func
in arr
.
The function func
is expected to take the value as the first parameter (required).
Example
[ {"age": 5}, {"age": 7}, {"age": 3} ]
ds.minBy(payload, function(value) value.age)
{ "age": 3 }
orderBy(array|object items, function func)
Reorders the array items
by the result of func
.
If items
is an array: the function func
is expected to take the value as the first parameter (required).
If items
is an object: the function func
is expected to take the value as the first parameter (required) and the key as the second parameter (optional).
Example
[ {"age": 5}, {"age": 7}, {"age": 3} ]
ds.orderBy(payload, function(value) value.age)
[ { "age": 3 }, { "age": 5 }, { "age": 7 } ]
parseDouble(string str)
Parses a string str
containing a number and returns its decimal value. Trailing zeros are ignored.
Example
{ "version":"1.5" }
ds.parseDouble(payload.version)
1.5
parseHex(string str)
Parses a hex value given as a string str
and returns its decimal value.
Example
{ "hex":"F" }
ds.parseHex(payload.hex)
15
parseInt(string str)
Parses an int value given as a string str
and returns its integer value.
Example
{ "number":"50" }
ds.parseInt(payload.number)
50
parseOctal(string str)
Parses an octal value given as a string str
and returns its integer value.
Example
{ "octal":"107136" }
ds.parseOctal(payload.octal)
36446
prepend(array arr, any val)
Given arr
and val
, inserts val
at the beginning of arr
.
Example
[ 2, 3, 4 ]
ds.prepend(payload, 1)
[ 1, 2, 3, 4 ]
range(number start, number end)
Returns an array with the numbers from the start
to the end
of the range, inclusive.
Example
{ "start": 0, "end": 3 }
ds.range(payload.start, payload.end)
[ 0, 1, 2, 3 ]
read(string data, string mimeType, object params)
Reads a string data
as the given mimetype
.
Example
ds.read("{\"price\": 8.95}", "application/json", {})
{ "price": 8.95 }
readUrl(string url)
Reads url
and returns the content of the url, if it’s JSON.
Example
ds.readUrl("http://httpbin.org/get")
{ "args": {}, "headers": { "Accept": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Host": "httpbin.org", "User-Agent": "Java/14.0.1", "X-Amzn-Trace-Id": "Root=1-5f7f568d-481e623471c21cc2686e53e8" }, "origin": "69.250.49.68", "url": "http://httpbin.org/get" }
remove(array|object item, string|array value)
Removes value
from item
and returns the remaining array or object.
All properties of the object can be removed using a value
in the array format.
Example
{ "array": [ 1, 2, 3, 4 ], "obj": { "a": 1, "b": 2 } }
{ array: ds.remove(payload.array, 3), obj: ds.remove(payload.obj, "b"), emptyObj: ds.remove(payload.obj, ["a","b"]) }
{ "array": [ 1, 2, 4 ], "obj": { "a": 1 }, "emptyObj": {} }
removeMatch(array|object items, any val)
Given an array or an object items
and val
of the same type, removes the matching values. If items
is an object, both key and value must match.
Example
{ "array": [1,2,3,4], "obj": {"a":1,"b":2} }
{ array: ds.removeMatch(payload.array, [1,4]), obj: ds.removeMatch(payload.obj, {a:1,b:3}) }
{ "array": [ 2, 3 ], "obj": { "b": 2 } }
replace(string phrase, string regex, string replacement)
Replaces the matching regex
with the replacement
in the phrase
.
Example
{ "regex": "Hello", "replacement": "Goodbye" }
ds.replace("Hello World", payload.regex, payload.replacement)
"Goodbye World"
reverse(array|object items)
Given an array or object as items
, reverses the order of the elements.
Example
{ "array": [ 1, 2, 3, 4 ], "obj": { "a":1, "b":2 } }
{ array: ds.reverse(payload.array), obj: ds.reverse(payload.obj) }
{ "array": [ 4, 3, 2, 1 ], "obj": { "b": 2, "a": 1 } }
scan(string str, string regex)
Executes the regex expression regex
against str
and returns an array with each match as an array.
Example
{ "email": "test@server.com" }
ds.scan(payload.email, "(.*)@(.*)(.com)")
[ [ "test@server.com", "test", "server", ".com" ] ]
select(object obj, string path)
Returns a value inside obj
by the provided path
. For nested objects, the path is separated by a dot ('.').
Example
{ "language": { "name": "Java", "version": "1.8" } }
{ language: ds.select(payload, 'language.name') }
{ "language": "Java" }
sizeOf(any val)
Returns the size of val
.
Example
{ "array": [1, 2], "obj": {"prop": 2}, "string": "x" }
{ array: ds.sizeOf(payload.array), object: ds.sizeOf(payload.obj), 'null': ds.sizeOf(null), 'function': ds.sizeOf(function(a,b,c) 1), string: ds.sizeOf(payload.string) }
{ "array": 2, "object": 1, "null": 0, "function": 3, "string": 1 }
splitBy(string strToSplit, string regex)
Splits strToSplit
into an array based on the matching regex
.
Example
{ "string": "Hello World" }
ds.splitBy(payload.string, " ")
[ "Hello", "World" ]
startsWith(string str, string subStr)
Checks if str
starts with subStr
. Ignores casing.
Example
{ "string": "Hello World" }
ds.startsWith(payload.string, "hello")
true
toString(any val)
Returns val
to a string.
Example
{ "num": 5 }
ds.toString(payload.num)
"5"
trim(string str)
Removes leading and trailing spaces in str
.
Example
{ "string": " Hello World " }
ds.trim(payload.string)
"Hello World"
typeOf(any val)
Returns a string describing the type of object val
is.
Example
{ string: ds.typeOf(""), bool: ds.typeOf(true), "null": ds.typeOf(null), number: ds.typeOf(0), "function": ds.typeOf(function() 1), array: ds.typeOf([]), object: ds.typeOf({}) }
{ "string": "string", "bool": "boolean", "null": "null", "number": "number", "function": "function", "array": "array", "object": "object" }
unzip(array arr)
Unzips an array of arrays arr
and creates a new array of arrays based on their index in arr
.
Example
[ [ 1, 2 ], [ 1, 2 ] ]
ds.unzip(payload)
[ [ 1, 1 ], [ 2, 2 ] ]
upper(string str)
Converts a string to all uppercase characters.
Example
{ "string": "HeLlO wOrLd" }
ds.upper(payload.string)
"HELLO WORLD"
uuid
Generates random alphanumeric uuid.
Example
ds.uuid
"cj36alpm-8mlt-fm43-8vth-mbd961259lqh"
valuesOf(object obj)
Given an object obj
, returns an array of the values inside obj
.
Example
{ "origin": "PHX", "destination": "SEA" }
ds.valuesOf(payload)
[ "PHX", "SEA" ]
write(array|object item, string mimeType, object params)
Converts item
to a string.
Example
{ "price": 8.95 }
ds.write(payload, "application/json", {})
"{\"price\":8.95}"
zip(array array1, array array2)
Accepts array1
and array2
and combines them into one using elements with matching indexes.
Example
{ "firstNames": ["Evelyn", "Herman"], "lastNames": ["Waugh" , "Melville", "Tolkien"] }
ds.zip(payload.firstNames, payload.lastNames)
[ [ "Evelyn", "Waugh" ], [ "Herman", "Melville" ] ]