mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Add support for moment in jsonata expressions, based on elasticio/jsonata-moment
This commit is contained in:
		
							
								
								
									
										12
									
								
								packages/node_modules/@node-red/util/lib/util.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								packages/node_modules/@node-red/util/lib/util.js
									
									
									
									
										vendored
									
									
								
							| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user