UNPKG

fxparser

Version:

Formula parser designed for Yotta Needs.

37 lines (30 loc) 1.01 kB
let FxParser = require('./lib/index').Parser; let parser = new FxParser(); parser.setVariable('MY_VARIABLE', 5); parser.setVariable('yottaBar', 10); console.log(parser.parse('(1 + MY_VARIABLE + (5 * yottaBar)) / yottaBar')); parser.on('callRangeValue', (startCellCoord, endCellCoord, done) => { // let data = [ // [1, 2, 3, 4, 5], // [6, 7, 8, 9, 110], // [11, 12, 13, 14, 15], // [16, 17, 18, 19, 20], // ]; let data = [ ['ronnie', 'mike', 'sole', 'juan', 'pepe'], ['ronnie', 'mike', 'sole', 'juan', 'pepe'], ]; let fragment = []; for (let row = startCellCoord.row.index; row <= endCellCoord.row.index; row++) { let rowData = data[row]; let colFragment = []; for (let col = startCellCoord.column.index; col <= endCellCoord.column.index; col++) { colFragment.push(rowData[col]); } fragment.push(colFragment); } if (fragment) { done(fragment); } }); console.log(parser.parse('if(COUNTIF(A1:E2, "sole"), COUNTIF(A1:E2, "sole"),0)'));