X-Git-Url: http://git.squeep.com/?p=squeep-mystery-box;a=blobdiff_plain;f=lib%2Fcommon.js;h=1d4223b1749d1cce37b729233f988098abc36b5a;hp=4c7e6392fe1f7e6f28a9321680d56fbf933404cb;hb=5c90dcd8088365a17f699dd683958536bc33c08c;hpb=5029da9845bcd89324e1e6ae95d94caa9febd9e8 diff --git a/lib/common.js b/lib/common.js index 4c7e639..1d4223b 100644 --- a/lib/common.js +++ b/lib/common.js @@ -19,7 +19,23 @@ const fileScope = (filename) => { } +/** + * 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