]>
git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/util.js
3 const Fs
= require('fs');
4 const Path
= require('path');
6 // Module containing utility functions.
9 // Parses a 16 bit number buffer.
10 parse16BitBuffer: function (buffer
) {
11 return buffer
[0] * 256 + buffer
[1];
14 // Picks a random element from an array.
15 pickRandom: function (array
) {
16 return array
[Math
.floor(Math
.random() * array
.length
)];
19 // For a given path, requires all of the files and returns an array
20 // with the results. If the directory contains any non-requireable file,
22 loadFiles: function (path
) {
23 return new Promise(function (resolve
, reject
) {
24 Fs
.readdir(path
, function (err
, files
) {
31 for (let file
of files
) {
32 let filePath
= Path
.join(path
, file
);
36 loadedFile
= require(filePath
);
41 loadedFiles
.push(loadedFile
);
50 module
.exports
= Util
;