Home Installation Install Documentation Docs Versions Demo

NovaSheets Class

Add custom functions to the NovaSheets parser using the NovaSheets class, which is the default import of require('novasheets') (in Node) or the script import (in a browser).

Initialize

Use new NovaSheets() to instantiate the class and set it to a variable, ready for functions to be added:

const sheet = new NovaSheets();

Adding functions

Use the addFunction method to register functions with the NovaSheets parser, using the syntax addFunction(name, function), where function has its first argument being the whole function match ($(...)) and the remainder being each individual argument.

Examples

  1. Register $(#one) as a function that returns 1:
    const sheet = new NovaSheets();
    sheet.addFunction('#one', () => 1); // set '$(#one)' to return '1'
    NovaSheets.parse('#one', sheet); // '1'
    
  2. Register $(add squares) as a function that returns the sum of the squares of two numbers:
    const sheet = new NovaSheets();
    sheet.addFunction('add squares', (match, num1, num2) => {
        return num1 * num1 + num2 * num2;
    });
    NovaSheets.parse('$(add squares | 20 | 4)', sheet); // 416