<commit_before>var Schema = require('../BaseSchema'),
  EqualitySchema = require('../patterns/equality'),
  anything = require('../patterns/anything').instance

var ArraySchema = module.exports = Schema.extensions.ArraySchema = Schema.extend({
  initialize: function(itemSchema, max, min) {
    this.itemSchema = itemSchema || anything
    this.min = min || 0
    this.max = max || Infinity;
  },
  errors: function(instance) {
    var self = this;
    // Instance must be an instance of Array
    if (!(instance instanceof Array))
      return self.err(instance + ' is not an instance of Array', instance);

    // Checking length
    if (this.min === this.max) {
      if (instance.length !== this.min) return self.err('Array length should be equal to ' + this.min + ' and is ' + instance.length, instance)

    } else {
      if (this.min > 0 && instance.length < this.min) return self.err('Array length should be less than ' + this.min + ' and is ' + instance.length, instance);
      if (this.max < Infinity && instance.length > this.max) return self.err('Array length should be more than ' + this.max + ' and is ' + instance.length, instance);
    }

    // Checking conformance to the given item schema
    var results = {};
    for (var i = 0; i < instance.length; i++) {
      var errs = this.itemSchema.errors(instance[i])
      if (errs) {
        results[i] = errs
      }
    }
    var resultKeysArray = Object.keys(results)
    if (resultKeysArray.length > 0) {
      return self.err(resultKeysArray.length + ' of ' + instance.length + ' were invalid', instance, results);
    }

    return false
  },
  validate: function(instance) {
    // Instance must be an instance of Array
    if (!(instance instanceof Array)) return false

    // Checking length
    if (this.min === this.max) {
      if (instance.length !== this.min) return false

    } else {
      if (this.min > 0 && instance.length < this.min) return false<commit_msg>Feature Errors : ArraySchema should pass structure of errors to parent Schema<commit_after>var Schema = require('../BaseSchema')
  , EqualitySchema = require('../patterns/equality')
  , anything = require('../patterns/anything').instance;

var ArraySchema = module.exports = Schema.extensions.ArraySchema = Schema.extend({
  initialize: function(itemSchema, max, min) {
    this.itemSchema = itemSchema || anything
    this.min = min || 0
    this.max = max || Infinity;
  },
  errors: function(instance) {
    var self = this;
    // Instance must be an instance of Array
    if (!(instance instanceof Array))
      return self.err(instance + ' is not an instance of Array', instance);

    // Checking length
    if (this.min === this.max) {
      if (instance.length !== this.min) return self.err('Array length should be equal to ' + this.min + ' and is ' + instance.length, instance)

    } else {
      if (this.min > 0 && instance.length < this.min) return self.err('Array length should be less than ' + this.min + ' and is ' + instance.length, instance);
      if (this.max < Infinity && instance.length > this.max) return self.err('Array length should be more than ' + this.max + ' and is ' + instance.length, instance);
    }

    // Checking conformance to the given item schema
    var results = {};
    for (var i = 0; i < instance.length; i++) {
      var errs = this.itemSchema.errors(instance[i])
      if (errs) {
        results[i] = errs
      }
    }
    var resultKeysArray = Object.keys(results)
    if (resultKeysArray.length > 0) {
      return results;
    }

    return false
  },
  validate: function(instance) {
    // Instance must be an instance of Array
    if (!(instance instanceof Array)) return false

    // Checking length
    if (this.min === this.max) {
      if (instance.length !== this.min) return false

    } else {
      if (this.min > 0 && instance.length < this.min) return false
{'fraction_non_alphanumeric': 0.13068181818181818, 'fraction_numerical': 0.0025826446280991736, 'mean_word_length': 2.846077457795432, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1967345', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1106, 'n_words': 357}