X-Git-Url: http://git.squeep.com/?p=squeep-mystery-box;a=blobdiff_plain;f=lib%2Fcommon.js;fp=lib%2Fcommon.js;h=0000000000000000000000000000000000000000;hp=1d4223b1749d1cce37b729233f988098abc36b5a;hb=82e47c29e2c11196901826e68c5dc9b090d8c214;hpb=6c9e123b3c10ef5caafc1a5f352a4705a8579ca9 diff --git a/lib/common.js b/lib/common.js deleted file mode 100644 index 1d4223b..0000000 --- a/lib/common.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -const path = require('path'); -const { randomBytes } = require('crypto'); -const { promisify } = require('util'); -const randomBytesAsync = promisify(randomBytes); - - -/** - * Return a function which combines a part of the filename with a scope, for use in logging. - * @param {string} filename - */ -const fileScope = (filename) => { - let fScope = path.basename(filename, '.js'); - if (fScope === 'index') { - fScope = path.basename(path.dirname(filename)); - } - return (scope) => `${fScope}:${scope}`; -} - - -/** - * Return an array containing x if x is something and not an array - * @param {*} x - */ -const ensureArray = (x) => { - if (x === undefined) { - return []; - } - if (!Array.isArray(x)) { - return Array(x); - } - return x; -}; - - -module.exports = { - ensureArray, - fileScope, - randomBytesAsync, -}; \ No newline at end of file