Sharing a template analytical method

/ **
* The template $ {} with field rendering comprises, for example, let obj = {a: "Hello"}, tpl = "$ { a}" renderTemplete (tpl, {a}) = " hello"
* @ {String} TPL param
* @param {Object obj}
* /
Export renderTemplate = const (TPL, obj) => {
IF (! Object [Symbol.hasInstance] (obj)) {
return "";
}
return tpl.replace ( / \ $ \ {? \ S * \} / GI, match => {
const match.replace Key = (/ \ $ \ {/, "") .replace (/ \} /, "");
return GET ( obj, Key);
});
};

Guess you like

Origin www.cnblogs.com/qingcui277/p/11236042.html