UNPKG

1.29 kBJavaScriptView Raw
1'use strict';
2
3var _jsdom = require('jsdom');
4
5function getWindowPropertyKeys(window) {
6 return Object.keys(window).concat(Object.keys(window._core)).filter(function (prop) {
7 return prop.substring(0, 1) !== '_';
8 });
9}
10
11var protectedproperties = function () {
12 var window = (0, _jsdom.jsdom)('<html><body></body></html>').defaultView;
13
14 return getWindowPropertyKeys(window).filter(function (prop) {
15 return global[prop];
16 });
17}();
18
19var getType = function getType(val) {
20 return Object.prototype.toString.call(val);
21};
22
23module.exports = function () {
24 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
25 args[_key] = arguments[_key];
26 }
27
28 var properties = args.filter(function (arg) {
29 return getType(arg) === '[object Array]';
30 })[0];
31 var jsdomConfig = args.filter(function (arg) {
32 return getType(arg) === '[object Object]';
33 })[0];
34
35 var window = (0, _jsdom.jsdom)('<html><body></body></html>', jsdomConfig).defaultView;
36
37 getWindowPropertyKeys(window).filter(function (prop) {
38 return protectedproperties.indexOf(prop) === -1;
39 }).filter(function (prop) {
40 return !(properties && properties.indexOf(prop) === -1);
41 }).forEach(function (prop) {
42 return global[prop] = window[prop];
43 });
44
45 return window;
46};
\No newline at end of file