@mschaeffler/node-red-logic 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/counter.html +32 -0
  2. package/counter.js +30 -0
  3. package/package.json +2 -1
package/counter.html ADDED
@@ -0,0 +1,32 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('counter',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""}
7
+ },
8
+ inputs:1,
9
+ outputs:1,
10
+ icon: "font-awesome/fa-list-ol",
11
+ label: function() {
12
+ return this.name||"counter";
13
+ },
14
+ inputLabels: 'input',
15
+ outputLabels: 'output'
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="counter">
20
+ <div class="form-row">
21
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-input-name" placeholder="Name">
23
+ </div>
24
+ </script>
25
+
26
+ <script type="text/html" data-help-name="counter">
27
+
28
+ <p>A node that just count the messages.</p>
29
+
30
+ <h3>Input</h3>
31
+
32
+ </script>
package/counter.js ADDED
@@ -0,0 +1,30 @@
1
+ module.exports = function(RED) {
2
+
3
+ function CounterNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
6
+ var node = this;
7
+ var context = this.context();
8
+
9
+ node.on('input', function(msg,send,done) {
10
+ let data = context.get( "data" ) ?? 0;
11
+ if( msg.reset || msg.topic==="init" )
12
+ {
13
+ data = 0;
14
+ }
15
+ else
16
+ {
17
+ data++;
18
+ }
19
+ context.set( "data", data );
20
+
21
+ msg.count = data;
22
+
23
+ node.status( data );
24
+ send( msg );
25
+ done();
26
+ });
27
+ }
28
+
29
+ RED.nodes.registerType("counter",CounterNode);
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "nodes for simple mathematical operations.",
5
5
  "license": "LGPL-2.1",
6
6
  "homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",
@@ -20,6 +20,7 @@
20
20
  "or":"logic_or.js",
21
21
  "and":"logic_and.js",
22
22
  "tobool":"logic_bool.js",
23
+ "counter":"counter.js",
23
24
  "plus":"math_plus.js"
24
25
  }
25
26
  },