Skip to main content

Understanding Operators

Ductape Operators are powerful string and array manipulation tools designed to provide flexible data transformation capabilities. Below is the detailed documentation for each available operator, including usage, examples, and explanations.

1. $Add

Description:

Adds multiple numeric values together.

Syntax:

$Add(value1, value2, ..., valueN)

Parameters:

ParameterDescription
value1...NNumeric values or placeholders

Example:

$Add(10, 20, 30)  # Result: 60
$Add(5, $valueFromVariable, 15) # Result: Computed sum

2. $Subtract

Description:

Subtracts subsequent numeric values from the first value.

Syntax:

$Subtract(value1, value2, ..., valueN)

Parameters:

ParameterDescription
value1Base number
value2...NNumbers to subtract

Example:

$Subtract(100, 20, 30)  # Result: 50 (100 - 20 - 30)

3. $Concat

Description:

Joins multiple strings into a single string with a specified delimiter.

Syntax:

$Concat([string1, string2, ..., stringN], 'delimiter')

Parameters:

ParameterDescription
[strings]Array of strings
'delimiter'String used to join

Example:

$Concat(["Hello", "World"], " ")  # Result: "Hello World"
$Concat(["2024", "07", "15"], "-") # Result: "2024-07-15"

4. $Substring

Description:

Extracts a substring from a string given start and end indices.

Syntax:

$Substring(string, start, end)

Parameters:

ParameterDescription
stringInput string
startStart index (inclusive)
endEnd index (exclusive)

Example:

$Substring("Ductape", 0, 4)  # Result: "Duct"
$Substring("Operator", 2, 6) # Result: "erat"

5. $Trim

Description:

Removes whitespace from both ends of a string.

Syntax:

$Trim(string)

Parameters:

ParameterDescription
stringInput string

Example:

$Trim("  Ductape  ")  # Result: "Ductape"
$Trim("\nNewLine\t") # Result: "NewLine"

6. $Split

Description:

Splits a string into an array based on a specified separator.

Syntax:

$Split(string, separator)

Parameters:

ParameterDescription
stringString to split
separatorDelimiter used

Example:

$Split("apple,banana,cherry", ",")  # Result: ["apple", "banana", "cherry"]
$Split("one-two-three", "-") # Result: ["one", "two", "three"]

7. $Pick

Description:

Retrieves a character from a string or an element from an array at the specified index.

Syntax:

$Pick(value, index)

Parameters:

ParameterDescription
valueString or array
indexZero-based index

Example:

$Pick("Hello", 1)  # Result: "e"
$Pick(["apple", "banana", "cherry"], 2) # Result: "cherry"

8. $Join

Description:

Merges arrays of objects into a single array.

Syntax:

$Join([[objectArray1], [objectArray2], ..., [objectArrayN]])

Parameters:

ParameterDescription
[[arrays]]Array of object arrays

Example:

$Join([[{id: 1}, {id: 2}], [{id: 3}]])  # Result: [{id: 1}, {id: 2}, {id: 3}]

9. $Uppercase

Description:

Converts a string to uppercase.

Syntax:

$Uppercase(string)

Parameters:

ParameterDescription
stringInput string

Example:

$Uppercase("ductape")  # Result: "DUCTAPE"

10. $Lowercase

Description:

Converts a string to lowercase.

Syntax:

$Lowercase(string)

Parameters:

ParameterDescription
stringInput string

Example:

$Lowercase("Ductape")  # Result: "ductape"

11. $Dateformat

Description:

Formats a date string into a specified format.

Syntax:

$Dateformat(dateString, format)

Parameters:

ParameterDescription
dateStringDate to be formatted
formatDesired date pattern

Valid Date Formats:

PatternTypeExample
YYYYYear2024
YYYear24
MMMMMonthFebruary
MMMMonthFeb
MMMonth02
MMonth2
DDDay09
DDay9
ddddWeekdayWednesday
dddWeekdayWed
HHHour (24)08
HHour (24)8
hhHour (12)08
hHour (12)8
mmMinutes05
mMinutes5
ssSeconds09
sSeconds9
AAM/PMPM
aam/pmpm

Example:

$Dateformat("2024-02-09", "DD/MM/YYYY")  # Result: "09/02/2024"
$Dateformat("2024-02-09T15:30:00", "hh:mm A") # Result: "03:30 PM"

12. $Replace

Description:

Replaces occurrences of a substring within a string.

Syntax:

$Replace(string, search, replace)

Parameters:

ParameterDescription
stringInput string
searchSubstring to find
replaceReplacement string

Example:

$Replace("Hello World", "World", "Ductape")  # Result: "Hello Ductape"
$Replace("2024-02-09", "-", "/") # Result: "2024/02/09"

13. $Filter

Description:

Filters an array based on a comparison operator and a value, returning all elements that satisfy the condition.

Syntax:

$Filter(array, "operator", value)

Parameters:

ParameterTypeDescription
arrayArrayArray of values to be filtered.
"operator"StringComparison operator (">", "<", ">=", "<=", "==", "!==").
valueAnyValue to compare each element of the array against.

Example:

$Filter([1, 2, 3, 4, 5], ">", 3)      # Result: [4, 5]
$Filter(["apple", "banana"], "==", "apple") # Result: ["apple"]

14. $Find

Description:

Finds and returns the first element in an array that matches the given comparison operator and value.

Syntax:

$Find(array, "operator", value)

Parameters:

ParameterTypeDescription
arrayArrayArray of values to search.
"operator"StringComparison operator (">", "<", ">=", "<=", "==", "!==").
valueAnyValue to compare each element of the array against.

Example:

$Find([1, 2, 3, 4, 5], "==", 3)      # Result: 3
$Find(["apple", "banana"], "==", "banana") # Result: "banana"
$Find([1, 4, 6], ">", 4) # Result: 6

Final Notes:

  • Errors are thrown for invalid inputs or out-of-bounds indices.
  • Operators are designed to be nestable and composable for complex transformations.