mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Rename directory: ext -> extension
This commit is contained in:
42
extension/src/lib/utils.ts
Normal file
42
extension/src/lib/utils.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export function getNextEllipsis(ellipsis: string): string {
|
||||
if (ellipsis === "") return ".";
|
||||
if (ellipsis === ".") return "..";
|
||||
if (ellipsis === "..") return "...";
|
||||
if (ellipsis === "...") return "";
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Template literal tag function, JSON-encodes substitutions.
|
||||
*/
|
||||
export function stringify(
|
||||
templateStrings: TemplateStringsArray,
|
||||
...substitutions: unknown[]
|
||||
) {
|
||||
let formattedString = "";
|
||||
|
||||
for (const templateString of templateStrings) {
|
||||
if (formattedString) {
|
||||
formattedString += JSON.stringify(substitutions.shift());
|
||||
}
|
||||
|
||||
formattedString += templateString;
|
||||
}
|
||||
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
export function loadScript(
|
||||
scriptUrl: string,
|
||||
doc: Document = document
|
||||
): Promise<HTMLScriptElement> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const scriptEl = doc.createElement("script");
|
||||
scriptEl.src = scriptUrl;
|
||||
(doc.head || doc.documentElement).append(scriptEl);
|
||||
|
||||
scriptEl.addEventListener("load", () => resolve(scriptEl));
|
||||
scriptEl.addEventListener("error", () => reject());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user