<commit_before>﻿/* expressive.annotations.validate.js - v1.2.0
 * this script is a part of client side component of ExpresiveAnnotations - annotation-based conditional validation library
 * copyright (c) 2014 <NAME> - https://github.com/JaroslawWaliszko
 * licensed MIT: http://www.opensource.org/licenses/mit-license.php */

(function ($, analyser) {

    var ModelPrefix = {
        append: function (value, prefix) {
            return prefix + value;
        },
        get: function (fieldName) {
            return fieldName.substr(0, fieldName.lastIndexOf('.') + 1);
        }
    };

    var Helper = {
        extractValue: function (form, dependentProperty, prefix) {
            function getFieldValue(field) {
                var type = $(field).attr('type');
                switch (type) {
                    case 'checkbox':
                        return $(field).is(':checked');
                    case 'radio':
                        return $(field).filter(':checked').val();
                    default:
                        return $(field).val();
                }
            }
            var dependentField = $(form).find(':input[name="' + ModelPrefix.append(dependentProperty, prefix) + '"]');
            var dependentValue = getFieldValue(dependentField);
            return dependentValue;
        },
        fetchTargetValue: function(form, targetValue, prefix) {
            if (typeof targetValue === 'string' || targetValue instanceof String) {
                var patt = new RegExp('\\[(.+)\\]');
                if (patt.test(targetValue)) {
                    var targetProperty = targetValue.substring(1, targetValue.length - 1);
                    targetValue = $(form).find(':input[name="' + ModelPrefix.append(targetProperty, prefix) + '"]').val();
                }
            }
            return targetValue;
        },
        compute: function (dependentValue, targetValue, relationalOperator) {
            switch (relationalOperator) {
                case '==':
                    return Helper.compare(dependentValue, targetValue);
                case "!=":
                    return !Helper.compare(dependentValue, targetValue);
                case ">":
                    return Helper.greater(dependentValue, targetValue);
                case ">=":
                    return !Helper.less(dependentValue, targetValue);
                case "<":
                    return Helper.less(dependentValue, targetValue);
                case "<=":
                    return !Helper.greater(dependentValue, targetValue);
            }

            throw analyser.Utils.String.format('Relational operator {0} is invalid. Available operators: ==, !=, >, >=, <, <=.', relationalOperator);
        },
        compare: function (dependentValue, targetValue) {
            var boolResult;
            if (typeof dependentValue === 'string' || dependentValue instanceof String) {
                boolResult = analyser.Utils.Bool.tryParse(dependentValue);
                dependentValue = boolResult.error ? dependentValue.trim() : boolResult;
            }
            if (typeof targetValue === 'string' || targetValue instanceof String) {
                boolResult = analyser.Utils.Bool.tryParse(targetValue);
                targetValue = boolResult.error ? targetValue.trim() : boolResult;
            }
            return (dependentValue === targetValue) || (dependentValue !== '' && targetValue === '*');
        },
        greater: function (dependentValue, targetValue) {
            if (!isNaN(dependentValue) && !isNaN(targetValue))
                return parseFloat(dependentValue) > parseFloat(targetValue);
            if ((typeof dependentValue === 'string' || dependentValue instanceof String)
                && (typeof targetValue === 'string' || targetValue instanceof String))
                return dependentValue.toLowerCase().localeCompare(targetValue.toLowerCase()) > 0;
            if (dependentValue === null || dependentValue === 'undefined' || targetValue === null || targetValue === 'undefined')
                return false;

            throw 'Greater than and less than relational operations not allowed for arguments of types other than numeric or string.';
        },
        less: function (dependentValue, targetValue) {
            if (!isNaN(dependentValue) && !isNaN(targetValue))
                return parseFloat(dependentValue) < parseFloat(targetValue);
            if ((typeof dependentValue === 'string' || dependentValue instanceof String)
                && (typeof targetValue === 'string' || targetValue instanceof String))
                return dependentValue.toLowerCase().localeCompare(targetValue.toLowerCase()) < 0;
            if (dependentValue === null || dependentValue === 'undefined' || targetValue === null || targetValue === 'undefined')
                return false;

            throw 'Greater than and less than relational operations not allowed for arguments of types other than numeric or string.';
        }
    };

    $.validator.unobtrusive.adapters.add('requiredif', ['dependentproperty', 'relationaloperator', 'targetvalue'], function (options) {
        options.rules['requiredif'] = {<commit_msg>Added support for enum values in expressions<commit_after>﻿/* expressive.annotations.validate.js - v1.2.0
 * this script is a part of client side component of ExpresiveAnnotations - annotation-based conditional validation library
 * copyright (c) 2014 <NAME> - https://github.com/JaroslawWaliszko
 * licensed MIT: http://www.opensource.org/licenses/mit-license.php */

(function ($, analyser) {

    var ModelPrefix = {
        append: function (value, prefix) {
            return prefix + value;
        },
        get: function (fieldName) {
            return fieldName.substr(0, fieldName.lastIndexOf('.') + 1);
        }
    };

    var Helper = {
        extractValue: function (form, dependentProperty, prefix) {
            function getFieldValue(field) {
                var type = $(field).attr('type');
                switch (type) {
                    case 'checkbox':
                        return $(field).is(':checked');
                    case 'radio':
                        return $(field).filter(':checked').val();
                    default:
                        return $(field).val();
                }
            }
            var dependentField = $(form).find(':input[name="' + ModelPrefix.append(dependentProperty, prefix) + '"]');
            var dependentValue = getFieldValue(dependentField);
            return dependentValue;
        },
        fetchTargetValue: function(form, targetValue, prefix) {
            if (typeof targetValue === 'string' || targetValue instanceof String) {
                var patt = new RegExp('\\[(.+)\\]');
                if (patt.test(targetValue)) {
                    var targetProperty = targetValue.substring(1, targetValue.length - 1);
                    targetValue = $(form).find(':input[name="' + ModelPrefix.append(targetProperty, prefix) + '"]').val();
                }
            }
            return targetValue;
        },
        compute: function (dependentValue, targetValue, relationalOperator) {
            switch (relationalOperator) {
                case '==':
                    return Helper.compare(dependentValue, targetValue);
                case "!=":
                    return !Helper.compare(dependentValue, targetValue);
                case ">":
                    return Helper.greater(dependentValue, targetValue);
                case ">=":
                    return !Helper.less(dependentValue, targetValue);
                case "<":
                    return Helper.less(dependentValue, targetValue);
                case "<=":
                    return !Helper.greater(dependentValue, targetValue);
            }

            throw analyser.Utils.String.format('Relational operator {0} is invalid. Available operators: ==, !=, >, >=, <, <=.', relationalOperator);
        },
        compare: function (dependentValue, targetValue) {
            var boolResult;
            if (typeof dependentValue === 'string' || dependentValue instanceof String) {
                boolResult = analyser.Utils.Bool.tryParse(dependentValue);
                dependentValue = boolResult.error ? dependentValue.trim() : boolResult;
            }
            if (typeof targetValue === 'string' || targetValue instanceof String) {
                boolResult = analyser.Utils.Bool.tryParse(targetValue);
                targetValue = boolResult.error ? targetValue.trim() : boolResult;
            }
            if (!isNaN(parseFloat(dependentValue)) && isFinite(dependentValue) && !isNaN(parseFloat(targetValue)) && isFinite(targetValue)) {
                dependentValue = parseFloat(dependentValue);
                targetValue = parseFloat(targetValue);
            }
            return (dependentValue === targetValue) || (dependentValue !== '' && targetValue === '*');
        },
        greater: function (dependentValue, targetValue) {
            if (!isNaN(dependentValue) && !isNaN(targetValue))
                return parseFloat(dependentValue) > parseFloat(targetValue);
            if ((typeof dependentValue === 'string' || dependentValue instanceof String)
                && (typeof targetValue === 'string' || targetValue instanceof String))
                return dependentValue.toLowerCase().localeCompare(targetValue.toLowerCase()) > 0;
            if (dependentValue === null || dependentValue === 'undefined' || targetValue === null || targetValue === 'undefined')
                return false;

            throw 'Greater than and less than relational operations not allowed for arguments of types other than numeric or string.';
        },
        less: function (dependentValue, targetValue) {
            if (!isNaN(dependentValue) && !isNaN(targetValue))
                return parseFloat(dependentValue) < parseFloat(targetValue);
            if ((typeof dependentValue === 'string' || dependentValue instanceof String)
                && (typeof targetValue === 'string' || targetValue instanceof String))
                return dependentValue.toLowerCase().localeCompare(targetValue.toLowerCase()) < 0;
            if (dependentValue === null || dependentValue === 'undefined' || targetValue === null || targetValue === 'undefined')
                return false;

            throw 'Greater than and less than relational operations not allowed for arguments of types other than numeric or string.';
        }
    };

    $.validator.unobtrusive.adapters.add('requiredif', ['dependentproperty', 'relationaloperator', 'targetvalue'], function (options) {
        options.rules['requiredif'] = {
{'fraction_non_alphanumeric': 0.1207554191087543, 'fraction_numerical': 0.002604893478463113, 'mean_word_length': 2.1386861313868613, 'pattern_counts': {'":': 10, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2218818', 'n_tokens_mistral': 2569, 'n_tokens_neox': 2448, 'n_words': 623}