Skip to content

Commit

Permalink
Fix boolean return
Browse files Browse the repository at this point in the history
- Boolean would always return true
- Some codestyle fixes
  • Loading branch information
Sineos committed Mar 19, 2018
1 parent 139d3e2 commit 9459320
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 53 deletions.
242 changes: 242 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
module.exports = {
"env": {
"node": false,
"browser": true,
"commonjs": true,
"jquery": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "script"
},
"rules": {
"accessor-pairs": "error",
"array-bracket-spacing": "error",
"array-callback-return": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": ["error", "1tbs"],
"callback-return": "error",
"camelcase": [
"error",
{
"properties": "never"
}
],
"comma-dangle": "error",
"comma-spacing": "error",
"comma-style": "error",
"complexity": "off",
"computed-property-spacing": "error",
"consistent-return": "off",
"consistent-this": "off",
"curly": "off",
"default-case": "off",
"dot-location": [
"error",
"object"
],
"dot-notation": "off",
"eol-last": "error",
"eqeqeq": ["error", "smart"],
"func-names": [
"error",
"never"
],
"func-style": [
"error",
"declaration"
],
"generator-star-spacing": "error",
"global-require": "off",
"guard-for-in": "error",
"handle-callback-err": "error",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": [
"error",
2, { "VariableDeclarator": 2 }
],
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "off",
"keyword-spacing": "off",
"linebreak-style": [
"error",
"unix"
],
"lines-around-comment": "error",
"max-depth": "error",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "error",
"multiline-ternary": "off",
"new-parens": "error",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "error",
"no-alert": "off",
"no-array-constructor": "error",
"no-bitwise": "warn",
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "error",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "error",
"no-empty-function": "error",
"no-eq-null": "off",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-implicit-coercion": "warn",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": "error",
"no-mixed-requires": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-negated-condition": "off",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "warn",
"no-path-concat": "error",
"no-plusplus": "error",
"no-process-env": "off",
"no-process-exit": "error",
"no-proto": "error",
"no-prototype-builtins": "off",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "error",
"no-tabs": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-undefined": "error",
"no-underscore-dangle": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "warn",
"no-use-before-define": "off",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-var": "off",
"no-void": "error",
"no-warning-comments": "warn",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": [
"error",
{ "multiline": true,
"consistent": true}
],
"object-curly-spacing": [
"error",
"never"
],
"object-property-newline": [
"error",
{ "allowMultiplePropertiesPerLine": true }
],
"object-shorthand": "off",
"one-var": "off",
"one-var-declaration-per-line": "error",
"operator-assignment": [
"warn",
"always"
],
"operator-linebreak": "error",
"padded-blocks": "off",
"prefer-arrow-callback": "off",
"prefer-const": "error",
"prefer-reflect": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "off",
"quote-props": "off",
"quotes": [
"error",
"single",
{ "allowTemplateLiterals": true }
],
"radix": [
"error",
"as-needed"
],
"require-jsdoc": "off",
"rest-spread-spacing": "error",
"semi": "error",
"semi-spacing": "error",
"sort-imports": "error",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": [
"error",
"never"
],
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "off",
"space-unary-ops": "error",
"spaced-comment": "off",
"strict": ["warn", "function"],
"template-curly-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"valid-jsdoc": "error",
"vars-on-top": "off",
"wrap-iife": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-timeouttrigger",
"version": "0.0.1",
"version": "0.0.2",
"description": "This node will pipe any received `msg` to its output. At the same time a time-out interval is set. Upon time-out a defined payload is send. Each new message will reset the time-out.",
"main": "timeouttrigger.js",
"scripts": {},
Expand All @@ -21,4 +21,4 @@
}
},
"dependencies": {}
}
}
108 changes: 57 additions & 51 deletions timeouttrigger.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
/**
* Copyright Sineos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
**/

module.exports = function(RED) {
"use strict";
function TimeOutTrigger(n) {
RED.nodes.createNode(this,n);
'use strict';
function TimeOutTrigger(n) {
RED.nodes.createNode(this, n);

this.units = n.units || "s";
this.duration = n.duration || 5;
this.ontimeoutval = n.ontimeoutval || "0";
this.ontimeouttype = n.ontimeouttype || "str";
this.units = n.units || 's';
this.duration = n.duration || 5;
this.ontimeoutval = n.ontimeoutval || '0';
this.ontimeouttype = n.ontimeouttype || 'str';

if (this.duration <= 0) { this.duration = 0; }
else {
if (this.units == "s") { this.duration = this.duration * 1000; }
if (this.units == "min") { this.duration = this.duration * 1000 * 60; }
if (this.units == "hr") { this.duration = this.duration * 1000 * 60 * 60; }
}
if (this.duration <= 0) {
this.duration = 0;
} else {
if (this.units === 's') {
this.duration = this.duration * 1000;
}
if (this.units === 'min') {
this.duration = this.duration * 1000 * 60;
}
if (this.units === 'hr') {
this.duration = this.duration * 1000 * 60 * 60;
}
}


if ((this.ontimeouttype === "num") && (!isNaN(this.ontimeoutval))) {
this.ontimeoutval = Number(this.ontimeoutval);
}
else if (this.ontimeoutval === 'true' || this.ontimeoutval === 'false') {
this.ontimeoutval = Boolean(this.ontimeoutval);
}
else if (this.ontimeoutval == "null") {
this.ontimeouttype = 'null';
this.ontimeoutval = null;
}
else {
this.ontimeoutval = String(this.ontimeoutval);
}
if ((this.ontimeouttype === 'num') && (!isNaN(this.ontimeoutval))) {
this.ontimeoutval = Number(this.ontimeoutval);
} else if (this.ontimeoutval === 'true' || this.ontimeoutval === 'false') {
(this.ontimeoutval === 'true' ? this.ontimeoutval = true : this.ontimeoutval = false);
} else if (this.ontimeoutval === 'null') {
this.ontimeouttype = 'null';
this.ontimeoutval = null;
} else {
this.ontimeoutval = String(this.ontimeoutval);
}

var node = this;
var tout = null;
this.on("input", function(msg) {
node.send(msg);
clearTimeout(tout);
node.status({fill:"green",shape:"dot"});
tout = setTimeout(function() {
var msg2 = RED.util.cloneMessage(msg);
msg2.payload = node.ontimeoutval;
node.send(msg2);
tout = null;
node.status({fill:"red",shape:"ring",text:"timed out"});
},node.duration);
});
this.on("close", function() {
if (tout) {
clearTimeout(tout);
}
node.status({});
});
}
RED.nodes.registerType("timeouttrigger",TimeOutTrigger);
}
var node = this;
var tout = null;

this.on('input', function(msg) {
node.send(msg);
clearTimeout(tout);
node.status({fill:'green', shape:'dot'});
tout = setTimeout(function() {
var msg2 = RED.util.cloneMessage(msg);
msg2.payload = node.ontimeoutval;
node.send(msg2);
tout = null;
node.status({fill:'red', shape:'ring', text:'timed out'});
}, node.duration);
});

this.on('close', function() {
if (tout) {
clearTimeout(tout);
}
node.status({});
});
}
RED.nodes.registerType('timeouttrigger', TimeOutTrigger);
};

0 comments on commit 9459320

Please sign in to comment.