# ready-state

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

Latest version **2.0.5** (published 2018-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install ready-state
pnpm add ready-state
yarn add ready-state
bun add ready-state
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2018-02-18 |
| First published | 2016-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 177 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Sönke Kluth |
| Maintainers | soenkekluth |
| Keywords | browser, readystate, readystatechange, change, window, document, dom, onready, ready, promise, window, complete, wait, domcontentloaded, check, onload, load |

## Links

- npm: https://www.npmjs.com/package/ready-state
- Repository: https://github.com/soenkekluth/ready-state
- Homepage: https://github.com/soenkekluth/ready-state#readme
- Issues: https://github.com/soenkekluth/ready-state/issues
- npm.io page: https://npm.io/package/ready-state

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.0.5 (latest) — 2018-02-18
- 2.0.1 — 2018-02-03
- 1.0.0 — 2016-11-25

## README

# ready-state [![Build Status](https://travis-ci.org/soenkekluth/ready-state.svg?branch=master)](https://travis-ci.org/soenkekluth/ready-state)

> Get / Check the document readyState by Promise [`readystatechange`](https://developer.mozilla.org/de/docs/Web/Events/readystatechange)
> Check when the DOM is loaded like [`DOMContentLoaded`](https://developer.mozilla.org/en/docs/Web/Events/DOMContentLoaded)
> Check when the Window is loaded like [`onload`](https://developer.mozilla.org/de/docs/Web/API/GlobalEventHandlers/onload)

All checks also work even after the DOM was loaded.

## Dependencies
none!

## Install

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


## Usage

```js
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
```js
  ✔ 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
```


## Related

- [element-ready](https://github.com/sindresorhus/element-ready) - Detect when an element is ready in the DOM


## License

MIT © [Sönke Kluth](https://soenkekluth.com)

---
_Source: https://npm.io/package/ready-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
