35302ed273
* [ML] Client side cut over * updating paths and commented code * changes based on review * disabling telemetry tests * fixing start job stylesheets * fixing everything that is broken * fixing types and ml icon order * using icon constant
24 lines
889 B
TypeScript
24 lines
889 B
TypeScript
/*
|
|
* 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: string, data?: Record<string, string>): string {
|
|
const matches = str.match(/{{(.*?)}}/g);
|
|
|
|
if (Array.isArray(matches) && data !== undefined) {
|
|
matches.forEach(v => {
|
|
str = str.replace(v, data[v.replace(/{{|}}/g, '')]);
|
|
});
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
export function getMedianStringLength(strings: string[]) {
|
|
const sortedStringLengths = strings.map(s => s.length).sort((a, b) => a - b);
|
|
return sortedStringLengths[Math.floor(sortedStringLengths.length / 2)] || 0;
|
|
}
|