You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/ui-default/utils/substitute.js

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;