json-formula
json-formula copied to clipboard
Example of how to add a custom function with signature using constants
Hi there,
I need to add a custom function to the JSONFormula instance. While I have been able to define and add the function, I'm having trouble specifying the data types for the function signature using the constants such as "TYPE_STRING" as I am unable to import it.
Expected Behaviour
"dataTypes" must be imported in some way.
Actual Behaviour
I am not able to import dataTypes constants.
Sample Code that illustrates the problem
I installed the package using NPM:
npm install @adobe/json-formula
import JsonFormula, { dataTypes } from "@adobe/json-formula"; // "import JsonFormula, { TYPE_STRING } from "@adobe/json-formula";" also does not work.
function test () {
const customFunctions = {
myFunc: {
_func: resolvedArgs => console.log(resolvedArgs[0]),
_signature: [{ types: [dataTypes.TYPE_STRING] }] // <= "dataTypes" is not imported resulting in "undefined", using a '2' works though.
}
};
const instance = new JsonFormula(customFunctions, 'null', []);
}
Could you please provide an example of how to add custom signatured functions?
Thanks!