<commit_before>import { generateUId } from './utils';
import Joi from 'joi';

const restrictedEvents = ['error', 'subscribe', 'unsubscribe'];
const validEventPattern = /^([A-Za-z0-9]+\.?)+$/;

export default class Event {
  static validate(eventIdentifier) {
    Joi.assert(eventIdentifier, Joi.alternatives().try(
      Joi.string().required().regex(validEventPattern).invalid(restrictedEvents),
      Joi.object().type(RegExp),
    ).required());
  }

  static normalize(eventIdentifier) {
    Event.validate(eventIdentifier);

    if (typeof eventIdentifier === 'string') {
      return eventIdentifier.trim();
    }

    return eventIdentifier;
  }

  static from(eventOrIdentifier, parent, meta) {
    if (eventOrIdentifier instanceof Event) {
      return {
        ...eventOrIdentifier,
        parent,
        meta: {
          ...(eventOrIdentifier.meta || {}),
          ...meta,
        },
      };
    }

    return new Event(eventOrIdentifier, parent, meta);
  }

  constructor(identifier, parent, meta = {}) {
    this.identifier = Event.normalize(identifier);
    this.parent = parent;
    this.meta = meta;
    this.uid = generateUId();
  }

  toString() {
    return this.identifier.toString();
  }

  isMatch(matcher) {
    if (this.identifier instanceof RegExp && (typeof matcher === 'string')) {
      return this.identifier.test(matcher);
    }

    if (matcher instanceof RegExp && (typeof this.identifier === 'string')) {
      return matcher.test(this.identifier);
    }

    return this.toString() === matcher.toString();
  }
}
<commit_msg>bugfix<commit_after>import { generateUId } from './utils';
import Joi from 'joi';

const restrictedEvents = ['error', 'subscribe', 'unsubscribe'];
const validEventPattern = /^([A-Za-z0-9]+\.?)+$/;

export default class Event {
  static validate(eventIdentifier) {
    Joi.assert(eventIdentifier, Joi.alternatives().try(
      Joi.string().required().regex(validEventPattern).invalid(restrictedEvents),
      Joi.object().type(RegExp),
    ).required());
  }

  static normalize(eventIdentifier) {
    Event.validate(eventIdentifier);

    if (typeof eventIdentifier === 'string') {
      return eventIdentifier.trim();
    }

    return eventIdentifier;
  }

  static from(eventOrIdentifier, parent, meta) {
    if (eventOrIdentifier instanceof Event) {
      return Object.assign(eventOrIdentifier, {
        parent,
        meta: {
          ...(eventOrIdentifier.meta || {}),
          ...meta,
        },
      });
    }

    return new Event(eventOrIdentifier, parent, meta);
  }

  constructor(identifier, parent, meta = {}) {
    this.identifier = Event.normalize(identifier);
    this.parent = parent;
    this.meta = meta;
    this.uid = generateUId();
  }

  toString() {
    return this.identifier.toString();
  }

  isMatch(matcher) {
    if (this.identifier instanceof RegExp && (typeof matcher === 'string')) {
      return this.identifier.test(matcher);
    }

    if (matcher instanceof RegExp && (typeof this.identifier === 'string')) {
      return matcher.test(this.identifier);
    }

    return this.toString() === matcher.toString();
  }
}

{'fraction_non_alphanumeric': 0.14966421490246243, 'fraction_numerical': 0.0012791813239526704, 'mean_word_length': 3.067620286085826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6906491', 'n_tokens_mistral': 929, 'n_tokens_neox': 898, 'n_words': 186}