UNPKG

express-locator

Version:
28 lines (22 loc) 1.28 kB
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * @description A class to automatically assign dependencies, relevant config and locator to this of the child class * @export * @class Instance */ var Instance = function Instance(properties, dependencies) { var _this = this; _classCallCheck(this, Instance); if (_typeof(properties) === 'object' && !Array.isArray(properties)) { Object.keys(properties).forEach(function (prop) { _this[prop] = properties[prop]; //eslint-disable-line }); } else throw new Error('Locator must be provided to class in an object key-value pair'); if (Array.isArray(dependencies)) { dependencies.forEach(function (dependency) { _this[dependency] = _this.locator.get(dependency); //eslint-disable-line }); } }; export { Instance as default };