Initial simple client implementation

This commit is contained in:
Pedro Lopez
2019-02-17 00:03:07 -04:00
parent 372187d275
commit bcbd16f196
8 changed files with 538 additions and 0 deletions

35
src/util/Util.js Normal file
View File

@@ -0,0 +1,35 @@
'use strict';
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
/**
* Utility methods
*/
class Util {
constructor() {
throw new Error(`The ${this.constructor.name} class may not be instantiated.`);
}
/**
* Sets default properties on an object that aren't already specified.
* @param {Object} def Default properties
* @param {Object} given Object to assign defaults to
* @returns {Object}
* @private
*/
static mergeDefault(def, given) {
if (!given) return def;
for (const key in def) {
if (!has(given, key) || given[key] === undefined) {
given[key] = def[key];
} else if (given[key] === Object(given[key])) {
given[key] = Util.mergeDefault(def[key], given[key]);
}
}
return given;
}
}
module.exports = Util;