node-window-polyfill v1.0.4
node-window-polyfill
Polyfill for the problem window is not defined in node.js.
It's inserting window object on globals
and inputing all needed sub-elements
with requiring web sockets dependency.
Installation
Yarn
yarn add node-window-polyfillNpm
npm install node-window-polyfillRequirements
Minimum ES5.
To use it in different environment it's required to clone and build it with the proper flag.
Usage
Import it in global file, or in every file
where the source code requires the window object.
import nodeWindowPolyfill from "node-window-polyfill";
nodeWindowPolyfill.register();For shorter import that will call register directrly
import "node-window-polyfill/register";If you don't want to import 'ws' module and just create empty objects:
import nodeWindowPolyfill from "node-window-polyfill";
nodeWindowPolyfill.register(false);And the version previous ES versions:
require('node-window-polyfill').register();What is polyfilled?
- usage of
windowin the code or libraries window.setTimeout- defaultsetTimeoutnode functionwindow.clearTimeout- defaultclearTimeoutnode functionwindow.WebSocket- version from global objectwindow.ArrayBuffer- version from global object onlywindow.addEventListener- empty void functionwindow.navigator-{ onLine: true }window.isNodeJS- to check if polyfills were apliedwindow.localStorage- in memory storagewindow.Date- version from global objectglobal.WebSocket- using ws if the right flag is not set- if the above functions/properties are already set in the
globalobject then they will be taken into the account
Configure
To configure development environment and run the tests, first clone the repository:
git clone https://github.com/tgorka/node-window-polyfill.gitthen (once you have yarn and node installed) install dependencies
yarnBuild
To build the distribution and types
yarn buildThe distribution is in the dist folder and types in the types folder.
To change defauld ES standard use --target flag. Ex.:
yarn build -target es3Test
After configuring we can run tests.
yarn testWe can use debug information logging with setting up env variable
DEBUG=nodeWindowPolyfill-* yarn testAuthor
Tomasz Górka http://tomasz.gorka.org.pl
License
© 2018 Tomasz Górka
MIT licensed.