Skip to main content
Modules

Functions

Functions

The Functions module is responsible for performing specific function actions — for example, generating a random string. Its methods can be accessed as in the example below:

js
await Functions.checkIsNumber["v1_0_0"]({
value: '1'
})

Methods

checkIsNumber

Method responsible for checking whether a value is of the numeric type.

js
const checkedValue = await Functions.checkIsNumber["v1_0_0"]({
value: '1'
})

Required parameters

  • value: Any - expects a value of the any type that will be checked.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the checkedValue constant shown in the previous example, receives a value of the boolean type. If the value passed is of the numeric type, the return is true; otherwise, the return is false.

contains

Method responsible for checking the occurrence of one or more texts in a given string.

js
const contains = await Functions.contains["v1_0_0"]({
text: 'texto de exemplo',
values: ['palavra1', 'palavra2']
})

Required parameters

  • text: String - expects a value of the string type that will be checked.
  • values: Array - expects an array of strings with the words or characters that will be searched for in the text.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the contains constant shown in the previous example, receives a value of the number type representing how many occurrences were found.

convertToNumber

Method responsible for converting a value of the string type into a value of the number type.

js
const number = await Functions.convertToNumber["v1_0_0"]({
value: '1',
})

Required parameters

  • value: Any - expects a value of the any type that will be converted to number.

Optional parameters

  • fractions: Number - expects a value of the number type representing how many decimal places there are in the value.
  • fractionSeparator: String - expects a value of the string type representing the character that will be used to separate the decimal places from the integer part.

Return

The constant or variable created to receive the return of the method, such as the number constant shown in the previous example, receives the value converted to number.

date

Method responsible for formatting and manipulating dates.

js
const formattedDate = await Functions.date["v1_0_0"]({
date: '2024-01-15',
inputFormat: 'YYYY-MM-DD',
outputFormat: 'DD/MM/YYYY',
timeline: [
{ operation: 'ADD', value: 1, unity: 'months' }
]
})

Required parameters

This method has no required parameters.

Optional parameters

  • date: String - date to be manipulated. If it is not provided, it uses the current date.
  • inputFormat: String - format of the input date (e.g. YYYY-MM-DD, DD/MM/YYYY). If it is not provided, it tries to detect it automatically.
  • locale: String - language for the date formatting (e.g. pt-BR, en-US).
  • timeline: Object[] - list of manipulation operations to be applied in sequence. Each object has:
    • operation: String - operation to be performed. Values: ADD | SUBTRACT | START_OF | END_OF.
    • value: Number - amount to be added or subtracted (used in ADD and SUBTRACT).
    • unity: String - time unit. Values: years | months | days | hours | minutes | seconds.
  • outputFormat: String - format of the output date (e.g. DD/MM/YYYY, YYYY-MM-DD HH:mm:ss).

Return

The constant or variable created to receive the return of the method, such as the formattedDate constant shown in the previous example, receives a string with the date formatted according to the outputFormat provided.

inRange

Method responsible for checking whether a value is within a numeric interval.

js
const inRange = await Functions.inRange["v1_0_0"]({
number: 1,
min: 0,
max: 10
})

Required parameters

  • number: Number - expects a value of the number type that will be checked.
  • min: Number - expects a value of the number type representing the minimum value of the interval.
  • max: Number - expects a value of the number type representing the maximum value of the interval.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the inRange constant shown in the previous example, receives a value of the boolean type. If the value passed is within the interval, the return is true; otherwise, the return is false.

join

Method responsible for joining one or more strings.

js
const joined = await Functions.join["v1_0_0"]({
list: ['palavra1', 'palavra2'],
separator: '-'
})

Required parameters

  • list: Any[] - expects an array of anything that will be joined.
  • separator: String - expects a value of the string type representing the character that will be used to separate the strings.

Optional parameters

  • startIndex: Number - expects a value of the number type representing from which position of the array the join will start.
  • endIndex: Number - expects a value of the number type representing up to which position of the array the join will end.

Return

The constant or variable created to receive the return of the method, such as the joined constant shown in the previous example, receives a string with every string joined.

mathExpression

Method responsible for evaluating a mathematical expression, with support for variable substitution.

js
const result = await Functions.mathExpression["v1_0_0"]({
expression: ["x", "+", "y", "*", "2"],
values: { x: 10, y: 5 }
})
// result.expression === "10 + 5 * 2"
// result.result === 20

Required parameters

  • expression: String[] - expects an array of strings that, when joined by a space, form the mathematical expression to be evaluated.

Optional parameters

  • values: Object - expects an object whose keys will be replaced by their respective values in the expression before it is evaluated.

Return

The constant or variable created to receive the return of the method, such as the result constant shown in the previous example, receives an object with the following properties:

  • result.expression: String - the final mathematical expression after the variable substitution.
  • result.result: Any - the numeric result of the expression evaluation.

randomString

Method responsible for generating a random string.

js
const randomString = await Functions.randomString["v1_0_0"]({
length: 10
})

Required parameters

This method has no required parameters.

Optional parameters

  • length: Number - expects a value of the number type representing the size of the string that will be generated. If it is not provided, the default value is 21.

Return

The constant or variable created to receive the return of the method, such as the randomString constant shown in the previous example, receives a random string with the size provided.

replaceAll

Method responsible for replacing every occurrence of one or more texts in a given string.

js
const replaced = await Functions.replaceAll["v1_0_0"]({
from: 'Hello',
to: 'Hello World',
text: 'Hello World'
})

Required parameters

  • from: String|String[] - expects a value of the string type or an array of strings representing the word(s) or character(s) present in the text that will be replaced.
  • to: String - expects a value of the string type that will be the replacement value.
  • text: String - expects a value of the string type in which the values provided in the from parameter will be replaced.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the replaced constant shown in the previous example, receives a string with the values replaced.

split

Method responsible for splitting a string into an array of strings.

js
const splitted = await Functions.split["v1_0_0"]({
text: 'Hello World',
separator: ' '
})

Required parameters

  • text: String - expects a value of the string type that will be split.
  • separator: String - expects a value of the string type representing the character that will be used to separate the strings.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the splitted constant shown in the previous example, receives an object with the following properties:

  • splitted.values: String[] - array with the strings resulting from the split.
  • splitted.count: Number - number of items in the resulting array.

xmlToJson

Method responsible for converting an XML into a JSON object.

js
const json = await Functions.xmlToJson["v1_0_0"]({
xml: '<xml><name>John</name></xml>'
})

Required parameters

  • xml: String - expects a value of the string type representing the XML that will be converted.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the json constant shown in the previous example, receives a JSON object converted from the XML.