<commit_before>/**
 * @module
 */
import _ from 'lodash';
import Random from 'random-js';
import assert from 'assert';
import {stdOpts} from './constants';

/**
 * A function to generate a function to take a random engine in random-js.
 * to generate a random value.
 *
 * @callback GeneratorMaker
 * @param {Engine} engine - engines provided in random-js.
 *                          The default is mt19937 with auto seeds.
 * @return {*}
 */

/**
 * Arguments of a GeneratorMaker.
 * @typedef {Array} GeneratorMakerOptions
 */

/**
 * Arbitrary Options.
 * @typedef {Object} ArbitraryOptions
 * @property {!GeneratorMaker} gen the generator maker.
 * @property {?GeneratorMakerOptions} genOts the options of the generator maker.
 * @property {?string} name the name of a arbitrary.
 * @property {?string} locale the locale tag. default is en.
 * @property {?Engine} engine the random engine.
 * @property {?number} seed the seed number.
 */

/**
 * A function to generate a random value.
 * @callback Generator
 * @param {Engine} engine
 * @param {string} locale
 * @return {*}
 */

/**
 * Random generation and shrinking of values.
 */
class Arbitrary {
  /**
   * Create an arbitrary.
   *
   * @param {!ArbitraryOptions} opts the options of arbitrary creation.
   * @return {Arbitrary}
   */
  constructor(opts) {
    assert(_.isObject(opts), 'opts must be an object.');
    // private attributes initialization.
    this._gen = null;
    this._genOpts = null;
    this._name = null;
    this._locale = null;
    this._engine = null;
    this._seed = null;
    this._transforms = [_.identity];

    this.locale(opts.locale || 'en');
    this.engine(opts.engine || stdOpts.engine);
    this.name(opts.name || 'Arbitrary-' + Random.uuid4(this._engine));
    this.gen(opts.gen);
    this.genOpts(opts.genOpts || []);
  }
  /**
   * Get/Set the name of this arbitrary.
   *
   * @param {string} name arbitrary name.
   * @return {Arbitrary|string}
   */
  name(name) {
    if (name !== undefined) {
      assert(_.isString(name) && name.length >= 3,
             'name must be a sring of length >= 3.');
      this._name = name;
      return this;
    }
    else {
      return this._name;
    }
  }
  /**
   * Get/Set locale.
   *
   * @param {!string} locale locale tag.
   * @return {Arbitrary|string}
   */
  locale(locale) {
    if (locale !== undefined) {
      this._locale = locale;
      return this;
    }
    else {
      return this._locale;
    }
  }
  /**
   * Get/Set a random engine.
   *
   * @param {!Engine} engine
   * @return {Arbitrary|Engine}
   */
  engine(engine) {
    if (engine !== undefined) {
      assert(engine, 'engine is required.');
      this._engine = engine;
      return this;
    }
    else {
      return this._engine;
    }
  }
  /**
   * Get/Set a seed number.
   *
   * @param {!number} seed 32-bit integer.
   * @return {Arbitrary|number}
   */
  seed(seed) {
    if (seed !== undefined) {
      assert(_.isInteger(seed), 'seed must be a 32-bit integer.');
      this._seed = seed;
      this._engine.seed(seed);
      return this;
    }
    else {
      return this._seed;
    }
  }
  /**
   * Get/Set a generator maker.
   *
   * @param {!GeneratorMaker} gen
   * @return {Arbitrary|GeneratorMaker}
   */
  gen(gen) {
    if (gen !== undefined) {
      assert(_.isFunction(gen), 'gen must be a function.');
      this._gen = gen.bind(this);
      return this;
    }
    else {
      return this._gen;
    }
  }
  /**
   * Get/Set the options of a generator maker.
   *
   * @param {?GeneratorMakerOptions} opts
   * @return {Arbitrary|GeneratorMakerOptions}
   */
  genOpts(genOpts) {
    if (typeof genOpts != undefined) {
      assert(_.isArray(genOpts), 'opts must be an object.');
      this._genOpts = genOpts;
      return this;
    }
    else {
      return this._genOpts;
    }
  }
  /**
   * Clone this arbitrary.
   *
   * @return {Arbitrary}
   */
  clone() {
    return _.cloneDeep(this);
  }
  /**
   * Create a new arbitrary with new
   * inclusive range of its generator maker.
   *
   * @param {...*}
   * @return {Arbitrary}
   */
  choose(...args) {
    const clone = this.clone();
    clone._genOpts = args;<commit_msg>Fix typo<commit_after>/**
 * @module
 */
import _ from 'lodash';
import Random from 'random-js';
import assert from 'assert';
import {stdOpts} from './constants';

/**
 * A function to generate a function to take a random engine in random-js.
 * to generate a random value.
 *
 * @callback GeneratorMaker
 * @param {Engine} engine - engines provided in random-js.
 *                          The default is mt19937 with auto seeds.
 * @return {*}
 */

/**
 * Arguments of a GeneratorMaker.
 * @typedef {Array} GeneratorMakerOptions
 */

/**
 * Arbitrary Options.
 * @typedef {Object} ArbitraryOptions
 * @property {!GeneratorMaker} gen the generator maker.
 * @property {?GeneratorMakerOptions} genOts the options of the generator maker.
 * @property {?string} name the name of a arbitrary.
 * @property {?string} locale the locale tag. default is en.
 * @property {?Engine} engine the random engine.
 * @property {?number} seed the seed number.
 */

/**
 * A function to generate a random value.
 * @callback Generator
 * @param {Engine} engine
 * @param {string} locale
 * @return {*}
 */

/**
 * Random generation and shrinking of values.
 */
class Arbitrary {
  /**
   * Create an arbitrary.
   *
   * @param {!ArbitraryOptions} opts the options of arbitrary creation.
   * @return {Arbitrary}
   */
  constructor(opts) {
    assert(_.isObject(opts), 'opts must be an object.');
    // private attributes initialization.
    this._gen = null;
    this._genOpts = null;
    this._name = null;
    this._locale = null;
    this._engine = null;
    this._seed = null;
    this._transforms = [_.identity];

    this.locale(opts.locale || 'en');
    this.engine(opts.engine || stdOpts.engine);
    this.name(opts.name || 'Arbitrary-' + Random.uuid4(this._engine));
    this.gen(opts.gen);
    this.genOpts(opts.genOpts || []);
  }
  /**
   * Get/Set the name of this arbitrary.
   *
   * @param {string} name arbitrary name.
   * @return {Arbitrary|string}
   */
  name(name) {
    if (name !== undefined) {
      assert(_.isString(name) && name.length >= 3,
             'name must be a sring of length >= 3.');
      this._name = name;
      return this;
    }
    else {
      return this._name;
    }
  }
  /**
   * Get/Set locale.
   *
   * @param {!string} locale locale tag.
   * @return {Arbitrary|string}
   */
  locale(locale) {
    if (locale !== undefined) {
      this._locale = locale;
      return this;
    }
    else {
      return this._locale;
    }
  }
  /**
   * Get/Set a random engine.
   *
   * @param {!Engine} engine
   * @return {Arbitrary|Engine}
   */
  engine(engine) {
    if (engine !== undefined) {
      assert(engine, 'engine is required.');
      this._engine = engine;
      return this;
    }
    else {
      return this._engine;
    }
  }
  /**
   * Get/Set a seed number.
   *
   * @param {!number} seed 32-bit integer.
   * @return {Arbitrary|number}
   */
  seed(seed) {
    if (seed !== undefined) {
      assert(_.isInteger(seed), 'seed must be a 32-bit integer.');
      this._seed = seed;
      this._engine.seed(seed);
      return this;
    }
    else {
      return this._seed;
    }
  }
  /**
   * Get/Set a generator maker.
   *
   * @param {!GeneratorMaker} gen
   * @return {Arbitrary|GeneratorMaker}
   */
  gen(gen) {
    if (gen !== undefined) {
      assert(_.isFunction(gen), 'gen must be a function.');
      this._gen = gen.bind(this);
      return this;
    }
    else {
      return this._gen;
    }
  }
  /**
   * Get/Set the options of a generator maker.
   *
   * @param {?GeneratorMakerOptions} opts
   * @return {Arbitrary|GeneratorMakerOptions}
   */
  genOpts(genOpts) {
    if (genOpts !== undefined) {
      assert(_.isArray(genOpts), 'opts must be an object.');
      this._genOpts = genOpts;
      return this;
    }
    else {
      return this._genOpts;
    }
  }
  /**
   * Clone this arbitrary.
   *
   * @return {Arbitrary}
   */
  clone() {
    return _.cloneDeep(this);
  }
  /**
   * Create a new arbitrary with new
   * inclusive range of its generator maker.
   *
   * @param {...*}
   * @return {Arbitrary}
   */
  choose(...args) {
    const clone = this.clone();
    clone._genOpts = args;
{'fraction_non_alphanumeric': 0.14268628154526972, 'fraction_numerical': 0.0028704700394689632, 'mean_word_length': 2.370415155179363, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '758714', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2728, 'n_words': 743}