<commit_before>"use strict";

var _ = require('lodash');
var Rule = require('./base/rule');
var iterate = require('./../utils/iterate');

var RuleEach = module.exports = Rule.extend({
	check: function (value, verifier, done) {
		var that = this;

		if (!_.isArray(value)) {
			return false;
		}

		iterate.array(value, function (itemValue, index, done) {
			verifier.verify(itemValue, function (err) {
				if (err instanceof Rule.ValidationError) {
					done(that.convertNestedError(err, index));
					return;
				}

				done(err);
			});
		}, function (err) {
			done(err, !err);
		});
	},

	serialize: function () {
		return this.params.serialize();
	},

	/**
	 * proxy error helper
	 *
	 * @method
	 * @param {Rule.ValidationError} err
	 * @param {?Number} index
	 *
	 * return Rule.ValidationError
	 * */
	convertNestedError: function (err, index) {
		var obj = {};
		obj[err.rule] = err.params;

		return this.error(index == null ? err.index : index, obj);
	},

	prepareParams: function (params) {
		if (_.isEmpty(params)) {
			throw new Error('#REACH1: param validation must be specified');
		}

		return new Rule.Verifier(params);<commit_msg>rule each redesign<commit_after>"use strict";

var _ = require('lodash');
var Rule = require('./base/rule');
var iterate = require('./../utils/iterate');

var RuleEach = module.exports = Rule.extend({
	check: function (value, verifier, done) {
		var that = this;

		if (!_.isArray(value)) {
			return new Rule.ValidationError('type', 'array');
		}

		iterate.array(value, function (itemValue, index, done) {
			verifier.verify(itemValue, function (err) {
				if (err instanceof Rule.ValidationError) {
					err.index = index;
				}

				done(err);
			});
		}, function (err) {
			done(err, !err);
		});
	},

	prepareParams: function (params) {
		if (_.isEmpty(params)) {
			throw new Error('#REACH1: param validation must be specified');
		}

		return new Rule.Verifier(params);
{'fraction_non_alphanumeric': 0.16398546964193045, 'fraction_numerical': 0.0010378827192527244, 'mean_word_length': 3.5258215962441315, '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': '3552963', 'n_tokens_mistral': 711, 'n_tokens_neox': 610, 'n_words': 156}