<commit_before>/*!
 * JavaScript Validator Library v1.0
 * To perform effective validation and filter with form elements.
 *
 * Author : <NAME>
 * Email  : <EMAIL>
 * Github : https://github.com/shankarThiyagaraajan
 *
 * Source
 * https://github.com/global-source/javascript_form_validator
 *
 * Site
 * https://global-source.github.io/javascript_form_validator/
 *
 * Copyright 2017
 *
 * Released under the MIT license
 * https://github.com/global-source/javascript_form_validator/blob/master/LICENSE
 *
 * Date: 2017-05-01
 */

/*
 * For Managing overall Validation flow.
 */

class jsValidator {

    constructor() {
        // Holding form element data.
        this.formData = false;
        // Switch complete validation and input filter.
        this.onlyFilter = false;
        // JS form.
        this.jsForm = false;
        // JS setting.
        this.jsSettings = false;
        // JS form error.
        this.jsFormError = false;
        // Overall error list.
        this.formErrorList = {};
        // Common Logger Instance.
        this.jsFilter = false;
        // To Filter non-required fields.
        this.forceFilter = false;
        // To Filter the First load.
        this.initialLoad = true;
        // Global options.
        this.option = false;
        // To apply global validator.
        this.onChange = false;
    }

    // Initiating the Validator.
    init(option) {
        this.jsFilter = new jsFilter(option.forceFilter);

        jsLogger.table(option);

        // To Update global options.
        this.option = option;
        // Updating the filter flag to global.
        // this.onlyFilter = option.onlyFilter;
        // To Enable/Disable global validator.
        this.onChange = option.onChange;
        // Update "jsSettings" to global object.
        this.jsSettings = new jsSettings().init(option);
        // Update "jsForm" to global object.
        this.jsForm = new jsForm().init(option);
        // Initiate form error setup.
        this.jsFormError = new jsFormError().init();
        // Initiate Rule Sets.
        this.jsRuleSets = new jsRuleSets();
        // Update Force Field status.
        this.forceFilter = option.forceFilter;
        // To check the form elements.
        this.check();
        // To register the listener.
        this.submitListener(this.jsForm.formCore, this);
        // Send back "this".
        return this;
    }

    // To make listen on submit action of the form.
    submitListener(formID, obj) {
        // To off submit listener, if only filter needed.
        if (false === this.onlyFilter || typeof(this.onlyFilter) === 'undefined') {
            // Initiate listener for form submission.
            document.querySelector("#" + formID).addEventListener("submit", function (e) {

                // To start form validations and authorize.
                if (false === obj.check()) {
                    //stop form from submitting, if validation fails
                    e.preventDefault();
                }
            });
        }
    }

    // To update the DOM to make action listener.
    update() {
        // To Update global options.
        let option = this.option;
        // Update "jsSettings" to global object.
        this.jsSettings = new jsSettings().init(option);
        // Update "jsForm" to global object.
        this.jsForm = new jsForm().init(option);
        // Initiate form error setup.
        this.jsFormError = new jsFormError().init();
    }

    // To checking all elements from registered form.
    check() {
        // Loading JS Form.
        let jsFormObj = this.jsForm;
        // Loading JS error list.
        let errorList = this.formErrorList;
        // Overall validation status.
        let status = false;

        let option = [];

        // Looping the "input" elements for validation and filter implementation.
        errorList.input = this.elemLoop('input', jsFormObj.input);
        // Looping the "textArea" elements fro validation filter implementation.
        errorList.textArea = this.elemLoop('textArea', jsFormObj.textArea);
        // Looping the "select" elements fro validation filter implementation.
        errorList.select = this.elemLoop('select', jsFormObj.select);

        option.push({'errorElem': errorList});

        jsLogger.out('Error List', option);

        // To Update global Validation Status.
        // If, Input elements have no errors.
        if (errorList.input.length === 0) {
            // If, Text Area elements have no errors.
            if (errorList.textArea.length === 0) {
                // If, Select elements have no errors.
                if (errorList.select.length === 0) {
                    alert('Form Valid !');
                    // If validation pass, then update "validationPass" object.
                    status = true;
                }
            }
        }
        if (false == this.initialLoad) validationResponse.init(errorList, this.option);

        this.initialLoad = false;

        return status;
    }

