Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-window-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-window-polyfill

Polyfill for the problem `window is not defined` in node.js

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-window-polyfill

Version npm

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-polyfill

Npm

npm install node-window-polyfill

Requirements

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 window in the code or libraries
  • window.setTimeout - default setTimeout node function
  • window.clearTimeout - default clearTimeout node function
  • window.WebSocket - version from global object
  • window.ArrayBuffer - version from global object only
  • window.addEventListener - empty void function
  • window.navigator - { onLine: true }
  • window.isNodeJS - to check if polyfills were aplied
  • window.localStorage - in memory storage
  • window.Date - version from global object
  • global.WebSocket - using ws if the right flag is not set
  • if the above functions/properties are already set in the global object 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.git

then (once you have yarn and node installed) install dependencies

yarn

Build

To build the distribution and types

yarn build

The distribution is in the dist folder and types in the types folder.

To change defauld ES standard use --target flag. Ex.:

yarn build -target es3

Test

After configuring we can run tests.

yarn test

We can use debug information logging with setting up env variable

DEBUG=nodeWindowPolyfill-* yarn test

Author

Tomasz Górka http://tomasz.gorka.org.pl

License

© 2018 Tomasz Górka

MIT licensed.

FAQs

Package last updated on 06 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc