<commit_before>/*---------------------------------*/
/*                                 */
 /*---------------------------------*/
  /* Blanket.js                      */
   /* version 1.0.0                   */
  /* See README.md for revision news */
 /*---------------------------------*/
  /*                                */
  /*-------------------------------*/


var fs = require("fs"),
    path = require("path"),
    configPath = process.cwd() + '/package.json',
    file = JSON.parse(fs.readFileSync(configPath, 'utf8')),
    packageConfig = file.scripts &&
                    file.scripts.blanket &&
                    file.scripts.blanket.pattern ?
                      file.scripts.blanket.pattern :
                      "src",
    pattern = packageConfig,
    blanket = require("./blanket").blanket,
    oldLoader = require.extensions['.js'];


blanket.options("filter",pattern);

//helper functions
blanket.normalizeBackslashes = function (str) {
    return str.replace(/\\/g, '/');
};

//you can pass in a string, a regex, or an array of files
blanket.matchPattern = function (filename,pattern){
    if (typeof pattern === 'string'){
        return filename.indexOf(blanket.normalizeBackslashes(pattern)) > -1;
    }else if ( pattern instanceof Array ){
        return pattern.some(function(elem){
            return filename.indexOf(blanket.normalizeBackslashes(elem)) > -1;
        });
    }else if (pattern instanceof RegExp){
        return pattern.test(filename);
    }else{
        throw new Error("Bad file instrument indicator.  Must be a string, regex, or array.");
    }
};

//instrument js files
require.extensions['.js'] = function(localModule, filename) {
    var pattern = blanket.options("filter");
    filename = blanket.normalizeBackslashes(filename);
    if (blanket.matchPattern(filename,pattern)){
        var content = fs.readFileSync(filename, 'utf8');
        blanket.instrument({
            inputFile: content,
            inputFileName: filename
        },function(instrumented){
            var baseDirPath = blanket.normalizeBackslashes(path.dirname(filename))+'/.';
            try{
                instrumented = instrumented.replace(/require\s*\(\s*("|')\./g,'require($1'+baseDirPath);
                localModule._compile(instrumented, filename);
            }
            catch(err){
                console.log("Error parsing instrumented code: "+err);
            }
        });
    }else{
        oldLoader(localModule,filename);
    }
};

//if a loader is specified, use it
if (file.scripts.blanket.loader){
    require(file.scripts.blanket.loader)(blanket);
}

module.exports = blanket;



<commit_msg>Update check for package.json config<commit_after>/*---------------------------------*/
/*                                 */
 /*---------------------------------*/
  /* Blanket.js                      */
   /* version 1.0.0                   */
  /* See README.md for revision news */
 /*---------------------------------*/
  /*                                */
  /*-------------------------------*/


var fs = require("fs"),
    path = require("path"),
    configPath = process.cwd() + '/package.json',
    file = JSON.parse(fs.readFileSync(configPath, 'utf8')),
    packageConfig = file.scripts &&
                    file.scripts.blanket &&
                    file.scripts.blanket.pattern,
    pattern = packageConfig  ?
                      file.scripts.blanket.pattern :
                      "src",
    blanket = require("./blanket").blanket,
    oldLoader = require.extensions['.js'];


blanket.options("filter",pattern);

//helper functions
blanket.normalizeBackslashes = function (str) {
    return str.replace(/\\/g, '/');
};

//you can pass in a string, a regex, or an array of files
blanket.matchPattern = function (filename,pattern){
    if (typeof pattern === 'string'){
        return filename.indexOf(blanket.normalizeBackslashes(pattern)) > -1;
    }else if ( pattern instanceof Array ){
        return pattern.some(function(elem){
            return filename.indexOf(blanket.normalizeBackslashes(elem)) > -1;
        });
    }else if (pattern instanceof RegExp){
        return pattern.test(filename);
    }else{
        throw new Error("Bad file instrument indicator.  Must be a string, regex, or array.");
    }
};

//instrument js files
require.extensions['.js'] = function(localModule, filename) {
    var pattern = blanket.options("filter");
    filename = blanket.normalizeBackslashes(filename);
    if (blanket.matchPattern(filename,pattern)){
        var content = fs.readFileSync(filename, 'utf8');
        blanket.instrument({
            inputFile: content,
            inputFileName: filename
        },function(instrumented){
            var baseDirPath = blanket.normalizeBackslashes(path.dirname(filename))+'/.';
            try{
                instrumented = instrumented.replace(/require\s*\(\s*("|')\./g,'require($1'+baseDirPath);
                localModule._compile(instrumented, filename);
            }
            catch(err){
                console.log("Error parsing instrumented code: "+err);
            }
        });
    }else{
        oldLoader(localModule,filename);
    }
};

//if a loader is specified, use it
if (packageConfig && file.scripts.blanket.loader){
    require(file.scripts.blanket.loader)(blanket);
}

module.exports = blanket;




{'fraction_non_alphanumeric': 0.18125816688445026, 'fraction_numerical': 0.0029867463132350197, 'mean_word_length': 1.8484848484848484, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '597658', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1395, 'n_words': 295}