X-Git-Url: https://git.r.bdr.sh/rbdr/tomato-sauce/blobdiff_plain/c80b2f4575cfc3d74ec8e0b112943cbd081ffcd7..a0666be3ab58ed83ad6d622cfe2b8293c40dffbb:/lib/util.js?ds=sidebyside diff --git a/lib/util.js b/lib/util.js index 65f14ae..4c8c3c1 100644 --- a/lib/util.js +++ b/lib/util.js @@ -11,7 +11,7 @@ const Path = require('path'); */ const Util = { - /** + /** * Parses a 16 bit number buffer * * @function parse16BitBuffer @@ -19,12 +19,12 @@ const Util = { * @param {Array} buffer the buffer to parse * @return {Number} the parsed value */ - parse16BitBuffer(buffer) { + parse16BitBuffer(buffer) { - return buffer[0] * 256 + buffer[1]; - }, + return buffer[0] * 256 + buffer[1]; + }, - /** + /** * Picks a random element from an array * * @function pickRandom @@ -32,12 +32,12 @@ const Util = { * @param {Array} array the array to use * @return {Any} the picked element */ - pickRandom(array) { + pickRandom(array) { - return array[Math.floor(Math.random() * array.length)]; - }, + return array[Math.floor(Math.random() * array.length)]; + }, - /** + /** * For a gi ven path, requires all of the files and returns an array * with the results. If the directory contains any non-requireable * files, it will fail. @@ -47,36 +47,36 @@ const Util = { * @param {String} path the path where the files are located * @return {Array} the array of all the loaded modules */ - loadFiles(path) { + loadFiles(path) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { - Fs.readdir(path, (err, files) => { + Fs.readdir(path, (err, files) => { - if (err) { - return reject(err); - } + if (err) { + return reject(err); + } - const loadedFiles = []; + const loadedFiles = []; - for (const file of files) { - const filePath = Path.join(path, file); - let loadedFile; + for (const file of files) { + const filePath = Path.join(path, file); + let loadedFile; - try { - loadedFile = require(filePath); - } - catch (err) { - return reject(err); - } + try { + loadedFile = require(filePath); + } + catch (err) { + return reject(err); + } - loadedFiles.push(loadedFile); - } + loadedFiles.push(loadedFile); + } - resolve(loadedFiles); - }); - }); - } + resolve(loadedFiles); + }); + }); + } }; module.exports = Util;