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

Tidying up the Change node after a lot of churn

This commit is contained in:
Nick O'Leary 2013-12-24 23:16:36 +00:00
parent 74f43f4059
commit 24c373ecc2
2 changed files with 6 additions and 8 deletions

View File

@ -96,7 +96,7 @@
$("#node-from-row").hide();
$("#node-to-row").show();
$("#node-reg-row").hide();
$("#node-tip").html("Tip: expects a new property name and either a fixed value OR the full name of another msg.property eg: msg.sentiment.score");
$("#node-tip").html("Tip: expects a new property name and either a fixed value OR the full name of another message property eg: msg.sentiment.score");
}
if (a === "delete") {
$("#node-input-todo").html("called");
@ -114,7 +114,7 @@
$("#node-from-row").show();
$("#node-to-row").show();
$("#node-reg-row").show();
$("#node-tip").html("Tip: If <i>contains</i> is a regex, you <b>must</b> escape any special characters. Likewise <i>replace with</i> can accept regex results. Only works on strings.");
$("#node-tip").html("Tip: only works on string properties. If regular expressions are used, the <i>replace with</i> field can contain capture results, eg $1.");
}
//if (a === "replace") {
// $("#node-input-todo").html("called");

View File

@ -24,7 +24,9 @@ function ChangeNode(n) {
this.to = n.to || " ";
this.reg = (n.reg === null || n.reg);
var node = this;
if (node.reg === false) {
this.from = this.from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
var makeNew = function( stem, path, value ) {
var lastPart = (arguments.length === 3) ? path.pop() : false;
for (var i = 0; i < path.length; i++) {
@ -36,12 +38,8 @@ function ChangeNode(n) {
this.on('input', function (msg) {
if (node.action == "change") {
var from = node.from;
if (node.reg === false) {
from = from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
try {
node.re = new RegExp(from, "g");
node.re = new RegExp(this.from, "g");
} catch (e) {
node.error(e.message);
}