# node-red-contrib-boolean-logic-ultimate | # node-red-contrib-boolean-logic-ultimate | ||||
<p> | <p> | ||||
<b>Version 1.0.0 LTS</b><br/> | |||||
- Added Filter node<br/> | |||||
</p> | |||||
<p> | |||||
<b>Version 0.0.8</b><br/> | <b>Version 0.0.8</b><br/> | ||||
- Delete persistent states when a new unexpected topic arrrives<br/> | - Delete persistent states when a new unexpected topic arrrives<br/> | ||||
- Better status representation<br/> | - Better status representation<br/> |
<br> | <br> | ||||
The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n | The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n | ||||
</p> | </p> | ||||
<p> | |||||
<b>Invert Ultimate</b><br /> | |||||
Outputs the inverted input. For example true -> false | |||||
</p> | |||||
<p> | |||||
<b>Filter Ultimate</b><br /> | |||||
This node has 2 outputs.<br /> | |||||
If the input payload is true, the node will send <code>true</code> on output 1 and nothing on oputput 2<br /> | |||||
If the input payload is false, the node will send nothing on output 1, and <code>false</code> on oputput 2<br /> | |||||
</p> | |||||
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg | [license-image]: https://img.shields.io/badge/license-MIT-blue.svg | ||||
[license-url]: https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/LICENSE | [license-url]: https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/LICENSE |
# node-red-contrib-boolean-logic-ultimate | # node-red-contrib-boolean-logic-ultimate | ||||
<p> | <p> | ||||
<b>Version 0.0.9 LTS (Long term stable)</b><br/> | |||||
<b>Version 1.0.0 LTS (Long term stable)</b><br/> | |||||
- For invert node, changed the category in the palette list to match the boolean logic ultimate's category<br/> | - For invert node, changed the category in the palette list to match the boolean logic ultimate's category<br/> | ||||
</p> | </p> | ||||
<p> | <p> |
<script type="text/javascript"> | |||||
RED.nodes.registerType('FilterUltimate',{ | |||||
category: 'boolean logic ultimate', | |||||
color: '#ff8080', | |||||
defaults: { | |||||
name: { | |||||
value: "Filter" | |||||
} | |||||
}, | |||||
inputs:1, | |||||
outputs:2, | |||||
outputLabels: function(i) { | |||||
var ret=""; | |||||
switch (i) { | |||||
case 0: | |||||
return "True"; | |||||
break; | |||||
case 1: | |||||
return "False"; | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
}, | |||||
icon: "switch.png", | |||||
label: | |||||
function() { | |||||
return this.name||"Filter"; | |||||
}, | |||||
paletteLabel: function() { | |||||
return "FilterUltimate"; | |||||
} | |||||
}); | |||||
</script> | |||||
<script type="text/x-red" data-template-name="FilterUltimate"> | |||||
<div class="form-row"> | |||||
<label for="node-input-name"><i class="icon-tag"></i> Name (topic)</label> | |||||
<input type="text" id="node-input-name" placeholder="Name"> | |||||
</div> | |||||
</script> | |||||
<script type="text/x-red" data-help-name="FilterUltimate"> | |||||
<p>The node emits on output "true", only input payloads that are true<br/> | |||||
and on the output "false", only input payload that are false. | |||||
</p> | |||||
</script> |
module.exports = function(RED) { | |||||
function FilterUltimate(config) { | |||||
RED.nodes.createNode(this,config); | |||||
this.config = config; | |||||
var node = this; | |||||
node.status( {fill: "grey" ,shape: "dot" ,text: "Waiting"}); | |||||
this.on('input', function (msg) { | |||||
var sTopic = node.config.name; | |||||
if (msg.hasOwnProperty("topic")){ | |||||
sTopic = (msg.topic === "" ? sTopic : msg.topic); | |||||
} | |||||
if (typeof msg.payload !== "undefined") { | |||||
var bRes = ToBoolean(msg.payload); | |||||
if (typeof bRes === "undefined") return; | |||||
var msgTrue = { | |||||
topic: sTopic, | |||||
payload: true | |||||
}; | |||||
var msgFalse = { | |||||
topic: sTopic, | |||||
payload: false | |||||
}; | |||||
if (bRes === true) { | |||||
node.status( {fill: "green" ,shape: "dot" ,text: "(Send) true,null"}); | |||||
node.send([msgTrue, null]); | |||||
} else | |||||
{ | |||||
node.status( {fill: "green" ,shape: "dot" ,text: "(Send) null,false"}); | |||||
node.send([null, msgFalse]); | |||||
} | |||||
return; | |||||
} | |||||
}); | |||||
function ToBoolean( value ) { | |||||
var res = false; | |||||
if (typeof value === 'boolean') { | |||||
res = value; | |||||
} | |||||
else if( typeof value === 'number' || typeof value === 'string' ) { | |||||
// Is it formated as a decimal number? | |||||
if( decimal.test( value ) ) { | |||||
var v = parseFloat( value ); | |||||
res = v != 0; | |||||
} | |||||
else { | |||||
res = value.toLowerCase() === "true"; | |||||
} | |||||
} | |||||
return res; | |||||
}; | |||||
} | |||||
RED.nodes.registerType("FilterUltimate",FilterUltimate); | |||||
} |
}, | }, | ||||
inputs:1, | inputs:1, | ||||
outputs:1, | outputs:1, | ||||
icon: "serial.png", | |||||
icon: "swap.png", | |||||
label: | label: | ||||
function() { | function() { | ||||
return this.name||"Invert"; | return this.name||"Invert"; |
{ | { | ||||
"name": "node-red-contrib-boolean-logic-ultimate", | "name": "node-red-contrib-boolean-logic-ultimate", | ||||
"version": "0.0.9", | |||||
"version": "1.0.0", | |||||
"description": "A set of Node-RED enhanced boolean logic, with persisten values after reboot and more", | "description": "A set of Node-RED enhanced boolean logic, with persisten values after reboot and more", | ||||
"author": "Supergiovane (https://github.com/Supergiovane)", | "author": "Supergiovane (https://github.com/Supergiovane)", | ||||
"dependencies": { | "dependencies": { | ||||
"keywords": [ | "keywords": [ | ||||
"node-red", | "node-red", | ||||
"boolean", | "boolean", | ||||
"gate", | |||||
"filter", | |||||
"logic" | "logic" | ||||
], | ], | ||||
"license": "MIT", | "license": "MIT", | ||||
"node-red": { | "node-red": { | ||||
"nodes": { | "nodes": { | ||||
"BooleanLogicUltimate": "boolean-logic-ultimate/BooleanLogicUltimate.js", | "BooleanLogicUltimate": "boolean-logic-ultimate/BooleanLogicUltimate.js", | ||||
"InvertUltimate": "boolean-logic-ultimate/InvertUltimate.js" | |||||
"InvertUltimate": "boolean-logic-ultimate/InvertUltimate.js", | |||||
"FilterUltimate": "boolean-logic-ultimate/FilterUltimate.js" | |||||
} | } | ||||
} | } | ||||
} | } |
{ | { | ||||
"name": "node-red-contrib-boolean-logic-ultimate", | "name": "node-red-contrib-boolean-logic-ultimate", | ||||
"version": "0.0.1", | |||||
"version": "0.0.8", | |||||
"lockfileVersion": 1, | "lockfileVersion": 1, | ||||
"requires": true, | "requires": true, | ||||
"dependencies": { | "dependencies": { |
"node-red": { | "node-red": { | ||||
"nodes": { | "nodes": { | ||||
"BooleanLogicUltimate": "boolean-logic-ultimate/BooleanLogicUltimate.js", | "BooleanLogicUltimate": "boolean-logic-ultimate/BooleanLogicUltimate.js", | ||||
"InvertUltimate": "boolean-logic-ultimate/InvertUltimate.js" | |||||
"InvertUltimate": "boolean-logic-ultimate/InvertUltimate.js", | |||||
"FilterUltimate": "boolean-logic-ultimate/FilterUltimate.js" | |||||
} | } | ||||
} | } | ||||
} | } |