-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TemplateFormulaCell : Possibility to add a template for a custom formula #158
Comments
I see common assumptions with another proposal #152 |
Found this technique on stackoverflow - not as flexible as eval() but would cause less security concern maybe? I have not tested or considered how it would fit in the scheme of things. https://stackoverflow.com/questions/29182244/convert-a-string-to-a-template-string const regex = /\${[^{]+}/g;
export default function interpolate(template, variables, fallback) {
return template.replace(regex, (match) => {
const path = match.slice(2, -1).trim();
return getObjPath(path, variables, fallback);
});
}
//get the specified property or nested property of an object
function getObjPath(path, obj, fallback = '') {
return path.split('.').reduce((res, key) => res[key] || fallback, obj);
} Usageconst replacements = {
name: 'Bob',
age: 37
}
interpolate('My name is ${name}, and I am ${age}.', replacements) |
I move this issue into issues list and mark as The
|
As @jasonclake requested on a Gitter channel
Transform something like
Into:
The text was updated successfully, but these errors were encountered: