UNPKG

video-ad-sdk

Version:

VAST/VPAID SDK that allows video ads to be played on top of any player

30 lines (29 loc) 1.13 kB
/** * Loads the script source. * * @ignore * @param src The script source. * @param options The allowed options */ export const loadScript = (source, { async = false, defer = false, type, placeholder } = {}) => { if (!source) { throw new TypeError('Missing required "src" parameter'); } return new Promise((resolve, reject) => { const script = document.createElement('script'); let scriptPlaceholder = placeholder; script.type = type !== null && type !== void 0 ? type : 'text/javascript'; script.async = async; script.defer = defer; script.onerror = () => reject(new URIError(`The script ${source} is not accessible.`)); script.onload = () => resolve(script); if (!scriptPlaceholder) { scriptPlaceholder = (document.currentScript ? /* istanbul ignore next */ document.currentScript.parentNode : document.head); } script.src = source; scriptPlaceholder === null || scriptPlaceholder === void 0 ? void 0 : scriptPlaceholder.appendChild(script); }); };