Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function matchSeriesOverride(aliasOrRegex: string, seriesAlias: string) {
if (!aliasOrRegex) {
return false;
}
if (aliasOrRegex[0] === '/') {
const regex = stringToJsRegex(aliasOrRegex);
return seriesAlias.match(regex) != null;
}
return aliasOrRegex === seriesAlias;
}
metricNamesToVariableValues(metricNames: any[]) {
let regex, options, i, matches;
options = [];
if (this.regex) {
regex = stringToJsRegex(this.templateSrv.replace(this.regex, {}, 'regex'));
}
for (i = 0; i < metricNames.length; i++) {
const item = metricNames[i];
let text = item.text === undefined || item.text === null ? item.value : item.text;
let value = item.value === undefined || item.value === null ? item.text : item.value;
if (_.isNumber(value)) {
value = value.toString();
}
if (_.isNumber(text)) {
text = text.toString();
}
if (regex) {
matchComposite(pattern): number {
for (let index = 0; index < this.metricComposites.length; index++) {
const aComposite = this.metricComposites[index];
const regex = stringToJsRegex(aComposite.compositeName);
const matches = pattern.match(regex);
if (matches && matches.length > 0 && aComposite.enabled) {
return index;
}
}
return -1;
}
metricNamesToVariableValues(metricNames: any[]) {
let regex, options, i, matches;
options = [];
if (this.regex) {
regex = stringToJsRegex(this.templateSrv.replace(this.regex, {}, 'regex'));
}
for (i = 0; i < metricNames.length; i++) {
const item = metricNames[i];
let text = item.text === undefined || item.text === null ? item.value : item.text;
let value = item.value === undefined || item.value === null ? item.text : item.value;
if (_.isNumber(value)) {
value = value.toString();
}
if (_.isNumber(text)) {
text = text.toString();
}
if (regex) {
initColumns() {
this.formatters = [];
this.colorState = {};
for (let colIndex = 0; colIndex < this.table.columns.length; colIndex++) {
const column = this.table.columns[colIndex];
column.title = column.text;
for (let i = 0; i < this.panel.styles.length; i++) {
const style = this.panel.styles[i];
const escapedPattern = stringStartsAsRegEx(style.pattern)
? style.pattern
: escapeStringForRegex(unEscapeStringFromRegex(style.pattern));
const regex = stringToJsRegex(escapedPattern);
if (column.text.match(regex)) {
column.style = style;
if (style.alias) {
column.title = column.text.replace(regex, style.alias);
}
break;
}
}
this.formatters[colIndex] = this.createColumnFormatter(column);
}
}
matchOverride(pattern): number {
for (let index = 0; index < this.metricOverrides.length; index++) {
const anOverride = this.metricOverrides[index];
const regex = stringToJsRegex(anOverride.metricName);
const matches = pattern.match(regex);
if (matches && matches.length > 0 && anOverride.enabled) {
return index;
}
}
return -1;
}
kbn.stringToJsRegex = (str: string) => {
deprecationWarning('kbn.ts', 'kbn.stringToJsRegex()', '@grafana/data');
return stringToJsRegex(str);
};
function matchSeriesOverride(aliasOrRegex: string, seriesAlias: string) {
if (!aliasOrRegex) {
return false;
}
if (aliasOrRegex[0] === '/') {
const regex = stringToJsRegex(aliasOrRegex);
return seriesAlias.match(regex) != null;
}
return aliasOrRegex === seriesAlias;
}
kbn.stringToJsRegex = (str: string) => {
deprecationWarning('kbn.ts', 'kbn.stringToJsRegex()', '@grafana/data');
return stringToJsRegex(str);
};