1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add support for moment in jsonata expressions, based on elasticio/jsonata-moment

This commit is contained in:
dxdc 2020-05-27 23:26:57 -05:00 committed by GitHub
parent bcf1d986a4
commit effff3405b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@
const clone = require("clone");
const jsonata = require("jsonata");
const moment = require("moment");
const safeJSONStringify = require("json-stringify-safe");
const util = require("util");
@ -558,10 +559,10 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
*/
function prepareJSONataExpression(value,node) {
var expr = jsonata(value);
expr.assign('flowContext',function(val, store) {
expr.assign('flowContext', function(val, store) {
return node.context().flow.get(val, store);
});
expr.assign('globalContext',function(val, store) {
expr.assign('globalContext', function(val, store) {
return node.context().global.get(val, store);
});
expr.assign('env', function(name) {
@ -569,9 +570,12 @@ function prepareJSONataExpression(value,node) {
if (typeof val !== 'undefined') {
return val;
} else {
return ""
return "";
}
})
});
expr.assign('moment', function(arg1, arg2, arg3, arg4) {
return moment(arg1, arg2, arg3, arg4);
});
expr.registerFunction('clone', cloneMessage, '<(oa)-:o>');
expr._legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(value);
expr._node = node;