export function isWindowObjectExist ( ) { return typeof window !== 'undefined' ; } export function loadScript ( scriptUrl , onSuccess , onError ? , scriptId ? ) { if ( ! isWindowObjectExist ( ) ) { return ; } const head = document . getElementsByTagName ( 'head' ) [ 0 ] ; const script = document . createElement ( 'script' ) ; script . setAttribute ( 'type' , 'text/javascript' ) ; script . setAttribute ( 'src' , scriptUrl ) ; if ( scriptId ) { script . id = scriptId ; } script . onload = ( ) => { if ( onSuccess ) { onSuccess ( ) ; } } ; script . onerror = ( e ) => { if ( onError ) { onError ( `Unable to load script '${ scriptUrl }'` , e ) ; } } ; head . appendChild ( script ) ; } export function loadScriptAsync ( scriptUrl , scriptId ? ) { return new Promise ( ( resolve , reject ) => { loadScript ( scriptUrl , ( ) => { resolve ( ) ; } , ( message , exception ) => { reject ( exception ) ; } ) ; } ) ; }