    // To looping all elements for actions.
    elemLoop(index, formElem) {
        // Initiate empty array for keep list of errors.
        let log = [];
        if (formElem === null || typeof formElem === 'undefined') return false;
        // jsLogger.out('Elem Loop Filter', formElem);
        // Looping elements.
        for (let i in formElem) {
            if (formElem[i]) {
                // Switch to static variable.
                let activeElem = formElem[i];
                // Apply filter to element.
                this.applyFilters(activeElem);
                // Register the DOM with live onChange validations.
                if (true == this.onChange) {
                    this.applyGlobalListener(activeElem);
                }
                // If not only filter, then start validations.
                if (false === this.onlyFilter || 'undefined' === this.onlyFilter) {<commit_msg>Update formValidator.es6.js<commit_after>/*!
 * JavaScript Validator Library v1.0
 * To perform effective validation and filter with form elements.
 *
 * Author : <NAME>
 * Email  : <EMAIL>
 * Github : https://github.com/shankarThiyagaraajan
 *
 * Source
 * https://github.com/global-source/javascript_form_validator
 *
 * Site
 * https://global-source.github.io/javascript_form_validator/
 *
 * Copyright 2017
 *
 * Released under the MIT license
 * https://github.com/global-source/javascript_form_validator/blob/master/LICENSE
 *
 * Date: 2017-05-01
 */

/*
 * For Managing overall Validation flow.
 */

class jsValidator {

    constructor() {
        // Holding form element data.
        this.formData = false;
        // Switch complete validation and input filter.
        this.onlyFilter = false;
        // JS form.
        this.jsForm = false;
        // JS setting.
        this.jsSettings = false;
        // JS form error.
        this.jsFormError = false;
        // Overall error list.
        this.formErrorList = {};
        // Common Logger Instance.
        this.jsFilter = false;
        // To Filter non-required fields.
        this.forceFilter = false;
        // To Filter the First load.
        this.initialLoad = true;
        // Global options.
        this.option = false;
        // To apply global validator.
        this.onChange = false;
    }

    // Initiating the Validator.
    init(option) {
        this.jsFilter = new jsFilter(option.forceFilter);

        jsLogger.table(option);

        // To Update global options.
        this.option = option;
        // Updating the filter flag to global.
        // this.onlyFilter = option.onlyFilter;
        // To Enable/Disable global validator.
        this.onChange = option.onChange;
        // Update "jsSettings" to global object.
        this.jsSettings = new jsSettings().init(option);
        // Update "jsForm" to global object.
        this.jsForm = new jsForm().init(option);
        // Initiate form error setup.
        this.jsFormError = new jsFormError().init();
        // Initiate Rule Sets.
        this.jsRuleSets = new jsRuleSets();
        // Update Force Field status.
        this.forceFilter = option.forceFilter;
        // To check the form elements.
        this.check();
        // To register the listener.
        this.submitListener(this.jsForm.formCore, this);
        // Send back "this".
        return this;
    }

    // To make listen on submit action of the form.
    submitListener(formID, obj) {
        // To off submit listener, if only filter needed.
        if (false === this.onlyFilter || typeof(this.onlyFilter) === 'undefined') {
            // Initiate listener for form submission.
            document.querySelector("#" + formID).addEventListener("submit", function (e) {

                // To start form validations and authorize.
                if (false === obj.check()) {
                    //stop form from submitting, if validation fails
                    e.preventDefault();
                }
            });
        }
    }

    // To update the DOM to make action listener.
    update() {
        // To Update global options.
        let option = this.option;
        // Update "jsSettings" to global object.
        this.jsSettings = new jsSettings().init(option);
        // Update "jsForm" to global object.
        this.jsForm = new jsForm().init(option);
        // Initiate form error setup.
        this.jsFormError = new jsFormError().init();
    }

    // To checking all elements from registered form.
    check() {
        // Loading JS Form.
        let jsFormObj = this.jsForm;
        // Loading JS error list.
        let errorList = this.formErrorList;
        // Overall validation status.
        let status = false;

        let option = [];

        // Looping the "input" elements for validation and filter implementation.
        errorList.input = this.elemLoop('input', jsFormObj.input);
        // Looping the "textArea" elements fro validation filter implementation.
        errorList.textArea = this.elemLoop('textArea', jsFormObj.textArea);
        // Looping the "select" elements fro validation filter implementation.
        errorList.select = this.elemLoop('select', jsFormObj.select);

        option.push({'errorElem': errorList});

        jsLogger.out('Error List', option);

        // To Update global Validation Status.
        // If, Input elements have no errors.
        if (errorList.input.length === 0) {
            // If, Text Area elements have no errors.
            if (errorList.textArea.length === 0) {
                // If, Select elements have no errors.
                if (errorList.select.length === 0) {
                    // If validation pass, then update "validationPass" object.
                    status = true;
                }
            }
        }
        if (false == this.initialLoad) validationResponse.init(errorList, this.option);

        this.initialLoad = false;

        return status;
    }

    // To looping all elements for actions.
    elemLoop(index, formElem) {
        // Initiate empty array for keep list of errors.
        let log = [];
        if (formElem === null || typeof formElem === 'undefined') return false;
        // jsLogger.out('Elem Loop Filter', formElem);
        // Looping elements.
        for (let i in formElem) {
            if (formElem[i]) {
                // Switch to static variable.
                let activeElem = formElem[i];
                // Apply filter to element.
                this.applyFilters(activeElem);
                // Register the DOM with live onChange validations.
                if (true == this.onChange) {
                    this.applyGlobalListener(activeElem);
                }
                // If not only filter, then start validations.
                if (false === this.onlyFilter || 'undefined' === this.onlyFilter) {
{'fraction_non_alphanumeric': 0.10724808485562758, 'fraction_numerical': 0.0029463759575721863, 'mean_word_length': 1.8065201984408221, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, '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': '3280409', 'n_tokens_mistral': 3115, 'n_tokens_neox': 3007, 'n_words': 929}