<commit_before>//     Checkit.js 0.6.0
//     http://tgriesser.com/checkit
//     (c) 2013-2015 <NAME>
//     Checkit may be freely distributed under the MIT license.
module.exports = function(_, Promise) {

var inherits = require('inherits')

// The top level `Checkit` constructor, accepting the
// `validations` to be run and any additional `options`.
function Checkit(validations, options) {
  if (!(this instanceof Checkit)) {
    return new Checkit(validations, options);
  }
  this.conditional    = [];
  options             = _.clone(options || {});
  this.labels         = options.labels   || {};
  this.messages       = options.messages || {};
  this.language       = Checkit.i18n[options.language || Checkit.language] || {};
  this.labelTransform = options.labelTransform || Checkit.labelTransform
  this.validations    = prepValidations(validations || {});
}

Checkit.VERSION = '0.6.0';

// Possibly run a validations on this object, depending on the
// result of the `conditional` handler.
Checkit.prototype.maybe = function(validations, conditional) {
  this.conditional.push([prepValidations(validations), conditional]);
  return this;
}

// Asynchronously runs a validation block, returning a promise
// which resolves with the validated object items, or is rejected
// with a `Checkit.Error`
Checkit.prototype.run =
Checkit.prototype.validate = function(target, context) {
  return new Runner(this, target, context).run();
}

// Synchronously runs a validation block, returning an object of all fields
// validated, or throwing a `Checkit.Error` object.
Checkit.prototype.runSync =
Checkit.prototype.validateSync = function(target, context) {
  try  {
    return [null, new SyncRunner(this, target, context).run()]
  } catch (err) {
    return [err, null]
  }
}

Checkit.prototype.getMessage = function(item, key) {
  var language = this.language;
  var label    = item.label   || this.labels[key] || language.labels[key] || this.labelTransform(key);
  var message  = item.message || this.messages[item.rule] || language.messages[item.rule] || language.messages.fallback;
  message = message.replace(labelRegex, label);
  for (var i = 0, l = item.params.length; i < l; i++) {
    message = message.replace(varRegex(i+1), item.params[i]);
  }
  return message;
}

// Used to transform the label before using it, can be
// set globally or in the `options` for the Checkit object.
Checkit.labelTransform = function(label) {
  return label;
}

// Object containing languages for the validations... Feel free to
// add anything to this object.
Checkit.i18n = {
  en: require('./lang/en'),
  es: require('./lang/es'),
  ru: require('./lang/ru'),
  fr: require('./lang/fr')
}

// The default language for all validations, defaults to "en" which
// is included with the library by default. To add additional languages,
// add them to the `Checkit.i18n` object.
Checkit.language = 'en';

// Runs validation on an individual rule & value, for convenience.
// e.g. `Checkit.check('email', 'foo@domain', 'email').then(...`
Checkit.check = function(key, value, rules, sync) {
  var input = {}, validations = {};
  input[key] = value;
  validations[key] = rules;<commit_msg>Fixed bug. If custom function specified by object doesnt include parameters it returns length error<commit_after>//     Checkit.js 0.6.0
//     http://tgriesser.com/checkit
//     (c) 2013-2015 <NAME>
//     Checkit may be freely distributed under the MIT license.
module.exports = function(_, Promise) {

var inherits = require('inherits')

// The top level `Checkit` constructor, accepting the
// `validations` to be run and any additional `options`.
function Checkit(validations, options) {
  if (!(this instanceof Checkit)) {
    return new Checkit(validations, options);
  }
  this.conditional    = [];
  options             = _.clone(options || {});
  this.labels         = options.labels   || {};
  this.messages       = options.messages || {};
  this.language       = Checkit.i18n[options.language || Checkit.language] || {};
  this.labelTransform = options.labelTransform || Checkit.labelTransform
  this.validations    = prepValidations(validations || {});
}

Checkit.VERSION = '0.6.0';

// Possibly run a validations on this object, depending on the
// result of the `conditional` handler.
Checkit.prototype.maybe = function(validations, conditional) {
  this.conditional.push([prepValidations(validations), conditional]);
  return this;
}

// Asynchronously runs a validation block, returning a promise
// which resolves with the validated object items, or is rejected
// with a `Checkit.Error`
Checkit.prototype.run =
Checkit.prototype.validate = function(target, context) {
  return new Runner(this, target, context).run();
}

// Synchronously runs a validation block, returning an object of all fields
// validated, or throwing a `Checkit.Error` object.
Checkit.prototype.runSync =
Checkit.prototype.validateSync = function(target, context) {
  try  {
    return [null, new SyncRunner(this, target, context).run()]
  } catch (err) {
    return [err, null]
  }
}

Checkit.prototype.getMessage = function(item, key) {
  var language = this.language;
  var label    = item.label   || this.labels[key] || language.labels[key] || this.labelTransform(key);
  var message  = item.message || this.messages[item.rule] || language.messages[item.rule] || language.messages.fallback;
  message = message.replace(labelRegex, label);
  if (item.params) {
    for (var i = 0, l = item.params.length; i < l; i++) {
      message = message.replace(varRegex(i+1), item.params[i]);
    }
  }
  return message;
}

// Used to transform the label before using it, can be
// set globally or in the `options` for the Checkit object.
Checkit.labelTransform = function(label) {
  return label;
}

// Object containing languages for the validations... Feel free to
// add anything to this object.
Checkit.i18n = {
  en: require('./lang/en'),
  es: require('./lang/es'),
  ru: require('./lang/ru'),
  fr: require('./lang/fr')
}

// The default language for all validations, defaults to "en" which
// is included with the library by default. To add additional languages,
// add them to the `Checkit.i18n` object.
Checkit.language = 'en';

// Runs validation on an individual rule & value, for convenience.
// e.g. `Checkit.check('email', '<EMAIL>', 'email').then(...`
Checkit.check = function(key, value, rules, sync) {
  var input = {}, validations = {};
  input[key] = value;
  validations[key] = rules;
{'fraction_non_alphanumeric': 0.1377551020408163, 'fraction_numerical': 0.006802721088435374, 'mean_word_length': 3.684286748732802, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '4363380', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1908, 'n_words': 587}