<commit_before>/**
 * _base.js
 *
 * The common, base functionality of an input generator.
 *
 * Copyright (c) 2013 - 2017 <NAME>, LocalNerve, contributors
 * Licensed under the MIT license.
 */
"use strict";

var events = require("events");
var path = require("path");
var urlm = require("url");
var _ = require("lodash");
var common = require("../common");

var emitter = new events.EventEmitter();

// Defaults for this module
var defaults = {
  protocol: "http",
  hostname: "localhost",
  port: undefined,
  auth: undefined,
  outputPath: undefined,
  outputDir: "./snapshots",
  selector: "body",
  timeout: 10000,
  checkInterval: 250,
  useJQuery: false,
  phantomjsOptions: ""
};

/**
 * Normalize the given object to a function.
 *
 * If the input is a function, return it as is.
 * If the input is undefined, then a passthru function is generated.
 * If the input is NOT an Object, then a function returns that value.
 * If the input is an Object, then a function receives a key and
 *   returns the property value if it exists, otherwise return the __default value.
 *   If a passthru is requested, the key is returned when no __default is found.
 *
 * @param {Any} obj - Some input to be represented by a function.
 * @returns {Function} A function to represent the given input.
 */
function normalize (obj) {
  var result = obj;
  if (typeof obj !== "function") {
    if (typeof obj !== "undefined") {
      if (Object.prototype.toString.call(obj) !== "[object Object]") {
        result = (function (value) { return function () { return value; }; }(obj));
      } else {
        result = (function (o) { return function (key, passthru) {
          if (o[key] === void 0) {
            return o.__default || (passthru ? key : undefined);
          } else {
            return o[key];
          }
        }; }(obj));
      }
    } else {
      result = function (passthru) { return passthru; };
    }
  }
  return result;
}

/**
 * If a normalized option was overriden, but a default still undefined, supply one.
 * The result could still be undefined, but only if the default is undefined.
 *
 * If calling the normalized option with no args is undefined, supply missing default.
 */
function supplyMissingDefault (options, name) {
  if (options[name]() === void 0) {
    options[name] = _.wrap(options[name], function(func, key) {
      var res = func(key);
      return res === void 0 ? defaults[name] : res;
    });
  }
}

/**
 * Prepare options for use by an input generator.
 *
 * @param {Object} [options] - Options with or without defaults.
 */
function prepOptions (options) {
  // ensure defaults are represented
  common.ensure(options, defaults);

  // normalize certain arguments if they are not functions.
  //   outputPath is a special case
  var perPageOptions = [
    "selector", "timeout", "useJQuery", "phantomjsOptions"<commit_msg>update comments<commit_after>/**
 * _base.js
 *
 * The common, base functionality of an input generator.
 *
 * Copyright (c) 2013 - 2017 <NAME>, LocalNerve, contributors
 * Licensed under the MIT license.
 */
"use strict";

var events = require("events");
var path = require("path");
var urlm = require("url");
var _ = require("lodash");
var common = require("../common");

var emitter = new events.EventEmitter();

// Defaults for this module
var defaults = {
  protocol: "http",
  hostname: "localhost",
  port: undefined,
  auth: undefined,
  outputPath: undefined,
  outputDir: "./snapshots",
  selector: "body",
  timeout: 10000,
  checkInterval: 250,
  useJQuery: false,
  phantomjsOptions: ""
};

/**
 * Normalize the given object to a function.
 *
 * If the input is a function, return it as is.
 * If the input is undefined, then a passthru function is generated.
 * If the input is NOT an Object, then a function returns that value.
 * If the input is an Object, then a function receives a key and
 *   returns the property value if it exists, otherwise return the __default value.
 *   If a passthru is requested, the key is returned when no __default is found.
 *
 * @param {Any} obj - Some input to be represented by a function.
 * @returns {Function} A function to represent the given input.
 */
function normalize (obj) {
  var result = obj;
  if (typeof obj !== "function") {
    if (typeof obj !== "undefined") {
      if (Object.prototype.toString.call(obj) !== "[object Object]") {
        result = (function (value) { return function () { return value; }; }(obj));
      } else {
        result = (function (o) { return function (key, passthru) {
          if (o[key] === void 0) {
            return o.__default || (passthru ? key : undefined);
          } else {
            return o[key];
          }
        }; }(obj));
      }
    } else {
      result = function (passthru) { return passthru; };
    }
  }
  return result;
}

/**
 * If a normalized option was overriden, but a default still undefined, supply one.
 * The result could still be undefined, but only if the default is undefined.
 *
 * If calling the normalized option with no args is undefined, supply missing default.
 *
 * @param {Object} options - Input generator options.
 * @param {String} name - The name of the property to supply missing default for.
 */
function supplyMissingDefault (options, name) {
  if (options[name]() === void 0) {
    options[name] = _.wrap(options[name], function(func, key) {
      var res = func(key);
      return res === void 0 ? defaults[name] : res;
    });
  }
}

/**
 * Prepare options for use by an input generator.
 *
 * @param {Object} [options] - Options with or without defaults.
 */
function prepOptions (options) {
  // ensure defaults are represented
  common.ensure(options, defaults);

  // normalize certain arguments if they are not functions.
  //   outputPath is a special case
  var perPageOptions = [
    "selector", "timeout", "useJQuery", "phantomjsOptions"
{'fraction_non_alphanumeric': 0.12182654626001023, 'fraction_numerical': 0.006474697563469075, 'mean_word_length': 3.1077676696990904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1051573', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1664, 'n_words': 675}