1 import { environment } from '../environments/environment'
3 function objectToUrlEncoded (obj: any) {
4 const str: string[] = []
5 for (const key of Object.keys(obj)) {
6 str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
12 // Thanks: https://github.com/uupaa/dynamic-import-polyfill
13 function importModule (path: string) {
14 return new Promise((resolve, reject) => {
15 const vector = '$importModule$' + Math.random().toString(32).slice(2)
16 const script = document.createElement('script')
18 const destructor = () => {
19 delete window[ vector ]
23 URL.revokeObjectURL(script.src)
28 script.type = 'module'
30 script.onerror = () => {
31 reject(new Error(`Failed to import: ${path}`))
34 script.onload = () => {
35 resolve(window[ vector ])
38 const absURL = (environment.apiUrl || window.location.origin) + path
39 const loader = `import * as m from "${absURL}"; window.${vector} = m;` // export Module
40 const blob = new Blob([ loader ], { type: 'text/javascript' })
41 script.src = URL.createObjectURL(blob)
43 document.head.appendChild(script)