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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more