rewiremock
Version:
Advanced dependency mocking device.
52 lines (43 loc) • 1.57 kB
JavaScript
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var currentScope = null;
export var setScope = function setScope(scope) {
return currentScope = scope;
};
export var 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;
};
export var 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;
};
export var 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, _toConsumableArray(scope[name]));
} else {
collect.push(scope[name]);
}
}
if (scope.parentScope) {
collectScopeVariable(name, scope.parentScope, collect);
}
return collect;
};
export default (function () {
return currentScope;
});