Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ready-state

soenkekluth7kMIT2.0.5

Get / Check the document readyState by Promise, when the DOM and Window is loaded

browser, readystate, readystatechange, change, window, document, dom, onready, ready, promise, window, complete, wait, domcontentloaded, check, onload, load

readme

ready-state Build Status

Get / Check the document readyState by Promise readystatechange Check when the DOM is loaded like DOMContentLoaded Check when the Window is loaded like onload

All checks also work even after the DOM was loaded.

Dependencies

none!

Install

$ npm i ready-state
$ yarn add ready-state

Usage

const readyState = require('ready-state');

readyState.loading.then(state => {
  console.log('readyState is loading');
}),

readyState.interactive.then(state => {
  console.log('readyState is interactive');
}),

readyState.load.then(state => {
  console.log('Window is loaded');
}),

readyState.window.then(state => {
  console.log('Window is loaded');
}),

readyState.complete.then(state => {
  console.log('readyState is complete');
}),

readyState.domready.then(state => {
  console.log('DOM is loaded');
}),

readyState.dom.then(state => {
  console.log('DOM is loaded');
}),

console.log(readyState.state);


console.log(readyState.ready ? 'I am ready' : 'still waiting');

Test result

  ✔ all document states should pass
    ℹ readyState.loading
    ℹ readyState.interactive
    ℹ readyState.load
    ℹ readyState.window (readyState.load)
    ℹ readyState.complete
    ℹ readyState.domready
    ℹ readyState.dom (readyState.domready)

  1 test passed

License

MIT © Sönke Kluth