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

View File

@ -828,6 +828,20 @@ RED.utils = (function() {
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 {
createObjectElement: buildMessageElement,
@ -839,6 +853,7 @@ RED.utils = (function() {
getNodeIcon: getNodeIcon,
getNodeLabel: getNodeLabel,
addSpinnerOverlay: addSpinnerOverlay,
decodeObject: decodeObject
decodeObject: decodeObject,
parseContextKey: parseContextKey
}
})();