How to create a data adaptor
Data adaptors transform input to output programmatically. To create a new adaptor, you need to provide a description of the input and output arguments (in a manifest.json file) and also provide the JavaScript function which transforms input to output programmatically (in a index.js file). This guides shows you how to create a new data adaptor which takes a text as input and returns the number of non-whitespace characters as an output.

Create a new adaptor folder

Adaptors are defined as subfolders underadaptors folder inside the root of the engine.
1
- engine
2
- adaptors
3
- text-length
4
- manifest.json
5
- index.js
Copied!

Define descriptions of the input and output arguments

Both input and output arguments are defined in the manifest.json file under input and output arrays. Each argument has a name, a data type, and an optional description as follows:
1
{
2
"description": "Counts the number of non-whitespace characters in a text.",
3
"category": "Text Manipulation",
4
"input": [
5
{
6
"name": "text",
7
"type": "text",
8
"description": "A text to be counted."
9
}
10
],
11
"output": [
12
{
13
"name": "length",
14
"type": "number",
15
"description": "The number of non-whitespace characters in the input text."
16
}
17
]
18
}
Copied!

Define transformation function

A JavaScript function, which transforms input to output programmatically, should be defined in theindex.js file
1
module.exports = function (args) {
2
const cleanedText = args.text.replace(/\s*/g, ''); // replace non-whitespace characters with an empty string
3
return {
4
length: cleanedText.length;
5
};
6
};
Copied!
Last modified 22h ago