Make jsenv detection conditional without return

This commit is contained in:
Yarmo Mackenbach 2021-04-26 12:28:43 +02:00
parent da59262c45
commit e0dc5f4b21
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
3 changed files with 215 additions and 218 deletions

View file

@ -26,13 +26,9 @@ const jsEnv = require("browser-or-node")
module.exports.timeout = 5000 module.exports.timeout = 5000
if (!jsEnv.isNode) { if (!jsEnv.isNode) {
module.exports.fn = null const dns = require('dns')
return
}
const dns = require('dns') /**
/**
* Execute a fetch request * Execute a fetch request
* @function * @function
* @async * @async
@ -40,7 +36,7 @@ const dns = require('dns')
* @param {string} data.domain - The targeted domain * @param {string} data.domain - The targeted domain
* @returns {object} * @returns {object}
*/ */
module.exports.fn = async (data, opts) => { module.exports.fn = async (data, opts) => {
let timeoutHandle let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => { const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout( timeoutHandle = setTimeout(
@ -69,4 +65,7 @@ module.exports.fn = async (data, opts) => {
clearTimeout(timeoutHandle) clearTimeout(timeoutHandle)
return result return result
}) })
}
} else {
module.exports.fn = null
} }

View file

@ -25,15 +25,11 @@ const jsEnv = require("browser-or-node")
*/ */
module.exports.timeout = 20000 module.exports.timeout = 20000
if (!jsEnv.isNode) { if (jsEnv.isNode) {
module.exports.fn = null const irc = require('irc-upd')
return const validator = require('validator')
}
const irc = require('irc-upd') /**
const validator = require('validator')
/**
* Execute a fetch request * Execute a fetch request
* @function * @function
* @async * @async
@ -44,7 +40,7 @@ const validator = require('validator')
* @param {string} opts.claims.irc.nick - The nick to be used by the library to log in * @param {string} opts.claims.irc.nick - The nick to be used by the library to log in
* @returns {object} * @returns {object}
*/ */
module.exports.fn = async (data, opts) => { module.exports.fn = async (data, opts) => {
let timeoutHandle let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => { const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout( timeoutHandle = setTimeout(
@ -92,4 +88,7 @@ module.exports.fn = async (data, opts) => {
clearTimeout(timeoutHandle) clearTimeout(timeoutHandle)
return result return result
}) })
}
} else {
module.exports.fn = null
} }

View file

@ -25,20 +25,16 @@ const jsEnv = require("browser-or-node")
*/ */
module.exports.timeout = 5000 module.exports.timeout = 5000
if (!jsEnv.isNode) { if (jsEnv.isNode) {
module.exports.fn = null const jsdom = require('jsdom')
return const { client, xml } = require('@xmpp/client')
} const debug = require('@xmpp/debug')
const validator = require('validator')
const jsdom = require('jsdom') let xmpp = null,
const { client, xml } = require('@xmpp/client')
const debug = require('@xmpp/debug')
const validator = require('validator')
let xmpp = null,
iqCaller = null iqCaller = null
const xmppStart = async (service, username, password) => { const xmppStart = async (service, username, password) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const xmpp = client({ const xmpp = client({
service: service, service: service,
@ -57,9 +53,9 @@ const xmppStart = async (service, username, password) => {
reject(error) reject(error)
}) })
}) })
} }
/** /**
* Execute a fetch request * Execute a fetch request
* @function * @function
* @async * @async
@ -72,7 +68,7 @@ const xmppStart = async (service, username, password) => {
* @param {string} opts.claims.xmpp.password - The password used to log in * @param {string} opts.claims.xmpp.password - The password used to log in
* @returns {object} * @returns {object}
*/ */
module.exports.fn = async (data, opts) => { module.exports.fn = async (data, opts) => {
let timeoutHandle let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => { const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout( timeoutHandle = setTimeout(
@ -140,4 +136,7 @@ module.exports.fn = async (data, opts) => {
clearTimeout(timeoutHandle) clearTimeout(timeoutHandle)
return result return result
}) })
}
} else {
module.exports.fn = null
} }