@square/web-sdk
Version:
Square Web SDK
2 lines (1 loc) • 689 B
JavaScript
function o(e){return document.querySelector(`script[src="${e}"]`)}function u(e){let n=document.head||document.body;if(!n)throw new Error("Square.js requires a <body> or <head> element.");let r=document.createElement("script");return r.src=e,n.appendChild(r),r}var i=null;function d(e){return i!==null||(i=new Promise((n,r)=>{if(typeof window=="undefined"){n(null);return}if(window.Square){n(window.Square);return}try{let t=o(e);t||(t=u(e)),t.addEventListener("load",()=>{window.Square?n(window.Square):r(new Error("Square.js failed to load properly."))}),t.addEventListener("error",()=>{r(new Error("Error occurred while loading Square.js"))})}catch(t){r(t)}})),i}export{d as loadSquare};