script-ready
v2.0.0
Published
Detect or wait for if a script node is ready
Downloads
3
Readme
script-ready
Detect or wait until if a script node is ready
Install
$ npm i script-ready
Usage
import {
// Check if the given script is exists in the dom
exists,
// Wait until the script is ready
loaded
} from 'script-ready'
exists('a.js') // true
loaded('b.js').then(node => {
// The `HTMLScriptElement` node of the script
console.log(node)
})
exists(tester, {parent}) -> boolean
Returns true
if the script node already exists
- tester
string
: sub string of thenode.src
RegExp
: regular expression to test thenode.src
Function(node: HTMLScriptElement) -> boolean
tester function to test theHTMLScriptElement
- parent
document | 'head' | 'body'
the parent element to test the script node from
async loaded(tester, {parent}) -> node
Wait until the script node is loaded