function isPlainObject(value) { return !!value && typeof value === "object" && !Array.isArray(value) } function normalizePosition(value) { var next = String(value || "").trim() return /^(top|bottom|left|right)$/.test(next) ? next : "top" } function entrySettings(entry) { if (!isPlainObject(entry)) return {} var copy = {} for (var key in entry) { if (key === "id") continue copy[key] = entry[key] } return copy } function entryId(entry) { if (typeof entry === "string") return entry if (isPlainObject(entry)) { var id = entry["id"] if (id !== undefined && id !== null && String(id) !== "") return String(id) } return "" } function pinTrayToInner(entries, section) { var trayEntry = null var result = [] var values = Array.isArray(entries) ? entries : [] for (var i = 0; i < values.length; i++) { if (entryId(values[i]) === "omarchy.tray") trayEntry = values[i] else result.push(values[i]) } if (trayEntry) { if (section === "right") result.unshift(trayEntry) else result.push(trayEntry) } return result } function moduleString(entry, key, fallback) { var settings = entrySettings(entry) var value = settings[key] return value === undefined || value === null ? fallback : String(value) } function entryIndex(entries, name) { if (!Array.isArray(entries)) return -1 for (var i = 0; i < entries.length; i++) { if (entryId(entries[i]) === name) return i } return -1 } function entriesBefore(entries, name) { var index = entryIndex(entries, name) return index <= 0 ? [] : entries.slice(0, index) } function entriesAfter(entries, name) { var index = entryIndex(entries, name) return index === -1 ? [] : entries.slice(index + 1) } function expandPath(value, home) { var path = String(value || "") if (path === "") return "" if (path.indexOf("~/") === 0) return home + path.substring(1) if (path.indexOf("$HOME/") === 0) return home + path.substring(5) return path } function customModuleSafeName(name) { var value = String(name || "") return value !== "" && value.indexOf("..") === -1 && value[0] !== "/" } function customModuleType(entry) { var settings = entrySettings(entry) var type = String(settings.type || "") if (type) return type if (settings.exec) return "command" if (settings.source) return "qml" return "" } function customModulePath(entry, home, configDir) { var settings = entrySettings(entry) var name = entryId(entry) var source = settings.source ? expandPath(settings.source, home) : "" if (!source && customModuleSafeName(name)) source = String(configDir || "") + "/bar/modules/" + String(name) + ".qml" return source } if (typeof module !== "undefined") { module.exports = { normalizePosition: normalizePosition, entrySettings: entrySettings, entryId: entryId, pinTrayToInner: pinTrayToInner, moduleString: moduleString, entryIndex: entryIndex, entriesBefore: entriesBefore, entriesAfter: entriesAfter, expandPath: expandPath, customModuleSafeName: customModuleSafeName, customModuleType: customModuleType, customModulePath: customModulePath } }