kibana/x-pack/plugins/ml/common/util/string_utils.js
2018-04-24 13:48:10 -07:00

23 lines
609 B
JavaScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
// A simple template renderer, it replaces mustache/angular style {{...}} tags with
// the values provided via the data object
export function renderTemplate(str, data) {
const matches = str.match(/{{(.*?)}}/g);
if (Array.isArray(matches)) {
matches.forEach(v => {
str = str.replace(v, data[v.replace(/{{|}}/g, '')]);
});
}
return str;
}