-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheddaLib.js
More file actions
117 lines (117 loc) · 3.15 KB
/
eddaLib.js
File metadata and controls
117 lines (117 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: eye;
// frontend utils (will be absorbing various others soon)
const VERSION = "1.3.0"
function makeAlert(title, message) {
let a = new Alert
a.title = title
a.message = message
return a
}
function makePrompt(title, message, placeholder) {
let a = makeAlert(title, message)
a.addTextField(placeholder)
a.addAction("OK")
return a
}
function prompt(title, message, placeholder) {
let a = makePrompt(title, message, placeholder)
return a.presentAlert().then(i => {
if (i == 0) {
return a.textFieldValue(0)
} else {
return null
}
})
}
// Helper: stringify keys safely (handles Symbols)
function keyToString(key) {
return typeof key === "symbol" ? key.toString() : key
}
// ===================== DICT PRINT =====================
function dictPrintBase(dictionary, name, first = true, lastness = [], seen = new Set()) {
let output = ""
if (seen.has(dictionary)) {
return "[Circular]\n"
}
seen.add(dictionary)
if (first) {
output += name + "\n"
}
let keys = Reflect.ownKeys(dictionary)
for (let i = 0; i < keys.length; i++) {
let lasty = lastness.slice()
// indentation
for (let j = 0; j < lasty.length; j++) {
output += lasty[j] ? " " : "│ "
}
// branch
output += (i === keys.length - 1) ? "└─" : "├─"
let key = keys[i]
let keyName = keyToString(key)
let value = dictionary[key]
output += keyName
if (Array.isArray(value)) {
output += "\n"
lasty.push(i === keys.length - 1)
output += listPrintBase(value, keyName, false, lasty, seen)
} else if (typeof value === "object" && value !== null) {
output += "\n"
lasty.push(i === keys.length - 1)
output += dictPrintBase(value, keyName, false, lasty, seen)
} else {
output += ": " + value + "\n"
}
}
return output
}
function dictPrint(name) {
return dictPrintBase(eval(name), name)
}
// ===================== LIST PRINT =====================
function listPrintBase(list, name, first = true, lastness = [], seen = new Set()) {
let output = ""
if (seen.has(list)) {
return "[Circular]\n"
}
seen.add(list)
if (first) {
output += name + "\n"
}
for (let i = 0; i < list.length; i++) {
let lasty = lastness.slice()
// indentation
for (let j = 0; j < lasty.length; j++) {
output += lasty[j] ? " " : "│ "
}
// branch
output += (i === list.length - 1) ? "└─" : "├─"
let value = list[i]
if (Array.isArray(value)) {
output += "[list]\n"
lasty.push(i === list.length - 1)
output += listPrintBase(value, name, false, lasty, seen)
} else if (typeof value === "object" && value !== null) {
output += "{dict}\n"
lasty.push(i === list.length - 1)
output += dictPrintBase(value, name, false, lasty, seen)
} else {
output += value + "\n"
}
}
return output
}
function listPrint(name) {
return listPrintBase(eval(name), name)
}
module.exports = {
makeAlert,
makePrompt,
prompt,
dictPrintBase,
dictPrint,
listPrintBase,
listPrint,
VERSION
}