mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
14 lines
311 B
JavaScript
14 lines
311 B
JavaScript
/**
|
|
* @param {string} str
|
|
* @param {any} obj
|
|
* @returns {string}
|
|
*/
|
|
export default function substitute(str, obj) {
|
|
return str.replace(/\{([^{}]+)\}/g, (match, key) => {
|
|
if (obj[key] !== undefined) return obj[key].toString();
|
|
return `{${key}}`;
|
|
});
|
|
}
|
|
|
|
window.Hydro.utils.substitute = substitute;
|