<commit_before>/**
 * @file
 * Defines and exports a simple function that will escape a string literal for use
 * as an argument in the standard JS RegExp object constructor function.
 * 
 * @note
 * These documentation blocks can be parsed by the "Doxygen" documentation generator.
 * @see http://stack.nl/~dmitri/doxygen
 */

'use strict'

var defaultEscapeCharsRegex =  /[-|\\{}()[\]^$+*?.]/g;

/**
 * @param patternString The string containing a regex pattern that needs to be escaped.
 * @param charactersToEscapeRegexPattern An optional RegEx pattern containing a set 
 *   of characters to escape. If not passed, will be set to default.
 * @return string The escaped regex pattern string.
 */
var escapeRegexString = function(unescapedString, escapeCharsRegex) {
  // Validate arguments.
  if (Object.prototype.toString.call(unescapedString) !== '[object String]') {
    throw new TypeError('Argument 1 should be a string.');
  }
  if (escapeCharsRegex === undefined) {
    escapeCharsRegex = defaultEscapeCharsRegex;
  }
  else if (Object.prototype.toString.call(escapeCharsRegex) !== '[object RegExp]') {
    throw new TypeError('Argument 2 should be a RegExp object.');
  }
  
  // Escape the string.
  return unescapedString.replace(escapeCharsRegex, '\\$&');
}

<commit_msg>Changed function from function expression to function statement. Used Object.defineProperty to change default pattern property to read-only. About to begin debugging.<commit_after>/**
 * @file
 * Defines and exports a simple function that will escape a string literal for use
 * as an argument in the standard JS RegExp object constructor function.
 * 
 * @note
 * These documentation blocks can be parsed by the "Doxygen" documentation generator.
 * @see http://stack.nl/~dmitri/doxygen
 */

'use strict'

var defaultEscapeCharsRegex =  /[-|\\{}()[\]^$+*?.]/g;

/**
 * @param patternString The string containing a regex pattern that needs to be escaped.
 * @param charactersToEscapeRegexPattern An optional RegEx pattern containing a set 
 *   of characters to escape. If not passed, will be set to default.
 * @return string The escaped regex pattern string.
 */
function escapeRegexString(unescapedString, escapeCharsRegex) {
  // Validate arguments.
  if (Object.prototype.toString.call(unescapedString) !== '[object String]') {
    throw new TypeError('Argument 1 should be a string.');
  }
  if (escapeCharsRegex === undefined) {
    escapeCharsRegex = defaultEscapeCharsRegex;
  }
  else if (Object.prototype.toString.call(escapeCharsRegex) !== '[object RegExp]') {
    throw new TypeError('Argument 2 should be a RegExp object.');
  }
  
  // Escape the string.
  return unescapedString.replace(escapeCharsRegex, '\\$&');
}

/**
 * Define a read-only property on the function object to contain default RegExp pattern.
 * This allows the user to utilize the pattern for his or her own purpose.
 */
Object.defineProperty(
  escapeRegexString,
  'defaultEscapeCharsRegex',
  {
    configurable: false,
    enumerable: true,
    value: defaultEscapeCharsRegex,
    writable: false
  }
);

/**
 * Expose escape-regex-string
 */
module.exports = escapeRegexString;

{'fraction_non_alphanumeric': 0.1065651760228354, 'fraction_numerical': 0.0012686330478908975, 'mean_word_length': 4.038338658146965, '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': '2024860', 'n_tokens_mistral': 893, 'n_tokens_neox': 866, 'n_words': 319}