@playkit-js/kaltura-player-js
Version:
[](https://github.com/kaltura/kaltura-player-js/actions/workflows/run_canary.yaml) [ • 689 B
text/typescript
/**
* @private
* @param {string} template - The template string to evaluate
* @param {Object} model - The model to evaluate with
* @return {string} - The evaluated string
*/
function evaluate(template: string, model: any = {}): string {
try {
let reg,
res = template;
for (const key in model) {
let value = model[key] !== undefined && model[key] !== null ? model[key] : '';
if (typeof value === 'string' && value.indexOf('"') > -1) {
value = value.replace(/"/g, '\\"');
}
reg = new RegExp('{{' + key + '}}', 'g');
res = res.replace(reg, value);
}
return res;
} catch (e) {
return '';
}
}
export default evaluate;