@node-red/util
Advanced tools
Comparing version 1.2.9 to 1.3.0-beta.1
18
index.js
@@ -20,2 +20,4 @@ /*! | ||
const util = require("./lib/util"); | ||
const events = require("./lib/events"); | ||
const exec = require("./lib/exec"); | ||
@@ -35,3 +37,3 @@ /** | ||
log.init(settings); | ||
i18n.init(); | ||
i18n.init(settings); | ||
}, | ||
@@ -59,2 +61,16 @@ | ||
util: util, | ||
/** | ||
* Runtime events | ||
* @mixes @node-red/util_event | ||
* @memberof @node-red/util | ||
*/ | ||
events: events, | ||
/** | ||
* Run system commands with event-log integration | ||
* @mixes @node-red/util_exec | ||
* @memberof @node-red/util | ||
*/ | ||
exec: exec | ||
} |
@@ -25,3 +25,2 @@ /** | ||
var when = require("when"); | ||
var path = require("path"); | ||
@@ -42,5 +41,5 @@ var fs = require("fs-extra"); | ||
var promises = catalogs.map(function(catalog) { | ||
return registerMessageCatalog(catalog.namespace,catalog.dir,catalog.file); | ||
return registerMessageCatalog(catalog.namespace,catalog.dir,catalog.file).catch(err => {}); | ||
}); | ||
return when.settle(promises); | ||
return Promise.all(promises); | ||
} | ||
@@ -52,3 +51,3 @@ | ||
*/ | ||
function registerMessageCatalog(namespace,dir,file) { | ||
async function registerMessageCatalog(namespace,dir,file) { | ||
return initPromise.then(function() { | ||
@@ -141,7 +140,7 @@ return new Promise((resolve,reject) => { | ||
function init() { | ||
function init(settings) { | ||
if (!initPromise) { | ||
// Keep this as a 'when' promise as top-level red.js uses 'otherwise' | ||
// and embedded users of NR may have copied that. | ||
initPromise = when.promise((resolve,reject) => { | ||
initPromise = new Promise((resolve,reject) => { | ||
i18n.use(MessageFileLoader); | ||
@@ -160,3 +159,3 @@ var opt = { | ||
}; | ||
var lang = getCurrentLocale(); | ||
var lang = settings.lang || getCurrentLocale(); | ||
if (lang) { | ||
@@ -163,0 +162,0 @@ opt.lng = lang; |
@@ -1,2 +0,2 @@ | ||
/** | ||
/*! | ||
* Copyright JS Foundation and other contributors, http://js.foundation | ||
@@ -15,3 +15,2 @@ * | ||
* limitations under the License. | ||
* @ignore | ||
**/ | ||
@@ -95,3 +94,3 @@ | ||
} | ||
util.log("["+levelNames[msg.level]+"] "+(msg.type?"["+msg.type+":"+(msg.name||msg.id)+"] ":"")+message); | ||
@@ -98,0 +97,0 @@ } |
@@ -192,2 +192,8 @@ /** | ||
* | ||
* If `msg` is provided, any internal cross-references will be evaluated against that | ||
* object. Otherwise, it will return a nested set of properties | ||
* | ||
* For example, without msg set, 'a[msg.foo]' returns `['a', [ 'msg', 'foo'] ]` | ||
* But if msg is set to '{"foo": "bar"}', 'a[msg.foo]' returns `['a', 'bar' ]` | ||
* | ||
* @param {String} str - the property expression | ||
@@ -197,3 +203,3 @@ * @return {Array} the normalised expression | ||
*/ | ||
function normalisePropertyExpression(str) { | ||
function normalisePropertyExpression(str, msg, toString) { | ||
// This must be kept in sync with validatePropertyExpression | ||
@@ -210,2 +216,3 @@ // in editor/js/ui/utils.js | ||
var inBox = false; | ||
var boxExpression = false; | ||
var quoteChar; | ||
@@ -253,4 +260,50 @@ var v; | ||
} | ||
// Next char is either a quote or a number | ||
if (!/["'\d]/.test(str[i+1])) { | ||
// Start of a new expression. If it starts with msg it is a nested expression | ||
// Need to scan ahead to find the closing bracket | ||
if (/^msg[.\[]/.test(str.substring(i+1))) { | ||
var depth = 1; | ||
var inLocalString = false; | ||
var localStringQuote; | ||
for (var j=i+1;j<length;j++) { | ||
if (/["']/.test(str[j])) { | ||
if (inLocalString) { | ||
if (str[j] === localStringQuote) { | ||
inLocalString = false | ||
} | ||
} else { | ||
inLocalString = true; | ||
localStringQuote = str[j] | ||
} | ||
} | ||
if (str[j] === '[') { | ||
depth++; | ||
} else if (str[j] === ']') { | ||
depth--; | ||
} | ||
if (depth === 0) { | ||
try { | ||
if (msg) { | ||
var crossRefProp = getMessageProperty(msg, str.substring(i+1,j)); | ||
if (crossRefProp === undefined) { | ||
throw createError("INVALID_EXPR","Invalid expression: undefined reference at position "+(i+1)+" : "+str.substring(i+1,j)) | ||
} | ||
parts.push(crossRefProp) | ||
} else { | ||
parts.push(normalisePropertyExpression(str.substring(i+1,j), msg)); | ||
} | ||
inBox = false; | ||
i = j; | ||
start = j+1; | ||
break; | ||
} catch(err) { | ||
throw createError("INVALID_EXPR","Invalid expression started at position "+(i+1)) | ||
} | ||
} | ||
} | ||
if (depth > 0) { | ||
throw createError("INVALID_EXPR","Invalid property expression: unmatched '[' at position "+i); | ||
} | ||
continue; | ||
} else if (!/["'\d]/.test(str[i+1])) { | ||
// Next char is either a quote or a number | ||
throw createError("INVALID_EXPR","Invalid property expression: unexpected "+str[i+1]+" at position "+(i+1)); | ||
@@ -301,2 +354,19 @@ } | ||
} | ||
if (toString) { | ||
var result = parts.shift(); | ||
while(parts.length > 0) { | ||
var p = parts.shift(); | ||
if (typeof p === 'string') { | ||
if (/"/.test(p)) { | ||
p = "'"+p+"'"; | ||
} else { | ||
p = '"'+p+'"'; | ||
} | ||
} | ||
result = result+"["+p+"]"; | ||
} | ||
return result; | ||
} | ||
return parts; | ||
@@ -348,4 +418,3 @@ } | ||
var result = null; | ||
var msgPropParts = normalisePropertyExpression(expr); | ||
var m; | ||
var msgPropParts = normalisePropertyExpression(expr,msg); | ||
msgPropParts.reduce(function(obj, key) { | ||
@@ -390,3 +459,3 @@ result = (typeof obj[key] !== "undefined" ? obj[key] : undefined); | ||
} | ||
var msgPropParts = normalisePropertyExpression(prop); | ||
var msgPropParts = normalisePropertyExpression(prop, msg); | ||
var depth = 0; | ||
@@ -563,2 +632,6 @@ var length = msgPropParts.length; | ||
var contextKey = parseContextStore(value); | ||
if (/\[msg/.test(contextKey.key)) { | ||
// The key has a nest msg. reference to evaluate first | ||
contextKey.key = normalisePropertyExpression(contextKey.key, msg, true) | ||
} | ||
result = node.context()[type].get(contextKey.key,contextKey.store,callback); | ||
@@ -565,0 +638,0 @@ if (callback) { |
{ | ||
"name": "@node-red/util", | ||
"version": "1.2.9", | ||
"version": "1.3.0-beta.1", | ||
"license": "Apache-2.0", | ||
@@ -23,5 +23,4 @@ "repository": { | ||
"lodash.clonedeep": "^4.5.0", | ||
"moment-timezone": "0.5.32", | ||
"when": "3.7.8" | ||
"moment-timezone": "0.5.32" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64309
6
9
1537
2
1
- Removedwhen@3.7.8
- Removedwhen@3.7.8(transitive)