<commit_before>'use strict';

var Fs = require('fs');
var Joi = require('joi');
var NPMUtils = require('requiresafe-npm-utils');
var ProxyAgent = require('https-proxy-agent');
var Semver = require('semver');
var Wreck = require('wreck');

var Conf = require('rc')('requiresafe', { api: { baseUrl: 'https://api.requiresafe.com', json: true } }, []);

var internals = {};
internals.findLines = function (shrinkwrap, module, version) {

  var modRE = new RegExp('\\s*\"' + module + '\":\\s*\\{\\s*([^\\}]*)\\}', 'gm');
  var versionRE = new RegExp('\\s*\"version\":\\s*\"' + version + '\"', 'gm');
  var found = false;
  while (!found) {
    var match = modRE.exec(shrinkwrap);
    if (versionRE.test(match[0])) {
      found = true;
    }

  }

  var start = shrinkwrap.slice(0, match.index).split('\n').length + 1;
  var end = shrinkwrap.slice(0, match.index + match[0].length).split('\n').length;
  return {
    start: start,
    end: end
  };
};

internals.exceptionRegex = /^https\:\/\/requiresafe\.com\/advisories\/([0-9]+)$/;

internals.optionSchema = Joi.object({
  package: Joi.alternatives().try(Joi.string(), Joi.object()),
  shrinkwrap: Joi.alternatives().try(Joi.string(), Joi.object()),
  exceptions: Joi.array().items(Joi.string().regex(internals.exceptionRegex)).default([]),
  advisoriesPath: Joi.string(),
  proxy: Joi.string()
}).or(['package', 'shrinkwrap']);

/*
options should be an object that contains one or more of the keys package, shrinkwrap, offline
  {
    package: '/path/to/package.json',
    shrinkwrap: '/path/to/npm-shrinkwrap.json',
    offline: false
  }
*/
module.exports = function (options, callback) {

  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  options.proxy = options.proxy || Conf.proxy;
  if (options.proxy) {
    Conf.api.agent = new ProxyAgent(options.proxy);
  }

  // Set defaults
  var wreck = Wreck.defaults(Conf.api);

  var shrinkwrap;<commit_msg>drop proxy from post<commit_after>'use strict';

var Fs = require('fs');
var Joi = require('joi');
var NPMUtils = require('requiresafe-npm-utils');
var ProxyAgent = require('https-proxy-agent');
var Semver = require('semver');
var Wreck = require('wreck');

var Conf = require('rc')('requiresafe', { api: { baseUrl: 'https://api.requiresafe.com', json: true } }, []);

var internals = {};
internals.findLines = function (shrinkwrap, module, version) {

  var modRE = new RegExp('\\s*\"' + module + '\":\\s*\\{\\s*([^\\}]*)\\}', 'gm');
  var versionRE = new RegExp('\\s*\"version\":\\s*\"' + version + '\"', 'gm');
  var found = false;
  while (!found) {
    var match = modRE.exec(shrinkwrap);
    if (versionRE.test(match[0])) {
      found = true;
    }

  }

  var start = shrinkwrap.slice(0, match.index).split('\n').length + 1;
  var end = shrinkwrap.slice(0, match.index + match[0].length).split('\n').length;
  return {
    start: start,
    end: end
  };
};

internals.exceptionRegex = /^https\:\/\/requiresafe\.com\/advisories\/([0-9]+)$/;

internals.optionSchema = Joi.object({
  package: Joi.alternatives().try(Joi.string(), Joi.object()),
  shrinkwrap: Joi.alternatives().try(Joi.string(), Joi.object()),
  exceptions: Joi.array().items(Joi.string().regex(internals.exceptionRegex)).default([]),
  advisoriesPath: Joi.string(),
  proxy: Joi.string()
}).or(['package', 'shrinkwrap']);

/*
options should be an object that contains one or more of the keys package, shrinkwrap, offline
  {
    package: '/path/to/package.json',
    shrinkwrap: '/path/to/npm-shrinkwrap.json',
    offline: false
  }
*/
module.exports = function (options, callback) {

  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  options.proxy = options.proxy || Conf.proxy;
  if (options.proxy) {
    Conf.api.agent = new ProxyAgent(options.proxy);
    delete options.proxy;
  }

  // Set defaults
  var wreck = Wreck.defaults(Conf.api);

  var shrinkwrap;
{'fraction_non_alphanumeric': 0.20321674751085014, 'fraction_numerical': 0.0035741639009446006, 'mean_word_length': 3.7148014440433212, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2790743', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1339, 'n_words': 286}