<commit_before>//
// Copyright (c) 2014 <NAME> <<EMAIL>>
// Distributed under MIT license
//

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['underscore'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(require('underscore'), require('backbone'));
  } else {
    factory(root._, root.Backbone);
  }
}(this, function (_, Backbone) {
  'use strict';

  function Validator(validation) {
    if (_.isEmpty(validation)) {
      throw new Error('validation must be an empty object');
    }
    return function (attributes, options) {
      var errors = {};
      for (var attr in validation) {
        var validators = validation[attr];
        for (var i = 0; i < validators.length; i++) {
          var validator = validators[i];
          var err = validator(attributes[attr], attr, this);
          if (err) {
            errors[attr] = err;
            break;
          }
        }
        if (_.has(errors, attr)) {
          this.trigger('invalid:' + attr, this, err);
        } else {
          this.trigger('valid:' + attr, this);
        }
      }
      if (_.isEmpty(errors)) {
        return;
      }
      return errors;
    };
  }

  Validator.valid = function(options) {
    return function(val, attr) {};
  };

  Validator.invalid = function(options) {
    options = _.defaults({}, options, {
      error: 'invalid'
    });
    return function(val, attr) { return options.error; };
  };

  Validator.required = function(options) {
    options = _.defaults({}, options, {
      error: 'required'
    });
    return function(val, attr) {
      if (_.isUndefined(val) || _.isNull(val) || _.isNaN(val)) {
        return options.error;
      }
      if (_.isObject(val) && _.isEmpty(val)) {
        return options.error;
      }
      if (_.isString(val) && _.isEmpty(val)) {
        return options.error;
      }
      return;
    };
  };

  Validator.json = function (options) {
    options = _.defaults({}, options, {
      error: 'invalid json'
    });
    return function (val, attr) {
      if (!_.isString(val)) {
        return options.error;
      }
      try {
        JSON.parse(val);
        return;
      } catch (err) {
        return options.error;
      }
    };
  };

  Backbone.Model.Validator = Validator;
  return Validator;
}));
<commit_msg>Fix a missing dependency<commit_after>//
// Copyright (c) 2014 <NAME> <<EMAIL>>
// Distributed under MIT license
//

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['underscore', 'backbone'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(require('underscore'), require('backbone'));
  } else {
    factory(root._, root.Backbone);
  }
}(this, function (_, Backbone) {
  'use strict';

  function Validator(validation) {
    if (_.isEmpty(validation)) {
      throw new Error('validation must be an empty object');
    }
    return function (attributes, options) {
      var errors = {};
      for (var attr in validation) {
        var validators = validation[attr];
        for (var i = 0; i < validators.length; i++) {
          var validator = validators[i];
          var err = validator(attributes[attr], attr, this);
          if (err) {
            errors[attr] = err;
            break;
          }
        }
        if (_.has(errors, attr)) {
          this.trigger('invalid:' + attr, this, err);
        } else {
          this.trigger('valid:' + attr, this);
        }
      }
      if (_.isEmpty(errors)) {
        return;
      }
      return errors;
    };
  }

  Validator.valid = function(options) {
    return function(val, attr) {};
  };

  Validator.invalid = function(options) {
    options = _.defaults({}, options, {
      error: 'invalid'
    });
    return function(val, attr) { return options.error; };
  };

  Validator.required = function(options) {
    options = _.defaults({}, options, {
      error: 'required'
    });
    return function(val, attr) {
      if (_.isUndefined(val) || _.isNull(val) || _.isNaN(val)) {
        return options.error;
      }
      if (_.isObject(val) && _.isEmpty(val)) {
        return options.error;
      }
      if (_.isString(val) && _.isEmpty(val)) {
        return options.error;
      }
      return;
    };
  };

  Validator.json = function (options) {
    options = _.defaults({}, options, {
      error: 'invalid json'
    });
    return function (val, attr) {
      if (!_.isString(val)) {
        return options.error;
      }
      try {
        JSON.parse(val);
        return;
      } catch (err) {
        return options.error;
      }
    };
  };

  Backbone.Model.Validator = Validator;
  return Validator;
}));

{'fraction_non_alphanumeric': 0.1553295189658826, 'fraction_numerical': 0.0021190930281839372, 'mean_word_length': 2.1487658438959305, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5972602', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1405, 'n_words': 344}