mout
Version:
Modular Utilities
18 lines (14 loc) • 443 B
text/typescript
import toString from '../lang/toString';
import get from '../object/get';
const stache = /\{\{([^\}]+)\}\}/g; // mustache-like
/**
* String interpolation
*/
function interpolate(template, replacements, syntax) {
template = toString(template);
const replaceFn = function(match, prop) {
return toString(get(replacements, prop));
};
return template.replace(syntax || stache, replaceFn);
}
export default interpolate;