scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
100 lines • 3.44 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var global_functions_exports = {};
__export(global_functions_exports, {
atob: () => atob,
btoa: () => btoa,
importModule: () => importModule,
log: () => log,
logError: () => logError,
logWarning: () => logWarning
});
module.exports = __toCommonJS(global_functions_exports);
var import_module_alias = __toESM(require("module-alias"));
import_module_alias.default.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));
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
atob,
btoa,
importModule,
log,
logError,
logWarning
});
//# sourceMappingURL=global-functions.js.map