Initial commit
This commit is contained in:
14
node_modules/node-red-node-random/LICENSE
generated
vendored
Normal file
14
node_modules/node-red-node-random/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
Copyright 2016,2020 JS Foundation and other contributors, https://js.foundation/
|
||||
Copyright 2013-2016 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
24
node_modules/node-red-node-random/README.md
generated
vendored
Normal file
24
node_modules/node-red-node-random/README.md
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# node-red-node-random
|
||||
|
||||
A <a href="http://nodered.org" target="_new">Node-RED</a> node that when triggered generates a random number between two values.
|
||||
|
||||
## Install
|
||||
|
||||
Either use the Manage Palette option in the Node-RED Editor menu, or run the following command in your Node-RED user directory - typically `~/.node-red`
|
||||
|
||||
npm i node-red-node-random
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
A simple node to generate a random number when triggered.
|
||||
|
||||
If set to return an integer it can include both the low and high values.
|
||||
`min <= n <= max` - so selecting 1 to 6 will return values 1,2,3,4,5 or 6.
|
||||
|
||||
If set to return a floating point value it will be from the low value, up to, but
|
||||
**not** including the high value. `min <= n < max` - so selecting 1 to 6 will return values 1 <= n < 6 .
|
||||
|
||||
You can dynamically pass in the 'From' and 'To' values to the node using msg.to and/or msg.from. **NOTE:** hard coded values in the node **always take precedence**.
|
||||
|
||||
**Note:** This returns numbers - objects of type **number**.
|
||||
13
node_modules/node-red-node-random/locales/de/random.json
generated
vendored
Normal file
13
node_modules/node-red-node-random/locales/de/random.json
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"random": {
|
||||
"label": {
|
||||
"generate": "Generiere",
|
||||
"wholeNumber": "eine Ganzzahl (integer)",
|
||||
"realNumber": "eine reelle Zahl (floating point)",
|
||||
"from": "Von",
|
||||
"lowestNumber": "kleinste Zahl",
|
||||
"to": "Bis",
|
||||
"highestNumber": "größte Zahl"
|
||||
}
|
||||
}
|
||||
}
|
||||
16
node_modules/node-red-node-random/locales/en-US/random.html
generated
vendored
Normal file
16
node_modules/node-red-node-random/locales/en-US/random.html
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<script type="text/html" data-help-name="random">
|
||||
<p>Generates a random number between a low and high value. Defaults to 1 to 10.</p>
|
||||
<p>If left blank <code>from</code> and <code>to</code> can be set dynamically as below.</p>
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>from <span class="property-type">number</span></dt>
|
||||
<dd>containing the low value to be used.</dd>
|
||||
<dt>to <span class="property-type">number</span></dt>
|
||||
<dd>containing the high value to be used.</dd>
|
||||
</dl>
|
||||
<h3>Details</h3>
|
||||
<p>If set to return an integer it can <i>include</i> both the low and high values.
|
||||
<code>min <= n <= max</code></p>
|
||||
<p>If set to return a floating point value it will be from the low value, up to, but
|
||||
not including the high value. <code>min <= n < max</code></p>
|
||||
</script>
|
||||
13
node_modules/node-red-node-random/locales/en-US/random.json
generated
vendored
Normal file
13
node_modules/node-red-node-random/locales/en-US/random.json
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"random": {
|
||||
"label": {
|
||||
"generate": "Generate",
|
||||
"wholeNumber": "a whole number - integer",
|
||||
"realNumber": "a real number - floating point",
|
||||
"from": "From",
|
||||
"lowestNumber": "lowest number",
|
||||
"to": "To",
|
||||
"highestNumber": "highest number"
|
||||
}
|
||||
}
|
||||
}
|
||||
16
node_modules/node-red-node-random/locales/ja/random.html
generated
vendored
Normal file
16
node_modules/node-red-node-random/locales/ja/random.html
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<script type="text/html" data-help-name="random">
|
||||
<p>最小値と最大値との間の乱数を生成します。デフォルトは1から10です。</p>
|
||||
<p><code>最小</code> や <code>最大</code> を空にした場合は、以下の様に動的に値を設定できます。</p>
|
||||
<h3>入力</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>from <span class="property-type">数値</span></dt>
|
||||
<dd>使用する最小値を含みます。</dd>
|
||||
<dt>to <span class="property-type">数値</span></dt>
|
||||
<dd>使用する最大値を含みます。</dd>
|
||||
</dl>
|
||||
<h3>詳細</h3>
|
||||
<p>整数値を返すように設定した場合は、乱数には最大値と最小値の両方が<i>含まれます</i>。
|
||||
<code>min <= n <= max</code></p>
|
||||
<p>浮動小数点値を返すように設定した場合、乱数は最小値から最大値未満の値を含み、最大値は含まれません。
|
||||
<code>min <= n < max</code></p>
|
||||
</script>
|
||||
13
node_modules/node-red-node-random/locales/ja/random.json
generated
vendored
Normal file
13
node_modules/node-red-node-random/locales/ja/random.json
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"random": {
|
||||
"label": {
|
||||
"generate": "生成",
|
||||
"wholeNumber": "整数 - 整数値",
|
||||
"realNumber": "実数 - 浮動小数点",
|
||||
"from": "最小",
|
||||
"lowestNumber": "最小値",
|
||||
"to": "最大",
|
||||
"highestNumber": "最大値"
|
||||
}
|
||||
}
|
||||
}
|
||||
27
node_modules/node-red-node-random/package.json
generated
vendored
Normal file
27
node_modules/node-red-node-random/package.json
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name" : "node-red-node-random",
|
||||
"version" : "0.4.1",
|
||||
"description" : "A Node-RED node that when triggered generates a random number between two values.",
|
||||
"dependencies" : {
|
||||
},
|
||||
"repository" : {
|
||||
"type":"git",
|
||||
"url":"https://github.com/node-red/node-red-nodes.git",
|
||||
"directory": "tree/master/function/random"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [ "node-red", "random" ],
|
||||
"node-red" : {
|
||||
"nodes" : {
|
||||
"random": "random.js"
|
||||
}
|
||||
},
|
||||
"author": {
|
||||
"name": "Dave Conway-Jones",
|
||||
"email": "ceejay@vnet.ibm.com",
|
||||
"url": "http://nodered.org"
|
||||
},
|
||||
"contributors": [
|
||||
{"name": "@zenofmud"}
|
||||
]
|
||||
}
|
||||
55
node_modules/node-red-node-random/random.html
generated
vendored
Normal file
55
node_modules/node-red-node-random/random.html
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<script type="text/html" data-template-name="random">
|
||||
<div class="form-row">
|
||||
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="node-red:common.label.property"></span></label>
|
||||
<input type="text" id="node-input-property" style="width:70%;"/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-inte"><i class="fa fa-random"></i> <span data-i18n="random.label.generate"></label>
|
||||
<select type="text" id="node-input-inte" style="width:70%;">
|
||||
<option value="true" data-i18n="random.label.wholeNumber"></option>
|
||||
<option value="false" data-i18n="random.label.realNumber"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-low"><i class="fa fa-arrow-down"></i> <span data-i18n="random.label.from"></label>
|
||||
<input type="text" id="node-input-low" data-i18n="[placeholder]random.label.lowestNumber" style="width:70%;">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-high"><i class="fa fa-arrow-up"></i> <span data-i18n="random.label.to"></label>
|
||||
<input type="text" id="node-input-high" data-i18n="[placeholder]random.label.highestNumber" style="width:70%;">
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name" style="width:70%;">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('random',{
|
||||
category: 'function',
|
||||
color:"#E2D96E",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
low: {value: 1,validate:function(v) { return !isNaN(v) || v.length === 0;} },
|
||||
high: {value: 10,validate:function(v) { return !isNaN(v) || v.length === 0;} },
|
||||
inte: {value:"true"},
|
||||
property: {value:"payload",required:true}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "debug.png",
|
||||
label: function() {
|
||||
return this.name||"random";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.property === undefined) {
|
||||
$("#node-input-property").val("payload");
|
||||
}
|
||||
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
74
node_modules/node-red-node-random/random.js
generated
vendored
Normal file
74
node_modules/node-red-node-random/random.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
function RandomNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
this.low = n.low
|
||||
this.high = n.high
|
||||
this.inte = n.inte || false;
|
||||
this.property = n.property||"payload";
|
||||
var node = this;
|
||||
var tmp = {};
|
||||
|
||||
this.on("input", function(msg) {
|
||||
|
||||
tmp.low = 1 // set this as the default low value
|
||||
tmp.low_e = ""
|
||||
if (node.low) { // if the the node has a value use it
|
||||
tmp.low = Number(node.low);
|
||||
} else if ('from' in msg) { // else see if a 'from' is in the msg
|
||||
tmp.low = Number(msg.from);
|
||||
if (isNaN(msg.from)) { // if it isn't a number setup NaN error
|
||||
tmp.low = NaN;
|
||||
tmp.low_e = " From: " + msg.from; // setup to show bad incoming msg.from
|
||||
}
|
||||
}
|
||||
|
||||
tmp.high = 10 // set this as the default high value
|
||||
tmp.high_e = "";
|
||||
if (node.high) { // if the the node has a value use it
|
||||
tmp.high = Number(node.high);
|
||||
} else if ('to' in msg) { // else see if a 'to' is in the msg
|
||||
tmp.high = Number(msg.to);
|
||||
if (isNaN(msg.to)) { // if it isn't a number setup NaN error
|
||||
tmp.high = NaN
|
||||
tmp.high_e = " To: " + msg.to // setup to show bad incoming msg.to
|
||||
}
|
||||
}
|
||||
|
||||
// if tmp.low or high are not numbers, send an error msg with bad values
|
||||
if ( (isNaN(tmp.low)) || (isNaN(tmp.high)) ) {
|
||||
this.error("Random: one of the input values is not a number. " + tmp.low_e + tmp.high_e);
|
||||
} else {
|
||||
// at this point we have valid values so now to generate the random number!
|
||||
|
||||
// flip the values if low > high so random will work
|
||||
var value = 0;
|
||||
if (tmp.low > tmp.high) {
|
||||
value = tmp.low
|
||||
tmp.low = tmp.high
|
||||
tmp.high = value
|
||||
}
|
||||
|
||||
// if returning an integer, do a math.ceil() on the low value and a
|
||||
// Math.floor()high value before generate the random number. This must be
|
||||
// done to insure the rounding doesn't round up if using something like 4.7
|
||||
// which would end up with 5
|
||||
if ( (node.inte == "true") || (node.inte === true) ) {
|
||||
tmp.low = Math.ceil(tmp.low);
|
||||
tmp.high = Math.floor(tmp.high);
|
||||
// use this to round integers
|
||||
value = Math.round(Math.random() * (tmp.high - tmp.low + 1) + tmp.low - 0.5);
|
||||
} else {
|
||||
// use this to round floats
|
||||
value = (Math.random() * (tmp.high - tmp.low)) + tmp.low;
|
||||
}
|
||||
|
||||
RED.util.setMessageProperty(msg,node.property,value);
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("random",RandomNode);
|
||||
}
|
||||
Reference in New Issue
Block a user