UNPKG

@playkit-js/kaltura-player-js

Version:

[![Build Status](https://github.com/kaltura/kaltura-player-js/actions/workflows/run_canary.yaml/badge.svg)](https://github.com/kaltura/kaltura-player-js/actions/workflows/run_canary.yaml) [![code style: prettier](https://img.shields.io/badge/code_style-pr

26 lines (24 loc) 689 B
/** * @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;