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

window-var

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

window-var

Acquires global `window` var in a browserify-compatible way.

  • 1.0.11
  • rc
  • dev
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Window Var

Acquires global `window` var in a browserify-compatible way.

npm overview
latest version license main script size typescript/js open issues
greenkeeper dependency status follow on twitter follow on github fork

developed by ‹src.works/›

Project Overview

When your project requires a DOM; i.e., a window.document reference. Using this library maximizes compatibility across a variety of browser-like environments. Instead of hard-coding references to window, use this package to work out the window reference dynamically; i.e., in case your web-based project ends up being used in places other than a traditional web browser.

For example, in an Electron app, in a JSDOM-related project, or in a project that doesn't expose window as window, but through another global variable, such as: global, self, or this.

Installation Options

Install via NPM package

$ npm install window-var --save;

Or install via Yarn Yarn package

$ yarn add window-var;

Using the Package

The following works when your package runs from a browser-like environment; i.e., when one of window, global, self, or this points to a Window object in the current environment.

import {win} from 'window-var';
console.log(win.document.URL);

Which is a much shorter version of this longer equivalency.

console.log((() => {
  if (typeof window !== 'undefined') {
    return window;
  } else if (typeof global !== 'undefined') {
    return global;
  } else if (typeof self !== 'undefined') {
    return self;
  } else {
    return this;
  }
})().document.URL);

Alternate Imports

This way allows you to work out the window var later by calling the .get() method on-demand.

import win from 'window-var';
console.log(win.get().document.URL);

This is basically the same as the previous example, but a little cleaner.

import {get as win} from 'window-var';
console.log(win().document.URL);

Built with TypeScript/JavaScript, Babel, NodeJS, NPM, and Sass

Commercial Use

@jaswrks

This software is created, documented and maintained by Jason Caldwell (@jaswrks) and a small team of talented developers at ‹src.works/›. It's open source, but if you use it commercially, please pay what you can.

Development Channels

Always use the latest stable version in production. If you want upcoming changes ahead of time use the @dev or @rc tag, but please do so at your own risk. The @dev and @rc tags are potentially unstable at various times throughout a development cycle, and therefore should not be used in production.

ChannelNPM TagDescriptionSemVerGitHub
Hackers@devLatest Bleeding Edge
potentially-unstable
Release Tagmaster (PRs)
Lab Rats@rcNext Release Candidate
upcoming semi-stable release
Release Tagreleases
Everyone@latestLatest Stable Version
highly recommended
Release Tagreleases

NPM Consumption Examples

ChannelNPM TagNPM package.json
Hackers@dev"window-var": "dev"
Lab Rats@rc"window-var": "rc"
Everyone@latest"window-var": "latest"
Latest Stable Version"window-var": "^1.0.11"
ChannelNPM TagNPM Install
Hackers@devnpm install window-var@dev
Lab Rats@rcnpm install window-var@rc
Everyone@latestnpm install window-var@latest
Latest Stable Versionnpm install window-var

MIT License

For full details see: LICENSE.txt

Changelog

For full details see: CHANGELOG.md

Semantic Versioning

New versions are released following semver.org guidelines.

Pull Requests Welcome

fork the master branch at GitHub and submit your changes for review.

Lab Rats Subscribe

Keywords

FAQs

Package last updated on 06 Aug 2017

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