<commit_before>'use strict';

import util from './util';
import values from 'lodash.values';
import last from 'lodash.last';
import difference from 'lodash.difference';
import pick from 'lodash.pick';
import union from 'lodash.union';
import createDebug from 'debug';
import createRule, {parseRules} from './rule';

const debug = createDebug('date-frequency');

function createFrequency (rules) {
  rules = rules || {};

  if (typeof rules === 'string') {
    debug('parse', rules);

    rules = parseRules(rules);
  }

  for (let unit in rules) {
    if (rules.hasOwnProperty(unit)) {
      let rule = rules[unit];
      let u = util.unit.filter(unit);

      rules[u] = createRule(u, rule);

      if (rules[u].fn && !createFrequency.fn[rules[u].fn]) {
        throw Error(`Filter function "${rules[u].fn}" not available`);
      }
    }
  }

  debug('rules', rules);

  function on (unit, options, scope) {
    unit = util.unit.filter(unit);

    if (typeof unit === 'undefined') {
      throw Error(`Invalid unit: ${unit}`);
    }

    if (typeof options !== 'object') {
      options = {fix: options};

      if (scope) {
        options.scope = scope;
      }
    }

    return createFrequency(Object.assign(
      {},
      rules,
      {[unit]: createRule(unit, options)}
    ));
  };

  /**
   * Retrieve value for unit (within default or specified scope)
   * @param {String} unit Date unit
   * @param {String} scope Date unit scope
   * @return {Number} Fix value
   */
  function getValue (unit, scope) {
    unit = util.unit.filter(unit);
    scope = util.scope.filter(unit, util.unit.filter(scope));

    if (!rules[unit] || rules[unit].scope !== scope) {
      return undefined;
    }

    let rule = rules[unit];

    if ('fix' in rule) {
      return rule.fix;
    } else if ('fn' in rule) {
      return rule.fn;
    }
  };

  function next (date) {
    date = util.date.clone(util.date.convert(date));<commit_msg>set default reference date<commit_after>'use strict';

import util from './util';
import values from 'lodash.values';
import last from 'lodash.last';
import difference from 'lodash.difference';
import pick from 'lodash.pick';
import union from 'lodash.union';
import createDebug from 'debug';
import createRule, {parseRules} from './rule';

const debug = createDebug('date-frequency');

function createFrequency (rules) {
  rules = rules || {};

  if (typeof rules === 'string') {
    debug('parse', rules);

    rules = parseRules(rules);
  }

  for (let unit in rules) {
    if (rules.hasOwnProperty(unit)) {
      let rule = rules[unit];
      let u = util.unit.filter(unit);

      rules[u] = createRule(u, rule);

      if (rules[u].fn && !createFrequency.fn[rules[u].fn]) {
        throw Error(`Filter function "${rules[u].fn}" not available`);
      }
    }
  }

  debug('rules', rules);

  function on (unit, options, scope) {
    unit = util.unit.filter(unit);

    if (typeof unit === 'undefined') {
      throw Error(`Invalid unit: ${unit}`);
    }

    if (typeof options !== 'object') {
      options = {fix: options};

      if (scope) {
        options.scope = scope;
      }
    }

    return createFrequency(Object.assign(
      {},
      rules,
      {[unit]: createRule(unit, options)}
    ));
  };

  /**
   * Retrieve value for unit (within default or specified scope)
   * @param {String} unit Date unit
   * @param {String} scope Date unit scope
   * @return {Number} Fix value
   */
  function getValue (unit, scope) {
    unit = util.unit.filter(unit);
    scope = util.scope.filter(unit, util.unit.filter(scope));

    if (!rules[unit] || rules[unit].scope !== scope) {
      return undefined;
    }

    let rule = rules[unit];

    if ('fix' in rule) {
      return rule.fix;
    } else if ('fn' in rule) {
      return rule.fn;
    }
  };

  function next (date) {
    if (date) {
      date = util.date.clone(util.date.convert(date));
    } else {
      date = new Date();
    }

{'fraction_non_alphanumeric': 0.15575849822425164, 'fraction_numerical': 0.0, 'mean_word_length': 2.7768199233716473, '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': '1408009', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1212, 'n_words': 348}