Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 838cdc3

Browse files
committed
2.3.0
1 parent 96ee511 commit 838cdc3

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

dist/formula-parser.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12550,7 +12550,9 @@ var Parser = function (_Emitter) {
1255012550
return _this._callVariable(variable);
1255112551
},
1255212552
evaluateByOperator: _evaluateByOperator2['default'],
12553-
callFunction: _evaluateByOperator2['default'],
12553+
callFunction: function callFunction(name, params) {
12554+
return _this._callFunction(name, params);
12555+
},
1255412556
cellValue: function cellValue(value) {
1255512557
return _this._callCellValue(value);
1255612558
},
@@ -12559,6 +12561,7 @@ var Parser = function (_Emitter) {
1255912561
}
1256012562
};
1256112563
_this.variables = Object.create(null);
12564+
_this.functions = Object.create(null);
1256212565

1256312566
_this.setVariable('TRUE', true).setVariable('FALSE', false).setVariable('NULL', null);
1256412567
return _this;
@@ -12655,6 +12658,62 @@ var Parser = function (_Emitter) {
1265512658
return value;
1265612659
};
1265712660

12661+
/**
12662+
* Set custom function which can be visible while parsing formula expression.
12663+
*
12664+
* @param {String} name Custom function name.
12665+
* @param {Function} fn Custom function.
12666+
* @returns {Parser}
12667+
*/
12668+
12669+
12670+
Parser.prototype.setFunction = function setFunction(name, fn) {
12671+
this.functions[name] = fn;
12672+
12673+
return this;
12674+
};
12675+
12676+
/**
12677+
* Get custom function.
12678+
*
12679+
* @param {String} name Custom function name.
12680+
* @returns {*}
12681+
*/
12682+
12683+
12684+
Parser.prototype.getFunction = function getFunction(name) {
12685+
return this.functions[name];
12686+
};
12687+
12688+
/**
12689+
* Call function with provided params.
12690+
*
12691+
* @param name Function name.
12692+
* @param params Function params.
12693+
* @returns {*}
12694+
* @private
12695+
*/
12696+
12697+
12698+
Parser.prototype._callFunction = function _callFunction(name) {
12699+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
12700+
12701+
var fn = this.getFunction(name);
12702+
var value = void 0;
12703+
12704+
if (fn) {
12705+
value = fn(params);
12706+
}
12707+
12708+
this.emit('callFunction', name, params, function (newValue) {
12709+
if (newValue !== void 0) {
12710+
value = newValue;
12711+
}
12712+
});
12713+
12714+
return value === void 0 ? (0, _evaluateByOperator2['default'])(name, params) : value;
12715+
};
12716+
1265812717
/**
1265912718
* Retrieve value by its label (`B3`, `B$3`, `B$3`, `$B$3`).
1266012719
*

dist/formula-parser.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hot-formula-parser",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Formula parser",
55
"browser": "dist/formula-parser.js",
66
"main": "lib/index.js",

0 commit comments

Comments
 (0)