From 9ad9c0ec6a9b6d470bb32ba6258d41531f3d1223 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 21 May 2018 15:28:15 +0100 Subject: [PATCH] Add $env function to JSONata expressions --- editor/vendor/jsonata/formatter.js | 1 + red/api/editor/locales/en-US/jsonata.json | 8 ++++++-- red/runtime/util.js | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/editor/vendor/jsonata/formatter.js b/editor/vendor/jsonata/formatter.js index 9b0f544c8..6ff26accb 100644 --- a/editor/vendor/jsonata/formatter.js +++ b/editor/vendor/jsonata/formatter.js @@ -117,6 +117,7 @@ '$contains':{ args:[ 'str', 'pattern' ]}, '$count':{ args:[ 'array' ]}, '$each':{ args:[ 'object', 'function' ]}, + '$env': { args:[ 'arg' ]}, '$exists':{ args:[ 'arg' ]}, '$filter':{ args:[ 'array', 'function' ]}, '$floor':{ args:[ 'number' ]}, diff --git a/red/api/editor/locales/en-US/jsonata.json b/red/api/editor/locales/en-US/jsonata.json index 14c7f7cd1..c839c759e 100644 --- a/red/api/editor/locales/en-US/jsonata.json +++ b/red/api/editor/locales/en-US/jsonata.json @@ -190,11 +190,11 @@ }, "$flowContext": { "args": "string", - "desc": "Retrieves a flow context property." + "desc": "Retrieves a flow context property.\n\nThis is a Node-RED defined function." }, "$globalContext": { "args": "string", - "desc": "Retrieves a global context property." + "desc": "Retrieves a global context property.\n\nThis is a Node-RED defined function." }, "$pad": { "args": "string, width [, char]", @@ -215,5 +215,9 @@ "$toMillis": { "args": "timestamp", "desc": "Convert a `timestamp` string in the ISO 8601 format to the number of milliseconds since the Unix Epoch (1 January, 1970 UTC) as a number. An error is thrown if the string is not in the correct format." + }, + "$env": { + "args": "arg", + "desc": "Returns the value of an environment variable.\n\nThis is a Node-RED defined function." } } diff --git a/red/runtime/util.js b/red/runtime/util.js index 1480a841a..257e87777 100644 --- a/red/runtime/util.js +++ b/red/runtime/util.js @@ -359,6 +359,9 @@ function prepareJSONataExpression(value,node) { expr.assign('globalContext',function(val) { return node.context().global.get(val); }); + expr.assign('env', function(val) { + return process.env[val]; + }) expr.registerFunction('clone', cloneMessage, '<(oa)-:o>'); expr._legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(value); return expr;