How to use the @grafana/data.stringToJsRegex function in @grafana/data

To help you get started, we’ve selected a few @grafana/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grafana / grafana / public / app / core / time_series2.ts View on Github external
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;
}
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / features / templating / query_variable.ts View on Github external
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) {
github grafana / grafana-polystat-panel / src / composites_manager.ts View on Github external
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;
  }
github grafana / grafana / public / app / features / templating / query_variable.ts View on Github external
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) {
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / plugins / panel / table / renderer.ts View on Github external
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);
    }
  }
github grafana / grafana-polystat-panel / src / metric_overrides_manager.ts View on Github external
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;
  }
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / core / utils / kbn.ts View on Github external
kbn.stringToJsRegex = (str: string) => {
  deprecationWarning('kbn.ts', 'kbn.stringToJsRegex()', '@grafana/data');
  return stringToJsRegex(str);
};
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / core / time_series2.ts View on Github external
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;
}
github grafana / grafana / public / app / core / utils / kbn.ts View on Github external
kbn.stringToJsRegex = (str: string) => {
  deprecationWarning('kbn.ts', 'kbn.stringToJsRegex()', '@grafana/data');
  return stringToJsRegex(str);
};