Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-loaded

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-loaded - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

15

index.d.ts

@@ -18,2 +18,3 @@ /**

@example
```

@@ -23,3 +24,3 @@ import domLoaded from 'dom-loaded';

if (domLoaded.hasLoaded) {
console.log('The DOM has already finished loading.')
console.log('The DOM has already finished loading.');
}

@@ -29,4 +30,16 @@ ```

readonly hasLoaded: boolean;
/**
An `AbortSignal` that triggers when the DOM finishes loading or immediately if it has already loaded.
@example
```
import domLoaded from 'dom-loaded';
showLoader({signal: domLoaded.signal});
```
*/
readonly signal: AbortSignal;
};
export default domLoaded;
const hasLoaded = () => document.readyState === 'interactive' || document.readyState === 'complete';
const controller = new AbortController();
const domLoaded = new Promise(resolve => {
if (hasLoaded()) {
resolve();
controller.abort();
} else {
document.addEventListener('DOMContentLoaded', () => {
resolve();
controller.abort();
}, {
capture: true,
once: true,
passive: true
passive: true,
});

@@ -20,3 +24,7 @@ }

Object.defineProperty(domLoaded, 'hasLoaded', {
get: () => hasLoaded()
get: hasLoaded,
});
Object.defineProperty(domLoaded, 'signal', {
get: () => controller.signal,
});

8

package.json
{
"name": "dom-loaded",
"version": "3.0.0",
"version": "3.1.0",
"description": "Check when the DOM has loaded like `DOMContentLoaded`",

@@ -15,2 +15,4 @@ "license": "MIT",

"exports": "./index.js",
"types": "./index.d.ts",
"sideEffects": false,
"engines": {

@@ -21,3 +23,3 @@ "node": ">=12"

"// TODO: Enable when JSOM support ESM - test": "xo && ava && tsd",
"test": "xo && tsd"
"test": "xo"
},

@@ -43,3 +45,3 @@ "files": [

"tsd": "^0.14.0",
"xo": "^0.39.1"
"xo": "^0.54.0"
},

@@ -46,0 +48,0 @@ "xo": {

@@ -9,5 +9,5 @@ # dom-loaded

```sh
npm install dom-loaded
```
$ npm install dom-loaded
```

@@ -37,4 +37,10 @@ ## Usage

### domLoaded.signal
Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
An `AbortSignal` that triggers when the DOM finishes loading or immediately if it has already loaded.
## Related
- [element-ready](https://github.com/sindresorhus/element-ready) - Detect when an element is ready in the DOM
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc