UNPKG

@awaitbox/document-ready

Version:

@awaitbox/document-ready ========================

24 lines (18 loc) 612 B
/** * Await for this to run code after the DOM has been parsed and loaded (but not * sub-resources like images, scripts, etc). * * The _passThrough arg is not for public use, it's for making data pass * through in promise chains. */ function documentReady( _passThrough ) { if ( document.readyState === 'loading' ) { return new Promise( resolve => { document.addEventListener( 'DOMContentLoaded', () => resolve( _passThrough ) ) } ) } return Promise.resolve( _passThrough ) } export default documentReady export { documentReady } export const version = '2.0.1'