<commit_before>// Backbone.Validation v0.1.2
//
// Copyright (C)2011 <NAME>
// Distributed under MIT License
//
// Documentation and full license availabe at:
// http://github.com/thedersen/backbone.validation
// ----------------------------
// Backbone.Validation
// ----------------------------
Backbone.Validation = (function(Backbone, _) {
	var getValidators = function(model, attr) {
		var validation = model.validation[attr],
		    validators = [];

		if (_.isFunction(validation)) {
			return validation;
		} else {
			for (attr in validation) {
				if (attr !== 'msg' && validation.hasOwnProperty(attr)) {
					validators.push({
						fn: Backbone.Validation.validators[attr],
						val: validation[attr],
						msg: validation['msg']
					});
				}
			}
			return validators;
		}
	};

	var validateAttr = function(model, attr, value) {
		var validators = getValidators(model, attr),
		    error = '',
		    validator,
		    result;

		if (_.isFunction(validators)) {
			return validators(value);
		} else {
			for (var i = 0; i < validators.length; i++) {
				validator = validators[i];
				result = validator.fn(value, attr, validator.msg, validator.val);
				if (result) {
					error += result;
				}
			};
			return error;
		}
	};

	return {
		version: '0.1.2',

		bind: function(view, options) {
			options = options || {};
			var model = view.model,
			    validFn = options.valid || Backbone.Validation.callbacks.valid,
				invalidFn = options.invalid || Backbone.Validation.callbacks.invalid;

			model.validate = function(attrs) {
				var invalidAttr = false,
				    isValid = true,
				    error;

				for (changedAttr in attrs) {
					if (changedAttr === 'isValid') {
						return false;
					}

					error = validateAttr(model, changedAttr, attrs[changedAttr]);
					if (error) {
						invalidAttr = true;
						invalidFn(view, changedAttr, error);
					} else {
						validFn(view, changedAttr);
					}
				}

				if (invalidAttr) {
					model.set({
						isValid: false
					});
				} else {
					for (attr in model.validation) {
						if (_.isUndefined(attrs[attr]) && validateAttr(model, attr, model.get(attr))) {
							isValid = false;
							break;
						}
					}
					model.set({
						isValid: isValid
					});
				}

				return invalidAttr;
			};
		},

		unbind: function(view) {
			view.model.validate = undefined;
		}
	};
} (Backbone, _));

Backbone.Validation.callbacks = {
	valid: function(view, attr) {
		view.$('#' + attr).removeClass('invalid');
		view.$('#' + attr).removeAttr('data-error');
	},

	invalid: function(view, attr, error) {
		view.$('#' + attr).addClass('invalid');
		view.$('#' + attr).attr('data-error', error);
	}
};

Backbone.Validation.patterns = {
	number: /^\d$/,
	email: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
	url: /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
};

