script-ready

Detect or wait for if a script node is ready

Usage no npm install needed!

<script type="module">
  import scriptReady from 'https://cdn.skypack.dev/script-ready';
</script>

README

Build Status

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 the node.src
    • RegExp: regular expression to test the node.src
    • Function(node: HTMLScriptElement) -> boolean tester function to test the HTMLScriptElement
  • 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

License

MIT