Public
Edited
Nov 3, 2023
Importers
3 stars
Insert cell
Insert cell
function ttemplatify(fn){
return (strings, ...exprs) => {
let template = '';
for (let i = 0; i < strings.length - 1; i++) {
template += strings.raw[i] + exprs[i];
}
template += strings.raw[strings.length - 1];
return fn(template.replace(/(\\[$`])/g, '`'));
};
}
Insert cell
// This isn't actually useful for anything, but it
// demonstrates how one might use `ttemplatify`
json = ttemplatify(str => JSON.parse(str))
Insert cell
json`{
"${Math.PI}": "Hmm, Pi",
"${Math.E}": "Some kind of absurdist deep-fried meme?"
}`
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