diff --git a/common/src/misc/utils.ts b/common/src/misc/utils.ts index b39ada3b2a..a91ccd5a35 100644 --- a/common/src/misc/utils.ts +++ b/common/src/misc/utils.ts @@ -7,7 +7,6 @@ const nodeURL = typeof window === "undefined" ? require("url") : null; export class Utils { static inited = false; - static isNativeScript = false; static isNode = false; static isBrowser = true; static isMobileBrowser = false; @@ -30,18 +29,13 @@ export class Utils { (process as any).release != null && (process as any).release.name === "node"; Utils.isBrowser = typeof window !== "undefined"; - Utils.isNativeScript = !Utils.isNode && !Utils.isBrowser; Utils.isMobileBrowser = Utils.isBrowser && this.isMobile(window); Utils.isAppleMobileBrowser = Utils.isBrowser && this.isAppleMobile(window); - Utils.global = Utils.isNativeScript - ? global - : Utils.isNode && !Utils.isBrowser - ? global - : window; + Utils.global = Utils.isNode && !Utils.isBrowser ? global : window; } static fromB64ToArray(str: string): Uint8Array { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return new Uint8Array(Buffer.from(str, "base64")); } else { const binaryString = window.atob(str); @@ -58,7 +52,7 @@ export class Utils { } static fromHexToArray(str: string): Uint8Array { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return new Uint8Array(Buffer.from(str, "hex")); } else { const bytes = new Uint8Array(str.length / 2); @@ -70,7 +64,7 @@ export class Utils { } static fromUtf8ToArray(str: string): Uint8Array { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return new Uint8Array(Buffer.from(str, "utf8")); } else { const strUtf8 = unescape(encodeURIComponent(str)); @@ -91,7 +85,7 @@ export class Utils { } static fromBufferToB64(buffer: ArrayBuffer): string { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return Buffer.from(buffer).toString("base64"); } else { let binary = ""; @@ -112,7 +106,7 @@ export class Utils { } static fromBufferToUtf8(buffer: ArrayBuffer): string { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return Buffer.from(buffer).toString("utf8"); } else { const bytes = new Uint8Array(buffer); @@ -127,7 +121,7 @@ export class Utils { // ref: https://stackoverflow.com/a/40031979/1090359 static fromBufferToHex(buffer: ArrayBuffer): string { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return Buffer.from(buffer).toString("hex"); } else { const bytes = new Uint8Array(buffer); @@ -160,7 +154,7 @@ export class Utils { } static fromUtf8ToB64(utfStr: string): string { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return Buffer.from(utfStr, "utf8").toString("base64"); } else { return decodeURIComponent(escape(window.btoa(utfStr))); @@ -172,7 +166,7 @@ export class Utils { } static fromB64ToUtf8(b64Str: string): string { - if (Utils.isNode || Utils.isNativeScript) { + if (Utils.isNode) { return Buffer.from(b64Str, "base64").toString("utf8"); } else { return decodeURIComponent(escape(window.atob(b64Str))); @@ -387,7 +381,7 @@ export class Utils { private static getUrlObject(uriString: string): URL { try { if (nodeURL != null) { - return nodeURL.URL ? new nodeURL.URL(uriString) : nodeURL.parse(uriString); + return new nodeURL.URL(uriString); } else if (typeof URL === "function") { return new URL(uriString); } else if (window != null) {