<commit_before>/*!
 * Copyright 2013 Apereo Foundation (AF) Licensed under the
 * Educational Community License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 *     http://opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

var _ = require('underscore');
var tz = require('oae-util/lib/tz');
var Validator = module.exports.Validator = require('validator').Validator;

/*!
 * Wrapper function around node-validator that makes sure that a validation
 * Failure doesn't throw an error and just collects all of the errors
 *
 * @param  {Object}  msg     Error that should be recorded if the validation fails
 */
Validator.prototype.error = function (msg) {
    this._errors.push(msg);
};

/*!
 * Wrapper function around node-validator that allows use of error objects
 */
Validator.prototype.check = function (str, fail_msg) {
    if (typeof str === 'object' && str !== null && str.toString) {
        str = str.toString();
    }
    this.str = (str === null || str === undefined || (isNaN(str) && str.length === undefined)) ? '' : str;
    this.str += '';

    this.errorDictionary = {};
    this.msg = fail_msg;

    this._errors = this._errors || [];
    return this;
};

/**
 * Wrapper function around node-validator that retrieves all of the validation
 * errors that have been encountered for a given Validator instance
 *
 * Usage:
 * ```
 * var validator = new Validator();
 * ...
 * var errors = validator.getErrors();
 * ```
 *
 * @return {Object[]}     Array containing all of the validation errors
 */
Validator.prototype.getErrors = function () {
    if (this._errors && this._errors.length > 0) {
        return this._errors;
    } else {
        return null;
    }
};

/**
 * Wrapper function around node-validator that determines how many errors have been collected.
 * @return {Number}     The number of errors that have been collected by this validator<commit_msg>actually wrap validator.check instead of re-writing it<commit_after>/*!
 * Copyright 2013 Apereo Foundation (AF) Licensed under the
 * Educational Community License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 *     http://opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

var _ = require('underscore');
var tz = require('oae-util/lib/tz');
var Validator = module.exports.Validator = require('validator').Validator;

/*!
 * Wrapper function around node-validator that makes sure that a validation
 * Failure doesn't throw an error and just collects all of the errors
 *
 * @param  {Object}  msg     Error that should be recorded if the validation fails
 */
Validator.prototype.error = function (msg) {
    this._errors.push(msg);
};

/*!
 * Wrapper function around node-validator that allows use of error objects
 */
var origCheck = Validator.prototype.check;
Validator.prototype.check = function (str, fail_msg) {
    var result = origCheck.apply(this, arguments);
    if (result.msg === null) {
        result.msg = result.errorDictionary;
    }
    return result;
};

/**
 * Wrapper function around node-validator that retrieves all of the validation
 * errors that have been encountered for a given Validator instance
 *
 * Usage:
 * ```
 * var validator = new Validator();
 * ...
 * var errors = validator.getErrors();
 * ```
 *
 * @return {Object[]}     Array containing all of the validation errors
 */
Validator.prototype.getErrors = function () {
    if (this._errors && this._errors.length > 0) {
        return this._errors;
    } else {
        return null;
    }
};

/**
 * Wrapper function around node-validator that determines how many errors have been collected.
 * @return {Number}     The number of errors that have been collected by this validator
{'fraction_non_alphanumeric': 0.106006275212909, 'fraction_numerical': 0.004034065441506051, 'mean_word_length': 3.4764292878635907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5280775', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1170, 'n_words': 483}