How to create a data adaptor

Data adaptor transform input to output programmatically. To create a new adaptor, you need to provide description of the input and output arguments (in a manifest.json file) and aldo 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.

- engine
- adaptors
- text-length
- manifest.json
- index.js

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 have a name, a data type, and an optional description as follows:

{
"description": "Counts the number of non-whitespace characters in a text.",
"category": "Text Manipulation",
"input": [
{
"name": "text",
"type": "text",
"description": "A text to be counted."
}
],
"output": [
{
"name": "length",
"type": "number",
"description": "The number of non-whitespace characters in the input text."
}
]
}

Define transformation function

A JavaScript function, which transforms input to output programmatically, should be defined in theindex.js file

module.exports = function (args) {
const cleanedText = args.text.replace(/\s*/g, ''); // replace non-whitespace characters with an empty string
return {
length: cleanedText.length;
};
};