npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

global-object

v1.0.0

Published

just the global object

Downloads

75,777

Readme

global-object

There are at least 3 different ways to reference the global object mentioned in ES6/2015

  • window historically on HTML pages
  • self in Workers, and historically on HTML pages too
  • global in basically all server side implementation of JavaScript

If we search in Github, the summed amount of typeof window or typeof global checks, mostly to understand which one is available, is about 23 millions of times.

This is madness, and since there's no reason at all to prefer anything different from global for an object defined indeed as the global object in the global scope, I've decided to create this page in order to put an end to all this.


Forget about window and self in Workers, normalize your work-flow once for all and with or without browserify in place!

As first script in your page

This is the most straight forward way to have it defined everywhere as such

<script>var global=global||this;</script>

No need to disturb the network, no need to ever update the script even if a browser will eventually expose global reference. It goes there to stay.

As first script in your Worker

Same goes with Web Workers and others, the code is exactly the same, without the node:

var global=global||this;

Forget about self or typeof window checks, we've got global!

As anything else

ES6, node itself, whatever ...

// ES6
import global from 'global-object';

// npm require
var global = require('global-object');

// browser
script.src = 'global-object.js';

Just use global-object

Strict compatible!

Yes, the this reference in the global scope is always the global object. In HTML pages like in workers, it will work everywhere even after "use strict" directive!

Content Security Policy Compatible

Using this meta will solve all problems:

<meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-inline' 'self' 'sha1-WWQNP0ydesPxK1yAm94nH5bQoIo=' 'sha256-5rMu52Es8MMWNrCqRkunbIAeVDz8iJ63wD0rPm57xi4='">

Great, no network request required, and global available under CSP too!

License

Nope, nothing ... do what you want, literally!