Public
Edited
Mar 24, 2023
Insert cell
Insert cell
class ReQL {
constructor(str) {
this.str = str;
}
toString() {
return this.str;
}
}
Insert cell
format_reql = (value) => {
if (typeof value === "string") {
return JSON.stringify(value);
} else if (typeof value === "boolean") {
return value ? "true" : "false";
} else if (typeof value === "number") {
return value.toString();
} else if (value instanceof ReQL) {
return `(${value.str})`;
} else {
throw new Error("Oof");
}
}
Insert cell
reql = (string_parts, ...args) => {
let content = string_parts[0];
for (let n of _.range(1, string_parts.length)) {
content += format_reql(args[n - 1]);
content += string_parts[n];
}
return new ReQL(content);
}
Insert cell
reql`
if ${reql` 'hi' `}
then 20
else 10
`
.toString()
.replaceAll(/(^\s*|(\()\s*|\s*(\))|\s*$)/g, "$2$3")
.replaceAll(/\s*(\n)\s*/g, " ")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more