Extending the plugin
Add functions & variables!
Parsify uses the math.js parser, so you can easily add and modify variables and functions.
In order to gain access to the parser, use it as the first argument:
1
export default parser => async expression => {
2
// ...
3
};
Copied!
If you are using TypeScript, install @parsify/math as a devDependency and import the Parser type interface.
You can then use the parser according to the math.js documentation:
1
// Set a new variable
2
parser.set('myVariable', 500);
3
parser.get('myVariable');
4
parser.remove('myVariable');
5
6
// Create a function
7
parser.set('hello', name => {
8
return `hello, ${name}!`;
9
});
10
11
/*
12
Remove all functions & variables
13
NOTE: this will not only remove things created by your plugin, so use it carefully.
14
*/
15
parser.clear()
Copied!
Last modified 1mo ago
Copy link