<commit_before>const parser = require('./lib/parser.js').parser;
const ruler = require('./lib/createLineRules.js');
const inject = require('./lib/injector.js');
const run = require('./lib/run.js');
const fs = require('fs');

const minty = {};

/**
* reads the file the user provides, creates an abstract syntax tree, creates rules, injects monitoring code based on rules, generates html file for user
* @param {file path to file user wants us to analyze} path
**/
function file(path) {
  const JSTEXT = fs.readFileSync(path).toString();
  const parsed = parser(JSTEXT);
  const rules = ruler(parsed);
  const injected = inject(rules, JSTEXT);
  run.runFile(injected, path, JSTEXT);
  return;
}

/**
* turns function to a string, turns function into abstract syntax tree, create rules for where to inject code, inject the monitoring code into user's function,
**/
function wrap(func) {
  const JSTEXT = func.toString();
  const parsed = parser(JSTEXT);
  const rules = ruler(parsed);
  const injected = inject(rules, JSTEXT);
  const mintified = run.wrap(injected, JSTEXT);
  return function() {
    const args = Array.prototype.slice.call(arguments);
    mintified.apply(null, args);
  };
}

minty.file = file;
minty.wrap = wrap;

file('/Users/AngieYeh/lumpy-turnips/lib/test.js')



module.exports = minty;<commit_msg>wrapping a file<commit_after>const parser = require('./lib/parser.js').parser;
const ruler = require('./lib/createLineRules.js');
const inject = require('./lib/injector.js');
const run = require('./lib/run.js');
const anonFunc = require('./lib/anonFuncHandler.js')
const fs = require('fs');

const minty = {};

/**
* reads the file the user provides, creates an abstract syntax tree, creates rules, injects monitoring code based on rules, generates html file for user
* @param {file path to file user wants us to analyze} path
**/
function file(path) {
  const JSTEXT = fs.readFileSync(path).toString();
  const parsed = parser(JSTEXT);
  const rules = ruler(parsed);
  const injected = inject(rules, JSTEXT);
  run.runFile(injected, path, JSTEXT);
  return;
}

/**
* turns function to a string, turns function into abstract syntax tree, create rules for where to inject code, inject the monitoring code into user's function,
**/
function wrap(func) {
  const JSTEXT = func.toString();
  const checkFuncText = anonFunc(JSTEXT);
  const parsed = parser(checkFuncText);
  const rules = ruler(parsed);
  const injected = inject(rules, JSTEXT);
  const mintified = run.wrap(injected, JSTEXT);
  return function() {
    const args = Array.prototype.slice.call(arguments);
    mintified.apply(null, args);
  };
}

minty.file = file;
minty.wrap = wrap;

// file('/Users/AngieYeh/lumpy-turnips/lib/test.js')

module.exports = minty;
{'fraction_non_alphanumeric': 0.13525337222019687, 'fraction_numerical': 0.0, 'mean_word_length': 4.444444444444445, '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': '689522', 'n_tokens_mistral': 848, 'n_tokens_neox': 839, 'n_words': 265}