Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit a6666bd

Browse files
committed
Added file info comments, Broke out common functions, Fixed bugs, improved dependency sort
1 parent a52b1b4 commit a6666bd

16 files changed

+528
-261
lines changed

dist/ScriptMerge built.scriptable

Lines changed: 12 additions & 0 deletions
Large diffs are not rendered by default.

dist/ScriptMerge.js

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ScriptMerge.scriptable

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Benchmark.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Variables used by Scriptable.
2+
// These must be at the very top of the file. Do not edit.
3+
// icon-color: deep-gray; icon-glyph: magic;
4+
/**
5+
* FILE: Benchmark.js
6+
*
7+
* A dead-simple benchmarking suite
8+
*
9+
* @author oezingle (oezingle@gmail.com)
10+
**/
11+
12+
const Benchmark = class {
13+
constructor (title = "Benchmark") {
14+
this.title = title
15+
16+
this.steps = []
17+
}
18+
19+
step(name) {
20+
const time = Date.now()
21+
22+
this.steps.push({name,time})
23+
}
24+
25+
start () {
26+
this.starting = Date.now()
27+
}
28+
29+
finish () {
30+
const end = Date.now()
31+
32+
const delta = end - this.starting
33+
34+
const seconds = delta / 1000
35+
36+
console.log(`${this.title} Finished `.padEnd(46, '='))
37+
console.log(`Time: ${seconds}s`)
38+
39+
this.steps.forEach(({name, time}, i) => {
40+
const next = this.steps[i+1]?.time ?? end
41+
42+
const stepDelta = next - time
43+
44+
const stepP = (stepDelta/delta) * 100
45+
46+
console.log(` - ${stepP.toFixed(1).toString().padStart(4)}% ${name}`)
47+
})
48+
49+
console.log("Run Benchmark multiple times for best results")
50+
51+
console.log('='.repeat(46))
52+
}
53+
}
54+
55+
importModule("shouldDemo")(module, () => {
56+
let benchmark = new Benchmark()
57+
58+
benchmark.start()
59+
60+
benchmark.step('For')
61+
for (let i = 0; i < 1000000; i++) {
62+
}
63+
64+
benchmark.step("While")
65+
let i = 0
66+
while (i < 1000000) i++
67+
68+
benchmark.step("Fast")
69+
70+
for (let q = 0; q < 100000; q ++) {}
71+
72+
benchmark.finish()
73+
})
74+
75+
module.exports = Benchmark

src/BracketBuffer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
// These must be at the very top of the file. Do not edit.
33
// icon-color: gray; icon-glyph: magic;
44
/**
5-
* TODO: edge case w/ code formatted like:
5+
* FILE: BracketBuffer.js
6+
*
7+
* Use brackets, string literals, and regex to
8+
* determine scope at a basic level. Does not
9+
* play well witn comments
10+
*
11+
* @author oezingle (oezingle@gmail.com)
12+
**/
13+
14+
/**
15+
* BEWARE: edge case w/ code formatted like:
616
* const fn = () =>
717
* {
818
* ...
919
* }
1020
* because of BracketBuffer.moveUntilLineEnd()
21+
* Minify your code if it looks like this!
1122
**/
1223

1324
// how on earth is regex detected

src/HardenedFS.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ const HardenedFS = class {
117117
directory = HardenedFS.directory
118118

119119
path (path) {
120-
return path.replace(
121-
'~', this.instance.documentsDirectory()
122-
)
120+
const docs = this.instance.documentsDirectory()
121+
122+
return path
123+
.replace(/\/[^\/]*\/\.\./g, '')
124+
.replace(/^~/m, docs)
123125
}
124126
}
125127

@@ -134,7 +136,8 @@ importModule("shouldDemo")(module, () => {
134136
Test.test(() => {fm.readString("@")}, "readString", true),
135137
Test.test(() => {fm.readImage("@")}, "readImage", true),
136138
Test.test(() => {fm.read("@")}, "read", true),
137-
Test.assert(fm.directory("/dir/file.ext"), "/dir", "Directory")
139+
Test.assert(fm.directory("/dir/file.ext"), "/dir", "Directory"),
140+
Test.assert(fm.path("/dir/../"), "/", "Path")
138141
)
139142
})
140143

src/ObjectiveCProxy.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
// Variables used by Scriptable.
22
// These must be at the very top of the file. Do not edit.
33
// icon-color: purple; icon-glyph: magic;
4+
/**
5+
* FILE: ObjectiveCProxy.js
6+
*
7+
* Provide Proxy-like functionality for
8+
* Scriptable Objective-C native objects
9+
* (eg, Alert, QuickLook). JS's Proxy with a
10+
* native object with a getter handler (often)
11+
* results in an error.
12+
*
13+
* @author oezingle (oezingle@gmail.com)
14+
**/
15+
416
const ObjectiveCProxy = class {
517
constructor (target, handler) {
618
this.target = target

0 commit comments

Comments
 (0)