scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
95 lines • 2.91 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var path_exports = {};
__export(path_exports, {
MockPath: () => MockPath
});
module.exports = __toCommonJS(path_exports);
var import_scriptable_abstract = require("scriptable-abstract");
const _DEFAULT_STATE = {
components: []
};
class MockPath extends import_scriptable_abstract.AbsPath {
constructor(components = []) {
super({
components: [...components]
});
}
get components() {
return [...this.state.components];
}
static parse(pathString) {
const normalized = pathString.replace(/\\/g, "/").replace(/^\/+/, "");
const components = normalized.split("/");
const result = [];
for (const component of components) {
if (!component || component === ".") {
continue;
}
if (component === "..") {
if (result.length > 0 && result[result.length - 1] !== "..") {
result.pop();
} else {
result.push("..");
}
continue;
}
result.push(component);
}
return new MockPath(result);
}
static join(...paths) {
const normalized = paths.map((p) => p.replace(/\\/g, "/")).filter(Boolean).join("/");
return MockPath.parse(normalized);
}
static documentsDirectory() {
return MockPath.parse("~/Documents");
}
static libraryDirectory() {
return MockPath.parse("~/Library");
}
static temporaryDirectory() {
return MockPath.parse("~/tmp");
}
static cacheDirectory() {
return MockPath.parse("~/Library/Caches");
}
toString() {
if (this.components.length === 0) return "";
return this.components.join("/");
}
appendComponent(component) {
const newComponents = [...this.components, component];
return new MockPath(newComponents);
}
appendingComponent(component) {
return this.appendComponent(component);
}
lastComponent() {
if (this.components.length === 0) return null;
return this.components[this.components.length - 1];
}
lastPathComponent() {
return this.lastComponent();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockPath
});
//# sourceMappingURL=path.js.map