UNPKG

node-browser-environment

Version:
46 lines (36 loc) 1.29 kB
'use strict'; var _jsdom = require('jsdom'); function getWindowPropertyKeys(window) { return Object.keys(window).concat(Object.keys(window._core)).filter(function (prop) { return prop.substring(0, 1) !== '_'; }); } var protectedproperties = function () { var window = (0, _jsdom.jsdom)('<html><body></body></html>').defaultView; return getWindowPropertyKeys(window).filter(function (prop) { return global[prop]; }); }(); var getType = function getType(val) { return Object.prototype.toString.call(val); }; module.exports = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var properties = args.filter(function (arg) { return getType(arg) === '[object Array]'; })[0]; var jsdomConfig = args.filter(function (arg) { return getType(arg) === '[object Object]'; })[0]; var window = (0, _jsdom.jsdom)('<html><body></body></html>', jsdomConfig).defaultView; getWindowPropertyKeys(window).filter(function (prop) { return protectedproperties.indexOf(prop) === -1; }).filter(function (prop) { return !(properties && properties.indexOf(prop) === -1); }).forEach(function (prop) { return global[prop] = window[prop]; }); return window; };