This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

window-var
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

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.

Channel NPM Tag Description SemVer GitHub
Hackers @dev Latest Bleeding Edge
potentially-unstable
Release Tag master (PRs)
Lab Rats @rc Next Release Candidate
upcoming semi-stable release
Release Tag releases
Everyone @latest Latest Stable Version
highly recommended
Release Tag releases

NPM Consumption Examples

Channel NPM Tag NPM 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"
Channel NPM Tag NPM Install
Hackers @dev npm install window-var@dev
Lab Rats @rc npm install window-var@rc
Everyone @latest npm install window-var@latest
Latest Stable Version npm 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

Package Sidebar

Install

npm i window-var

Weekly Downloads

0

Version

1.0.11

License

MIT

Last publish

Collaborators

  • jaswrks