Skip to content

Instantly share code, notes, and snippets.

@wavebeem
Last active Sep 28, 2018
Embed
What would you like to do?
#!/usr/bin/env bash
set -eu
main() {
Object.new |
Object.set name "$(echo Brian Mock | String.new)" |
Object.get name
Array.new |
Array.push 1 |
Array.push 2 |
Array.push "$(Math.multiply 3 4)" |
Array.get 2
}
Array.new() {
echo "[]"
}
Array.push() {
env \
arr="$(cat)" \
val="$1" \
node -pe "
var arr = JSON.parse(process.env.arr);
var val = JSON.parse(process.env.val);
arr.push(val);
JSON.stringify(arr);
"
}
Array.get() {
env \
arr="$(cat)" \
idx="$1" \
node -pe "
var arr = JSON.parse(process.env.arr);
var idx = JSON.parse(process.env.idx);
JSON.stringify(arr[idx]);
"
}
Object.new() {
echo "{}"
}
Object.set() {
env \
obj="$(cat)" \
key="$1" \
val="$2" \
node -pe "
var obj = JSON.parse(process.env.obj);
var key = process.env.key;
var val = JSON.parse(process.env.val);
obj[key] = val;
JSON.stringify(obj);
"
}
Object.get() {
env \
obj="$(cat)" \
key="$1" \
node -pe "
var obj = JSON.parse(process.env.obj);
var key = process.env.key;
JSON.stringify(obj[key]);
"
}
String.new() {
env \
str="$(cat)" \
node -pe "
var str = process.env.str;
JSON.stringify(str);
"
}
Number.new() {
env \
num="$(cat)" \
node -pe "
var num = +process.env.num;
JSON.stringify(num);
"
}
Math.multiply() {
env \
a="$1" \
b="$2" \
node -pe "
var a = +process.env.a;
var b = +process.env.b;
JSON.stringify(a * b)
"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment