Browse Source

node => Node.js

pull/19/head
Luke Childs 8 years ago
parent
commit
248aa9b101
  1. 6
      README.md
  2. 4
      src/index.js

6
README.md

@ -4,7 +4,7 @@
Previously named `node-browser-environment`.
This allows you to run browser modules in node 4 or newer with minimal or no effort. Can also be used to test browser modules with any node test framework. Please note, only the DOM is simulated, if you want to run a module that requires more advanced browser features (like `localStorage`), you'll need to polyfill that seperately.
This allows you to run browser modules in Node.js 4 or newer with minimal or no effort. Can also be used to test browser modules with any Node.js test framework. Please note, only the DOM is simulated, if you want to run a module that requires more advanced browser features (like `localStorage`), you'll need to polyfill that seperately.
## Install
@ -24,7 +24,7 @@ npm install --save-dev browser-env
// Init
require('browser-env')();
// Now you have access to a browser like environment in node:
// Now you have access to a browser like environment in Node.js:
typeof window;
// 'object'
@ -39,7 +39,7 @@ div instanceof HTMLElement
// true
```
By default everything in the `jsdom` window namespace is tacked on to the node global namespace (excluding existing node properties e.g `console`, `setTimout`). If you want to trim this down you can pass an array of required properties:
By default everything in the `jsdom` window namespace is tacked on to the Node.js global namespace (excluding existing Node.js properties e.g `console`, `setTimout`). If you want to trim this down you can pass an array of required properties:
```js
// Init

4
src/index.js

@ -21,7 +21,7 @@ const createWindow = userJsdomConfig => {
return jsdom.jsdom('<html><body></body></html>', clone(jsdomConfig)).defaultView;
};
// IIFE executed on import to return an array of global node properties that
// IIFE executed on import to return an array of global Node.js properties that
// conflict with global browser properties.
const protectedproperties = (() => Object
.getOwnPropertyNames(createWindow())
@ -48,7 +48,7 @@ module.exports = function browserEnv() {
// If we're only applying specific required properties remove everything else
.filter(prop => !(properties && properties.indexOf(prop) === -1))
// Copy what's left to node's global scope
// Copy what's left to the Node.js global scope
.forEach(prop => global[prop] = window[prop]);
// Return reference to original window object

Loading…
Cancel
Save