UNPKG

rewiremock

Version:

Advanced dependency mocking device.

63 lines (50 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.collectScopeVariable = exports.getScopeOption = exports.getScopeVariable = exports.setScope = undefined; var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray"); var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var currentScope = null; var setScope = exports.setScope = function setScope(scope) { return currentScope = scope; }; var getScopeVariable = exports.getScopeVariable = function getScopeVariable(name) { var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : currentScope; if (name in scope) { return scope[name]; } if (scope.parentScope) { return getScopeVariable(name, scope.parentScope); } return undefined; }; var getScopeOption = exports.getScopeOption = function getScopeOption(name) { var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : currentScope; if (name in scope.options) { return scope.options[name]; } if (scope.parentScope) { return getScopeOption(name, scope.parentScope); } return undefined; }; var collectScopeVariable = exports.collectScopeVariable = function collectScopeVariable(name) { var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : currentScope; var collect = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; if (name in scope) { if (Array.isArray(scope[name])) { collect.push.apply(collect, (0, _toConsumableArray3.default)(scope[name])); } else { collect.push(scope[name]); } } if (scope.parentScope) { collectScopeVariable(name, scope.parentScope, collect); } return collect; }; exports.default = function () { return currentScope; };