Backbone.Validation.validators = (function(_, $) {
	return {
		required: function(value, attr, msg) {
			var isEmptyString = _.isString(value) && $.trim(value) === '';
			var isFalseBoolean = _.isBoolean(value) && value === false;

			if (_.isNull(value) || _.isUndefined(value) || isEmptyString || isFalseBoolean) {
				return msg || attr + ' is required';
			}
		},
		min: function(value, attr, msg, minValue) {
			value = parseInt(value, 10);
			if (!_.isNumber(value) || value < minValue) {
				return msg || attr + ' must be larger than or equal to ' + minValue;
			}
		},
		max: function(value, attr, msg, maxValue) {
			value = parseInt(value, 10);
			if (!_.isNumber(value) || value > maxValue) {
				return msg || attr + ' must be less than or equal to ' + maxValue;
			}
		},
		minLength: function(value, attr, msg, minLength) {
			value = $.trim(value);
			if (_.isString(value) && value.length < minLength) {
				return msg || attr + ' must be longer than or equal to ' + minLength + ' characters';
			}
		},
		maxLength: function(value, attr, msg, maxLength) {
			value = $.trim(value);
			if (_.isString(value) && value.length > maxLength) {
				return msg || attr + ' must be shorter than or equal to' + maxLength + ' characters';
			}
		},
		pattern: function(value, attr, msg, pattern) {
			pattern = Backbone.Validation.patterns[pattern] || pattern;
			if (_.isString(value) && !value.match(pattern)) {
				return msg || attr + ' is not a valid ' + pattern;
			}
		}
	};
} (_, jQuery));<commit_msg>Code formatting<commit_after>// Backbone.Validation v0.1.2
//
// Copyright (C)2011 <NAME>
// Distributed under MIT License
//
// Documentation and full license availabe at:
// http://github.com/thedersen/backbone.validation
// ----------------------------
// Backbone.Validation
// ----------------------------
Backbone.Validation = (function(Backbone, _) {
    var getValidators = function(model, attr) {
        var validation = model.validation[attr],
            validators = [];

        if (_.isFunction(validation)) {
            return validation;
        } else {
            for (attr in validation) {
                if (attr !== 'msg' && validation.hasOwnProperty(attr)) {
                    validators.push({
                        fn: Backbone.Validation.validators[attr],
                        val: validation[attr],
                        msg: validation['msg']
                    });
                }
            }
            return validators;
        }
    };

    var validateAttr = function(model, attr, value) {
        var validators = getValidators(model, attr),
            error = '',
            validator, result;

        if (_.isFunction(validators)) {
            return validators(value);
        } else {
            for (var i = 0; i < validators.length; i++) {
                validator = validators[i];
                result = validator.fn(value, attr, validator.msg, validator.val);
                if (result) {
                    error += result;
                }
            };
            return error;
        }
    };

    return {
        version: '0.1.2',

        bind: function(view, options) {
            options = options || {};
            var model = view.model,
                validFn = options.valid || Backbone.Validation.callbacks.valid,
                invalidFn = options.invalid || Backbone.Validation.callbacks.invalid;

            model.validate = function(attrs) {
                var invalidAttr = false,
                    isValid = true,
                    error;

                for (changedAttr in attrs) {
                    if (changedAttr === 'isValid') {
                        return false;
                    }

                    error = validateAttr(model, changedAttr, attrs[changedAttr]);
                    if (error) {
                        invalidAttr = true;
                        invalidFn(view, changedAttr, error);
                    } else {
                        validFn(view, changedAttr);
                    }
                }

                if (invalidAttr) {
                    model.set({
                        isValid: false
                    });
                } else {
                    for (attr in model.validation) {
                        if (_.isUndefined(attrs[attr]) && validateAttr(model, attr, model.get(attr))) {
                            isValid = false;
                            break;
                        }
                    }
                    model.set({
                        isValid: isValid
                    });
                }

                return invalidAttr;
            };
        },

        unbind: function(view) {
            view.model.validate = undefined;
        }
    };
} (Backbone, _));

Backbone.Validation.callbacks = {
    valid: function(view, attr) {
        view.$('#' + attr).removeClass('invalid');
        view.$('#' + attr).removeAttr('data-error');
    },

    invalid: function(view, attr, error) {
        view.$('#' + attr).addClass('invalid');
        view.$('#' + attr).attr('data-error', error);
    }
};

Backbone.Validation.patterns = {
    number: /^\d$/,
    email: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
    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\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
};

Backbone.Validation.validators = (function(_, $) {
    return {
        required: function(value, attr, msg) {
            var isEmptyString = _.isString(value) && $.trim(value) === '';
            var isFalseBoolean = _.isBoolean(value) && value === false;

            if (_.isNull(value) || _.isUndefined(value) || isEmptyString || isFalseBoolean) {
                return msg || attr + ' is required';
            }
        },
        min: function(value, attr, msg, minValue) {
            value = parseInt(value, 10);
            if (!_.isNumber(value) || value < minValue) {
                return msg || attr + ' must be larger than or equal to ' + minValue;
            }
        },
        max: function(value, attr, msg, maxValue) {
            value = parseInt(value, 10);
            if (!_.isNumber(value) || value > maxValue) {
                return msg || attr + ' must be less than or equal to ' + maxValue;
            }
        },
        minLength: function(value, attr, msg, minLength) {
            value = $.trim(value);
            if (_.isString(value) && value.length < minLength) {
                return msg || attr + ' must be longer than or equal to ' + minLength + ' characters';
            }
        },
        maxLength: function(value, attr, msg, maxLength) {
            value = $.trim(value);
            if (_.isString(value) && value.length > maxLength) {
                return msg || attr + ' must be shorter than or equal to' + maxLength + ' characters';
            }
        },
        pattern: function(value, attr, msg, pattern) {
            pattern = Backbone.Validation.patterns[pattern] || pattern;
            if (_.isString(value) && !value.match(pattern)) {
                return msg || attr + ' is not a valid ' + pattern;
            }
        }
    };
} (_, jQuery));
{'fraction_non_alphanumeric': 0.23244079108000326, 'fraction_numerical': 0.02864816472694718, 'mean_word_length': 1.9978043425225664, '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': '3062031', 'n_tokens_mistral': 5035, 'n_tokens_neox': 4481, 'n_words': 650}