<commit_before>/*
 * StdError
 *
 */

module.exports = StdError;

//==============================================================================
//-- constructor

function StdError(message) {
  if (! (this instanceof StdError)) {
    return new StdError(message);
  }

  Error.captureStackTrace(this, this.constructor);

  //-- defaults...
  this.code = 0;
  this.name = "StdError";
  this.message = "Standard Error";

  if (typeof(message) === "object") {
    (message.code) && (this.code = message.code);
    (message.name) && (this.name = message.name);
    (message.message) && (this.message = message.message);
  }
  if (typeof(message) === "string") {
    this.message = message;
  }
}

//------------------------------------------------------------------------------

StdError.prototype = Object.create(Error.prototype);
StdError.prototype.constructor = StdError;
StdError._name = StdError.name;

//------------------------------------------------------------------------------

StdError.extend = extend.bind(StdError);

function extend(options) {
  var self = this;
  var code, name, message;

  switch (typeof(options)) {
    case "string":
      name = options;
      break;
    case "object":
      code = options.code;
      name = options.name;
      message = options.message;
      break;
  }

  function init(obj, constructor, args) {
    constructor.apply(obj, args);
    (code) && (obj.code = code);
    (name) && (obj.name = name);
    obj.message = message || obj.name;

    return obj;
  }

  //-- constructor
  var child = function() {
    var args = Array.prototype.slice.call(arguments);

    if (! (this instanceof child)) {
      var obj = Object.create(child.prototype);
      return init(obj, child, args);
    }

    init(this, self, args);
  };

  child.prototype = Object.create(self.prototype);
  child.prototype.constructor = child;
  child.extend = extend.bind(child);
  child.define = define.bind(child);
  child._name = name;

  return child;
}

//------------------------------------------------------------------------------

StdError.define = define.bind(StdError);;

function define(options) {
  var self = this;
  var E = self[(typeof(options) === "object") ? options.parent : ""];
  var error = (E || self).extend(options);

  if (error) {
    Object.defineProperty(self, error._name, { value: error });
  }

  return error;
}

//==============================================================================<commit_msg>optimized code to make it more OOP<commit_after>/*
 * StdError
 *
 */

module.exports = StdError;

//==============================================================================
//-- constructor

function StdError(message) {
  if (! (this instanceof StdError)) {
    return new StdError(message);
  }

  Error.captureStackTrace(this, this.constructor);

  //-- defaults...
  this.code = 0;
  this.name = "StdError";
  this.message = "Standard Error";

  if (typeof(message) === "object") {
    (message.code) && (this.code = message.code);
    (message.name) && (this.name = message.name);
    (message.message) && (this.message = message.message);
  }
  if (typeof(message) === "string") {
    this.message = message;
  }
}

//------------------------------------------------------------------------------

StdError.prototype = Object.create(Error.prototype);
StdError.prototype.constructor = StdError;

//------------------------------------------------------------------------------

Object.defineProperty(StdError, "_name", { value: StdError.name });

//------------------------------------------------------------------------------

Object.defineProperty(StdError, "extend", {
  value: function(options) {
    var self = this;
    var code, name, message;

    switch (typeof(options)) {
      case "string":
        name = options;
        break;
      case "object":
        code = options.code;
        name = options.name;
        message = options.message;
        break;
    }

    function init(obj, constructor, args) {
      constructor.apply(obj, args);
      (code) && (obj.code = code);
      (name) && (obj.name = name);
      obj.message = message || obj.name;

      return obj;
    }

    //-- constructor
    var child = function() {
      var args = Array.prototype.slice.call(arguments);

      if (! (this instanceof child)) {
        var obj = Object.create(child.prototype);
        return init(obj, child, args);
      }

      init(this, self, args);
    };

    child.prototype = Object.create(self.prototype);
    child.prototype.constructor = child;
    Object.defineProperty(child, "extend", { value: self.extend });
    Object.defineProperty(child, "define", { value: self.define });
    Object.defineProperty(child, "_name", { value: name });

    return child;
  }
});

//------------------------------------------------------------------------------

Object.defineProperty(StdError, "define", {
  value: function(options) {
    var self = this;
    var E = self[(typeof(options) === "object") ? options.parent : ""];
    var error = (E || self).extend(options);

    if (error) {
      Object.defineProperty(self, error._name, { value: error });
    }

    return error;
  }
});

//==============================================================================
{'fraction_non_alphanumeric': 0.29849895496864903, 'fraction_numerical': 0.0003800114003420103, 'mean_word_length': 2.1074380165289255, 'pattern_counts': {'":': 4, '<': 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': '5839380', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1408, 'n_words': 310}