Skip to content

Commit e4eee07

Browse files
committed
allow custom functions
1 parent b16deb4 commit e4eee07

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

jmespath.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@
11221122

11231123
};
11241124

1125-
function Runtime(interpreter) {
1125+
function Runtime(interpreter, options) {
11261126
this._interpreter = interpreter;
11271127
this.functionTable = {
11281128
// name: [function, <signature>]
@@ -1203,6 +1203,13 @@
12031203
_signature: [{types: [TYPE_ANY], variadic: true}]
12041204
}
12051205
};
1206+
if (options.functionTable) {
1207+
for (var property in options.functionTable) {
1208+
if (options.functionTable.hasOwnProperty(property)) {
1209+
this.functionTable[property] = options.functionTable[property];
1210+
}
1211+
}
1212+
}
12061213
}
12071214

12081215
Runtime.prototype = {
@@ -1653,12 +1660,12 @@
16531660
return lexer.tokenize(stream);
16541661
}
16551662

1656-
function search(data, expression) {
1663+
function search(data, expression, options) {
16571664
var parser = new Parser();
16581665
// This needs to be improved. Both the interpreter and runtime depend on
16591666
// each other. The runtime needs the interpreter to support exprefs.
16601667
// There's likely a clean way to avoid the cyclic dependency.
1661-
var runtime = new Runtime();
1668+
var runtime = new Runtime(undefined, options);
16621669
var interpreter = new TreeInterpreter(runtime);
16631670
runtime._interpreter = interpreter;
16641671
var node = parser.parse(expression);

0 commit comments

Comments
 (0)