UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

62 lines 1.65 kB
import moduleAlias from "module-alias"; moduleAlias.addPath(process.cwd()); function isErrorLike(value) { return typeof value === "object" && value !== null && "message" in value && typeof value.message === "string"; } function log(message) { console.log(message); } function logWarning(message) { console.warn(message); } function logError(message) { console.error(message); } function atob(str) { if (!/^[A-Za-z0-9+/]*={0,2}$/.test(str)) { throw new Error("Invalid base64 string"); } try { return Buffer.from(str, "base64").toString("ascii"); } catch { throw new Error("Invalid base64 string"); } } function btoa(str) { try { return Buffer.from(str, "ascii").toString("base64"); } catch { throw new Error("Invalid ascii string"); } } function importModule(modulePath) { try { const normalizedPath = modulePath.replace(/\.(js|ts)$/, "").replace(/^(\.\/|\.\.\/)/g, ""); try { return require(normalizedPath); } catch (error) { const errorMessage = isErrorLike(error) ? error.message : String(error); if (errorMessage.includes("Cannot find module")) { throw new Error(`Module not found: ${modulePath}`); } throw error; } } catch (error) { if (isErrorLike(error)) { if ("name" in error && error.name === "SyntaxError") { throw new Error(`Syntax error in module: ${modulePath}`); } throw new Error(`Failed to import module ${modulePath}: ${error.message}`); } throw new Error(String(error)); } } export { atob, btoa, importModule, log, logError, logWarning }; //# sourceMappingURL=global-functions.js.map