Published
Edited
Aug 30, 2021
3 stars
Insert cell
Insert cell
function prefixVarsInFormula(str, arg = "d", ignore = ["aq", "op"]) {
let shift = 0;
const add = `${arg}.`;
for (const { type, start, end, name } of P.parseCell(str).references) {
if (type === "Identifier" && name !== arg && !ignore.includes(name)) {
str = str.slice(0, start + shift) + add + name + str.slice(end + shift);
shift += add.length;
}
}
return str;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// https://github.com/observablehq/parser
P = require("@observablehq/parser@4")
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