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

readystate

v0.4.1

Published

Get the current readyState of the environment we're loaded in.

Downloads

63

Readme

readystate

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

readystate is a module to determine the readystate of the current document and allows you to listen to various of readystate change events.

Installation

The module is available for Node.js and Browsers (using browserify) and can be installed by running the following command in your CLI:

npm install --save readystate

Usage

In all examples we assume that you've required the library as following in your code:

'use strict';

var readystate = require('readystate');

The readystate is a pre-constructed ReadyState instance which exposes various of methods to check and listen to readystate changes. Before continuing with the API here is a list of the ready state's that we currently support:

  • ALL: The I don't really give a fuck state.
  • UNKNOWN: We got an unknown readyState we should start listening for events.
  • LOADING: Environment is currently loading.
  • INTERACTIVE: Environment is ready for interaction.
  • COMPLETE: All resources have been loaded.

The INTERACTIVE state can be used for DOM ready and the COMPLETE for load events.

readystate#is

The is method allows you check if a certain readystate has been reached. It is not a strict check but a minimum check. For example if you want to know if the LOADING state has been reached but your document is already in the COMPLETE state we will return true.

// assume that document is fully loaded, these will all return true.
readystate.is('loading');
readystate.is('LOADING');
readystate.is(readystate.LOADING);

// assume that document is in `loading` state, these will return false
readystate.is('interactive');
readystate.is('INTERACTIVE');
readystate.is(readystate.COMPLETE);

readystate#{state}

We also you to assign callback for when a certain readystate is reached. If the state has yet to be reached we will queue your callback until the state is reached. If we are already in that state we will immediately call the supplied callback.

readystate.loading(function () { console.log('loading'); });
readystate.complete(function () { console.log('complete'); });
readystate.interactive(function () { console.log('interactive'); });

It also supports a second context argument which allows you to control the this value of your callback:

readystate.loading(function () {
  console.log(this); // 'foo'
}, 'foo');

readystate.removeAllListeners

Remove all previously assigned listeners.

readystate.removeAllListeners();

readystate.readystate

Please note, this is a private property

We store our current detected readystate in the .readystate it might be useful it you want to some manual checking.

License

MIT