mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-31 19:27:00 -06:00
22 lines
604 B
JavaScript
22 lines
604 B
JavaScript
/**
|
|
* Injects content into string
|
|
* @param string {String}
|
|
* @param data {Object} - content to replace
|
|
* @return {*}
|
|
*/
|
|
function stringFormat(string, data) {
|
|
for (let key in data) {
|
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
return string.replace(/({([^}]+)})/g, function (i) {
|
|
let replacedKey = i.replace(/{/, '').replace(/}/, '');
|
|
if (!data[replacedKey]) {
|
|
return i;
|
|
}
|
|
return data[replacedKey];
|
|
});
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
module.exports = stringFormat; |