for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
class Validate {
url (string) {
/* eslint no-useless-escape: 0 */
let regex = /(mqtt|mqtts|tcp|tls|ws|wss):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/
var pattern = new RegExp(regex)
return pattern.test(string)
}
sourceConfiguration (input, callback) {
let error = null
if (!input.source.url) {
if (!error) {
error = new Error('URL for MQTT broker has not been set.')
if (!this.url(input.source.url)) {
error = new Error('Your defined URL is invalid. It should start with mqtt://')
let port = Number.parseInt(input.source.port)
if (Number.isNaN(port)) {
input.source.port = 1883
} else {
input.source.port = port
callback(input, error)
paramConfiguration (input, callback) {
if (!input.hasOwnProperty('params')) {
return error = new Error('The parameters are not been set.')
error
error === new Error("The...ers are not been set.")
if (!input.params.topic) {
error = new Error('The parameter topic has not been set.')
if (!input.params.payload) {
error = new Error('The parameter payload has not been set.')
if (![0, 1, 2].includes(input.params.qos)) {
input.params.qos = 1
input.params.qos.toString()
return
return undefined;
module.exports = new Validate