
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Acquires global `window` var in a browserify-compatible way.
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
.
$ npm install window-var --save;
$ yarn add window-var;
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);
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);
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.
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 | master (PRs) | |
Lab Rats | @rc | Next Release Candidate upcoming semi-stable release | releases | |
Everyone | @latest | Latest Stable Version highly recommended | releases |
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 |
For full details see: LICENSE.txt
For full details see: CHANGELOG.md
New versions are released following semver.org guidelines.
the
master
branch at GitHub and submit your changes for review.
FAQs
Acquires global `window` var in a browserify-compatible way.
We found that window-var demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.