<commit_before>'use strict';

const EventEmitter = require('events');
const keys = require('lodash.keys');
const isObject = require('lodash.isplainobject');
const isArray = require('lodash.isarray');
const includes = require('lodash.includes');
const Iterator = require('./iterator');
const ObjectGenerator = require('./object-generator');
const TypeChecker = require('hadron-type-checker');
const uuid = require('node-uuid');

/**
 * The event constant.
 */
const Events = {
  'Added': 'Element::Added',
  'Edited': 'Element::Edited',
  'Removed': 'Element::Removed',
  'Reverted': 'Element::Reverted'
};

/**
 * Id field constant.
 */
const ID = '_id';

/**
 * Types that are not editable.
 */
const UNEDITABLE_TYPES = [
  'ObjectID',
  'Binary',
  'Code',
  'MinKey',
  'MaxKey',
  'Timestamp'
];

/**
 * Curly brace constant.
 */
const CURLY = '{';

/**
 * Bracket constant.
 */
const BRACKET = '[';

/**
 * Regex to match an array or object string.
 */
const ARRAY_OR_OBJECT = /^(\[|\{)(.+)(\]|\})$/;

/**
 * Represents an element in a document.
 */
class Element extends EventEmitter {

  /**
   * Bulk edit the element. Can accept JSON strings.
   *
   * @param {String} value - The JSON string value.
   */
  bulkEdit(value) {
    if (value.match(ARRAY_OR_OBJECT)) {
      this.edit(JSON.parse(value));
    } else {
      this.edit(value);
    }
  }

  /**
   * Create the element.<commit_msg>INT-1770: Bubble up converted event<commit_after>'use strict';

const EventEmitter = require('events');
const keys = require('lodash.keys');
const isObject = require('lodash.isplainobject');
const isArray = require('lodash.isarray');
const includes = require('lodash.includes');
const Iterator = require('./iterator');
const ObjectGenerator = require('./object-generator');
const TypeChecker = require('hadron-type-checker');
const uuid = require('node-uuid');

/**
 * The event constant.
 */
const Events = {
  'Added': 'Element::Added',
  'Edited': 'Element::Edited',
  'Removed': 'Element::Removed',
  'Reverted': 'Element::Reverted',
  'Converted': 'Element::Converted'
};

/**
 * Id field constant.
 */
const ID = '_id';

/**
 * Types that are not editable.
 */
const UNEDITABLE_TYPES = [
  'ObjectID',
  'Binary',
  'Code',
  'MinKey',
  'MaxKey',
  'Timestamp'
];

/**
 * Curly brace constant.
 */
const CURLY = '{';

/**
 * Bracket constant.
 */
const BRACKET = '[';

/**
 * Regex to match an array or object string.
 */
const ARRAY_OR_OBJECT = /^(\[|\{)(.+)(\]|\})$/;

/**
 * Represents an element in a document.
 */
class Element extends EventEmitter {

  /**
   * Bulk edit the element. Can accept JSON strings.
   *
   * @param {String} value - The JSON string value.
   */
  bulkEdit(value) {
    if (value.match(ARRAY_OR_OBJECT)) {
      this.edit(JSON.parse(value));
      this._bubbleUp(Events.Converted);
    } else {
      this.edit(value);
    }
  }

  /**
   * Create the element.
{'fraction_non_alphanumeric': 0.18441916580489487, 'fraction_numerical': 0.0013788348845225785, 'mean_word_length': 3.48531684698609, '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': '4960144', 'n_tokens_mistral': 976, 'n_tokens_neox': 965, 'n_words': 234}