node-red-viseo-helper
Advanced tools
Comparing version 0.0.16 to 0.1.16
@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct |
@@ -0,0 +0,0 @@ # Contributing to the Project |
90
index.js
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const vm = require('vm'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const vm = require('vm'); | ||
const extend = require('extend'); | ||
const EventEmitter = require('events'); | ||
// ------------------------------------------ | ||
// CONFIG | ||
// ------------------------------------------ | ||
require('./lib/config.js').init(); | ||
exports.CONFIG = CONFIG; | ||
const mkpathsync = exports.mkpathsync = (dirpath, mode) => { | ||
dirpath = path.resolve(dirpath); | ||
if (typeof mode === 'undefined') { | ||
mode = parseInt('0777', 8) & (~process.umask()); | ||
} | ||
try { | ||
if (!fs.statSync(dirpath).isDirectory()) { | ||
throw new Error(dirpath + ' exists and is not a directory'); | ||
} | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
mkpathsync(path.dirname(dirpath), mode); | ||
fs.mkdirSync(dirpath, mode); | ||
} else { throw err; } | ||
} | ||
}; | ||
// ------------------------------------------ | ||
// STRING | ||
// ------------------------------------------ | ||
const getByString = exports.getByString = (obj, str, def) => { | ||
@@ -35,3 +64,2 @@ if (!str) return def; | ||
const resolve = exports.resolve = (str, obj, def) => { | ||
@@ -77,20 +105,42 @@ if (str === undefined) return str; | ||
// ------------------------------------------ | ||
// EVENT | ||
// ------------------------------------------ | ||
const mkpathsync = exports.mkpathsync = (dirpath, mode) => { | ||
dirpath = path.resolve(dirpath); | ||
class NodeEmitter extends EventEmitter {} | ||
const emitter = new NodeEmitter(); | ||
if (typeof mode === 'undefined') { | ||
mode = parseInt('0777', 8) & (~process.umask()); | ||
const emitEvent = exports.emitEvent = (type, node, data, config) => { | ||
emitter.emit(type, node, config, data); | ||
} | ||
const listenEvent = exports.listenEvent = (type, callback) => { | ||
emitter.addListener(type, callback); | ||
} | ||
const removeListener = exports.removeListener = (type, callback) => { | ||
emitter.removeListener(type, callback); | ||
} | ||
const emitAsyncEvent = exports.emitAsyncEvent = (type, node, data, config, callback) => { | ||
let listeners = emitter.listeners(type) | ||
if (!listeners || listeners.length == 0){ | ||
return callback(data); | ||
} | ||
try { | ||
if (!fs.statSync(dirpath).isDirectory()) { | ||
throw new Error(dirpath + ' exists and is not a directory'); | ||
} | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
mkpathsync(path.dirname(dirpath), mode); | ||
fs.mkdirSync(dirpath, mode); | ||
} else { throw err; } | ||
} | ||
}; | ||
data._tmp = data._tmp || {} | ||
data._tmp['event_emitter'] = { callback: callback, config: config }; // Only one in a flow otherwise might loose it | ||
emitter.emit(type, node, data, config); | ||
} | ||
const fireAsyncCallback = exports.fireAsyncCallback = (data) => { | ||
if (!data._tmp) return; | ||
if (!data._tmp.event_emitter) return; | ||
let callback = data._tmp.event_emitter.callback; | ||
if (!callback) return; | ||
delete data._tmp.event_emitter; | ||
callback(data); | ||
} |
@@ -0,0 +0,0 @@ const extend = require('extend'); |
{ | ||
"name" : "node-red-viseo-helper", | ||
"version" : "0.0.16", | ||
"version" : "0.1.16", | ||
"description" : "Utility libarary for Node-RED", | ||
@@ -5,0 +5,0 @@ "dependencies" : { }, |
# Node-RED | ||
Utility library to work with Node-RED and a set of Node-RED nodes OpenSourced by [VISEO](http://www.viseo.com/) Technologies. | ||
Utility library to work with Node-RED and a set of Node-RED nodes OpenSourced by [VISEO](http://www.viseo.com/). | ||
@@ -5,0 +5,0 @@ ## Getting Help |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22480
121