@symbo.ls/utils
Advanced tools
Comparing version 2.11.410 to 2.11.411
@@ -136,3 +136,3 @@ "use strict"; | ||
self: () => self, | ||
window: () => window | ||
window: () => window2 | ||
}); | ||
@@ -142,4 +142,4 @@ module2.exports = __toCommonJS2(globals_exports); | ||
var self = globalThis; | ||
var window = globalThis; | ||
var document2 = window.document; | ||
var window2 = globalThis; | ||
var document2 = window2.document; | ||
} | ||
@@ -146,0 +146,0 @@ }); |
@@ -136,3 +136,3 @@ "use strict"; | ||
self: () => self, | ||
window: () => window | ||
window: () => window2 | ||
}); | ||
@@ -142,4 +142,4 @@ module2.exports = __toCommonJS2(globals_exports); | ||
var self = globalThis; | ||
var window = globalThis; | ||
var document2 = window.document; | ||
var window2 = globalThis; | ||
var document2 = window2.document; | ||
} | ||
@@ -1530,2 +1530,3 @@ }); | ||
loadJavascriptFile: () => loadJavascriptFile, | ||
loadJavascriptFileSync: () => loadJavascriptFileSync, | ||
removeChars: () => removeChars, | ||
@@ -1600,6 +1601,6 @@ toCamelCase: () => toCamelCase, | ||
scriptEle.addEventListener("error", (ev) => { | ||
reject({ | ||
reject(new Error({ | ||
status: false, | ||
message: `Failed to load the script ${FILE_URL}` | ||
}); | ||
})); | ||
}); | ||
@@ -1612,2 +1613,15 @@ doc.body.appendChild(scriptEle); | ||
}; | ||
var loadJavascriptFileSync = (FILE_URL, doc = document, type = "text/javascript") => { | ||
const xhr = new window.XMLHttpRequest(); | ||
xhr.open("GET", FILE_URL, false); | ||
xhr.send(); | ||
if (xhr.status === 200) { | ||
const scriptEle = doc.createElement("script"); | ||
scriptEle.type = type; | ||
scriptEle.text = xhr.responseText; | ||
doc.body.appendChild(scriptEle); | ||
} else { | ||
throw new Error(`Failed to load the script ${FILE_URL}`); | ||
} | ||
}; | ||
var loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => { | ||
@@ -1614,0 +1628,0 @@ return new Promise((resolve, reject) => { |
@@ -25,3 +25,4 @@ "use strict"; | ||
loadJavascript: () => loadJavascript, | ||
loadJavascriptFile: () => loadJavascriptFile | ||
loadJavascriptFile: () => loadJavascriptFile, | ||
loadJavascriptFileSync: () => loadJavascriptFileSync | ||
}); | ||
@@ -42,6 +43,6 @@ module.exports = __toCommonJS(load_exports); | ||
scriptEle.addEventListener("error", (ev) => { | ||
reject({ | ||
reject(new Error({ | ||
status: false, | ||
message: `Failed to load the script ${FILE_URL}` | ||
}); | ||
})); | ||
}); | ||
@@ -54,2 +55,15 @@ doc.body.appendChild(scriptEle); | ||
}; | ||
var loadJavascriptFileSync = (FILE_URL, doc = document, type = "text/javascript") => { | ||
const xhr = new window.XMLHttpRequest(); | ||
xhr.open("GET", FILE_URL, false); | ||
xhr.send(); | ||
if (xhr.status === 200) { | ||
const scriptEle = doc.createElement("script"); | ||
scriptEle.type = type; | ||
scriptEle.text = xhr.responseText; | ||
doc.body.appendChild(scriptEle); | ||
} else { | ||
throw new Error(`Failed to load the script ${FILE_URL}`); | ||
} | ||
}; | ||
var loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => { | ||
@@ -56,0 +70,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "@symbo.ls/utils", | ||
"version": "2.11.410", | ||
"version": "2.11.411", | ||
"author": "symbo.ls", | ||
@@ -29,3 +29,3 @@ "files": [ | ||
}, | ||
"gitHead": "8ea25d0b8ce6086f6892b69b372af85f80391a80" | ||
"gitHead": "e45830a80e83324329963be4d39dc5b0aa50d43d" | ||
} |
@@ -18,6 +18,6 @@ 'use strict' | ||
scriptEle.addEventListener('error', (ev) => { | ||
reject({ | ||
reject(new Error({ | ||
status: false, | ||
message: `Failed to load the script ${FILE_URL}` | ||
}) | ||
})) | ||
}) | ||
@@ -32,2 +32,17 @@ | ||
export const loadJavascriptFileSync = (FILE_URL, doc = document, type = 'text/javascript') => { | ||
const xhr = new window.XMLHttpRequest() | ||
xhr.open('GET', FILE_URL, false) // false makes the request synchronous | ||
xhr.send() | ||
if (xhr.status === 200) { | ||
const scriptEle = doc.createElement('script') | ||
scriptEle.type = type | ||
scriptEle.text = xhr.responseText | ||
doc.body.appendChild(scriptEle) | ||
} else { | ||
throw new Error(`Failed to load the script ${FILE_URL}`) | ||
} | ||
} | ||
export const loadCssFile = (FILE_URL, async = false, doc = document, type = 'text/javascript') => { | ||
@@ -34,0 +49,0 @@ return new Promise((resolve, reject) => { |
192598
5213