summaryrefslogtreecommitdiff
path: root/utils.html
diff options
context:
space:
mode:
authorSimon Parri <simonparri@ganzeria.com>2025-02-16 23:29:02 -0600
committerSimon Parri <simonparri@ganzeria.com>2025-02-16 23:36:39 -0600
commitca51ae66c40c0f040b81a5ed7b39602eb30c4ad2 (patch)
tree01546304cf59582de29fd12e3c639e3aa1174397 /utils.html
downloadonpoint-0.1.tar.gz
onpoint-0.1.zip
Add version 0.1v0.1
Diffstat (limited to 'utils.html')
-rw-r--r--utils.html44
1 files changed, 44 insertions, 0 deletions
diff --git a/utils.html b/utils.html
new file mode 100644
index 0000000..5e96f56
--- /dev/null
+++ b/utils.html
@@ -0,0 +1,44 @@
+<script>
+const sleep = t => new Promise(r => setTimeout(r, t))
+
+Array.prototype.each = Array.prototype.forEach
+Array.prototype.shuffle = function() {
+ for (let i = this.length; i >= 0; --i) {
+ let j = Math.floor(Math.random() * (i + 1))
+ ;[this[i], this[j]] = [this[j], this[i]]
+ }
+ return this
+}
+Object.defineProperty(Array.prototype, -1, {
+ get() { return this[this.length-1] },
+ set(x) { this[this.length-1] = x },
+})
+
+Object.prototype.ǀ = function(f) { f(this); return this }
+Object.prototype.in_p = function(coll) { return coll.includes(this) }
+
+
+const fi = ss => x => x[ss[0]]
+const ff = ss => (x, ...a) => x[ss[0]](...a)
+
+const ė = (name, props, ...children) =>
+ Object.assign(document.createElement(name), props)
+ .ǀ(e => e.append(...children))
+
+const Œ = Object.assign
+const Æ = (size, fill) => Array(size).fill(fill)
+
+const 𝑓 = (ss, ...ii) => (
+ ss = ss.flatMap((s, i) => [s, ii[i] ? `arguments[${ii[i]-1}]` : ""]),
+ new Function("", `return (${ss.join("")})`)
+)
+
+const ı = i => Æ(i).map(𝑓`${2}`)
+
+const Enum = ss =>
+ Object.fromEntries(ss[0]
+ .trim()
+ .split(/\s*,\s*/)
+ .filter(fi`length`)
+ .map(Array))
+</script>