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

Add RED.utils.parseContextKey

This commit is contained in:
Nick O'Leary 2018-07-10 11:41:46 +01:00
parent f8aa4a9588
commit d8cf86fd6f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 20 additions and 10 deletions

View File

@ -15,16 +15,11 @@
**/ **/
(function($) { (function($) {
var contextParse = function(v) { var contextParse = function(v) {
var parts = {}; var parts = RED.utils.parseContextKey(v);
var m = /^#:\((\S+?)\)::(.*)$/.exec(v); return {
if (m) { option: parts.store,
parts.option = m[1]; value: parts.key
parts.value = m[2];
} else {
parts.value = v;
parts.option = RED.settings.context.default;
} }
return parts;
} }
var contextExport = function(v,opt) { var contextExport = function(v,opt) {
if (!opt) { if (!opt) {

View File

@ -828,6 +828,20 @@ RED.utils = (function() {
return payload; return payload;
} }
function parseContextKey(key) {
var parts = {};
var m = /^#:\((\S+?)\)::(.*)$/.exec(key);
if (m) {
parts.store = m[1];
parts.key = m[2];
} else {
parts.key = key;
if (RED.settings.context) {
parts.store = RED.settings.context.default;
}
}
return parts;
}
return { return {
createObjectElement: buildMessageElement, createObjectElement: buildMessageElement,
@ -839,6 +853,7 @@ RED.utils = (function() {
getNodeIcon: getNodeIcon, getNodeIcon: getNodeIcon,
getNodeLabel: getNodeLabel, getNodeLabel: getNodeLabel,
addSpinnerOverlay: addSpinnerOverlay, addSpinnerOverlay: addSpinnerOverlay,
decodeObject: decodeObject decodeObject: decodeObject,
parseContextKey: parseContextKey
} }
})(); })();