<commit_before>var Promise = require('promise');
var jsonFormater = require('./jsl-format');

var TOKEN = (Math.random() + 1).toString(36).slice(2, 7);
var WRAP_START = "<wrap_" + TOKEN + ">";
var WRAP_END = "</wrap_" + TOKEN +">";
var NUM_REGEX = /^-?\d+\.?[\deE]*$/g;

var WRAP_REGEX = new RegExp(
  "^" + WRAP_START + "(-?\\d+\\.?[\\deE]*)" + WRAP_END + "$", "g"
);

var REPLACE_WRAP_REGEX = new RegExp(
  "\"" + WRAP_START + "(-?\\d+\\.?[\\deE]*)" + WRAP_END + "\"", "g"
);

function contentExtractor(pre, options) {
  return new Promise(function(resolve, reject) {
    try {
      var rawJsonText = pre.textContent;
      var wrappedText = wrapNumbers(rawJsonText);
      var jsonExtracted = extractJSON(wrappedText);

      var jsonParsed = JSON.parse(jsonExtracted);
      if (options.addons.sortKeys) jsonParsed = sortByKeys(jsonParsed);

      // Validate and decode json
      var decodedJson = JSON.stringify(jsonParsed);
      decodedJson = decodedJson.replace(REPLACE_WRAP_REGEX, "$1");

      var jsonFormatted = jsonFormater(decodedJson, options.structure);
      var jsonText = wrappedText.replace(jsonExtracted, jsonFormatted);
      resolve({jsonText: jsonText, jsonExtracted: decodedJson});

    } catch(e) {
      reject(new Error('contentExtractor: ' + e.message));
    }
  });
}

function extractJSON(rawJson) {
  return rawJson.replace(/^.+[a-zA-Z0-9_$\.]+\(/, '').replace(/\);?\s*$/, '');
}
<commit_msg>fixed highlight of JSONP callbacks which contains numbers (issue #50 and issue #51)<commit_after>var Promise = require('promise');
var jsonFormater = require('./jsl-format');

var TOKEN = (Math.random() + 1).toString(36).slice(2, 7);
var WRAP_START = "<wrap_" + TOKEN + ">";
var WRAP_END = "</wrap_" + TOKEN +">";
var NUM_REGEX = /^-?\d+\.?[\deE]*$/g;

var WRAP_REGEX = new RegExp(
  "^" + WRAP_START + "(-?\\d+\\.?[\\deE]*)" + WRAP_END + "$", "g"
);

var REPLACE_WRAP_REGEX = new RegExp(
  "\"" + WRAP_START + "(-?\\d+\\.?[\\deE]*)" + WRAP_END + "\"", "g"
);

function contentExtractor(pre, options) {
  return new Promise(function(resolve, reject) {
    try {
      var rawJsonText = pre.textContent;
      var jsonExtracted = extractJSON(rawJsonText);
      var wrappedText = wrapNumbers(jsonExtracted);

      var jsonParsed = JSON.parse(wrappedText);
      if (options.addons.sortKeys) jsonParsed = sortByKeys(jsonParsed);

      // Validate and decode json
      var decodedJson = JSON.stringify(jsonParsed);
      decodedJson = decodedJson.replace(REPLACE_WRAP_REGEX, "$1");

      var jsonFormatted = jsonFormater(decodedJson, options.structure);
      var jsonText = rawJsonText.replace(jsonExtracted, jsonFormatted);
      resolve({jsonText: jsonText, jsonExtracted: decodedJson});

    } catch(e) {
      reject(new Error('contentExtractor: ' + e.message));
    }
  });
}

function extractJSON(rawJson) {
  return rawJson.replace(/^.+[a-zA-Z0-9_$\.]+\(/, '').replace(/\);?\s*$/, '');
}

{'fraction_non_alphanumeric': 0.18878248974008208, 'fraction_numerical': 0.006839945280437756, 'mean_word_length': 3.695024077046549, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4815087', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1032, 'n_words': 198}