src/static/js/Intl.js
function $$core$$calculateScore (options, formats, bestFit) {
        var
        // Additional penalty type when bestFit === true
           diffDataTypePenalty = 8,

        // 1. Let removalPenalty be 120.
            removalPenalty = 120,

        // 2. Let additionPenalty be 20.
            additionPenalty = 20,

        // 3. Let longLessPenalty be 8.
            longLessPenalty = 8,

        // 4. Let longMorePenalty be 6.
            longMorePenalty = 6,

        // 5. Let shortLessPenalty be 6.
            shortLessPenalty = 6,

        // 6. Let shortMorePenalty be 3.
            shortMorePenalty = 3,

        // 7. Let bestScore be -Infinity.
            bestScore = -Infinity,

        // 8. Let bestFormat be undefined.
            bestFormat,

        // 9. Let i be 0.
            i = 0,

        // 10. Let len be the result of calling the [[Get]] internal method of formats with argument "length".
            len = formats.length;

        // 11. Repeat while i < len:
        while (i < len) {
            var
            // a. Let format be the result of calling the [[Get]] internal method of formats with argument ToString(i).
                format = formats[i],

            // b. Let score be 0.
                score = 0;

            // c. For each property shown in Table 3:
            for (var property in $$core$$dateTimeComponents) {
                if (!$$core$$hop.call($$core$$dateTimeComponents, property))
                    continue;

                var
                // i. Let optionsProp be options.[[<property>]].
                    optionsProp = options['[['+ property +']]'],

                // ii. Let formatPropDesc be the result of calling the [[GetOwnProperty]] internal method of format
                //     with argument property.
                // iii. If formatPropDesc is not undefined, then
                //     1. Let formatProp be the result of calling the [[Get]] internal method of format with argument property.
                    formatProp = $$core$$hop.call(format, property) ? format[property] : undefined;

                // iv. If optionsProp is undefined and formatProp is not undefined, then decrease score by
                //     additionPenalty.
                if (optionsProp === undefined && formatProp !== undefined)
                    score -= additionPenalty;

                // v. Else if optionsProp is not undefined and formatProp is undefined, then decrease score by
                //    removalPenalty.
                else if (optionsProp !== undefined && formatProp === undefined)
                    score -= removalPenalty;

                // vi. Else
                else {
                    var
                    // 1. Let values be the array ["2-digit", "numeric", "narrow", "short",
                    //    "long"].
                        values = [ '2-digit', 'numeric', 'narrow', 'short', 'long' ],

                    // 2. Let optionsPropIndex be the index of optionsProp within values.
                        optionsPropIndex = $$core$$arrIndexOf.call(values, optionsProp),

                    // 3. Let formatPropIndex be the index of formatProp within values.
                        formatPropIndex = $$core$$arrIndexOf.call(values, formatProp),

                    // 4. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2).
                        delta = Math.max(Math.min(formatPropIndex - optionsPropIndex, 2), -2);

                    // When the bestFit argument is true, subtract additional penalty where data types are not the same
                    if (bestFit && (
                        ((optionsProp === 'numeric' || optionsProp === '2-digit') && (formatProp !== 'numeric' && formatProp !== '2-digit') || (optionsProp !== 'numeric' && optionsProp !== '2-digit') && (formatProp === '2-digit' || formatProp === 'numeric'))
                    ))
                        score -= diffDataTypePenalty;

                    // 5. If delta = 2, decrease score by longMorePenalty.
                    if (delta === 2)
                        score -= longMorePenalty;

                    // 6. Else if delta = 1, decrease score by shortMorePenalty.
                    else if (delta === 1)
                        score -= shortMorePenalty;

                    // 7. Else if delta = -1, decrease score by shortLessPenalty.
                    else if (delta === -1)
                        score -= shortLessPenalty;

                    // 8. Else if delta = -2, decrease score by longLessPenalty.
                    else if (delta === -2)
                        score -= longLessPenalty;
                }
            }

            // d. If score > bestScore, then
            if (score > bestScore) {
                // i. Let bestScore be score.
                bestScore = score;

                // ii. Let bestFormat be format.
                bestFormat = format;
            }

            // e. Increase i by 1.
            i++;
        }

        // 12. Return bestFormat.
        return bestFormat;
    }
function $$core$$calculateScore (options, formats, bestFit) {
        var
        // Additional penalty type when bestFit === true
           diffDataTypePenalty = 8,

        // 1. Let removalPenalty be 120.
            removalPenalty = 120,

        // 2. Let additionPenalty be 20.
            additionPenalty = 20,

        // 3. Let longLessPenalty be 8.
            longLessPenalty = 8,

        // 4. Let longMorePenalty be 6.
            longMorePenalty = 6,

        // 5. Let shortLessPenalty be 6.
            shortLessPenalty = 6,

        // 6. Let shortMorePenalty be 3.
            shortMorePenalty = 3,

        // 7. Let bestScore be -Infinity.
            bestScore = -Infinity,

        // 8. Let bestFormat be undefined.
            bestFormat,

        // 9. Let i be 0.
            i = 0,

        // 10. Let len be the result of calling the [[Get]] internal method of formats with argument "length".
            len = formats.length;

        // 11. Repeat while i < len:
        while (i < len) {
            var
            // a. Let format be the result of calling the [[Get]] internal method of formats with argument ToString(i).
                format = formats[i],

            // b. Let score be 0.
                score = 0;

            // c. For each property shown in Table 3:
            for (var property in $$core$$dateTimeComponents) {
                if (!$$core$$hop.call($$core$$dateTimeComponents, property))
                    continue;

                var
                // i. Let optionsProp be options.[[<property>]].
                    optionsProp = options['[['+ property +']]'],

                // ii. Let formatPropDesc be the result of calling the [[GetOwnProperty]] internal method of format
                //     with argument property.
                // iii. If formatPropDesc is not undefined, then
                //     1. Let formatProp be the result of calling the [[Get]] internal method of format with argument property.
                    formatProp = $$core$$hop.call(format, property) ? format[property] : undefined;

                // iv. If optionsProp is undefined and formatProp is not undefined, then decrease score by
                //     additionPenalty.
                if (optionsProp === undefined && formatProp !== undefined)
                    score -= additionPenalty;

                // v. Else if optionsProp is not undefined and formatProp is undefined, then decrease score by
                //    removalPenalty.
                else if (optionsProp !== undefined && formatProp === undefined)
                    score -= removalPenalty;

                // vi. Else
                else {
                    var
                    // 1. Let values be the array ["2-digit", "numeric", "narrow", "short",
                    //    "long"].
                        values = [ '2-digit', 'numeric', 'narrow', 'short', 'long' ],

                    // 2. Let optionsPropIndex be the index of optionsProp within values.
                        optionsPropIndex = $$core$$arrIndexOf.call(values, optionsProp),

                    // 3. Let formatPropIndex be the index of formatProp within values.
                        formatPropIndex = $$core$$arrIndexOf.call(values, formatProp),

                    // 4. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2).
                        delta = Math.max(Math.min(formatPropIndex - optionsPropIndex, 2), -2);

                    // When the bestFit argument is true, subtract additional penalty where data types are not the same
                    if (bestFit && (
                        ((optionsProp === 'numeric' || optionsProp === '2-digit') && (formatProp !== 'numeric' && formatProp !== '2-digit') || (optionsProp !== 'numeric' && optionsProp !== '2-digit') && (formatProp === '2-digit' || formatProp === 'numeric'))
                    ))
                        score -= diffDataTypePenalty;

                    // 5. If delta = 2, decrease score by longMorePenalty.
                    if (delta === 2)
                        score -= longMorePenalty;

                    // 6. Else if delta = 1, decrease score by shortMorePenalty.
                    else if (delta === 1)
                        score -= shortMorePenalty;

                    // 7. Else if delta = -1, decrease score by shortLessPenalty.
                    else if (delta === -1)
                        score -= shortLessPenalty;

                    // 8. Else if delta = -2, decrease score by longLessPenalty.
                    else if (delta === -2)
                        score -= longLessPenalty;
                }
            }

            // d. If score > bestScore, then
            if (score > bestScore) {
                // i. Let bestScore be score.
                bestScore = score;

                // ii. Let bestFormat be format.
                bestFormat = format;
            }

            // e. Increase i by 1.
            i++;
        }

        // 12. Return bestFormat.
        return bestFormat;
    }
function $$core$$calculateScore ( options , formats , bestFit ) { var // Additional penalty type when bestFit === true diffDataTypePenalty = 8 , // 1. Let removalPenalty be 120. removalPenalty = 120 , // 2. Let additionPenalty be 20. additionPenalty = 20 , // 3. Let longLessPenalty be 8. longLessPenalty = 8 , // 4. Let longMorePenalty be 6. longMorePenalty = 6 , // 5. Let shortLessPenalty be 6. shortLessPenalty = 6 , // 6. Let shortMorePenalty be 3. shortMorePenalty = 3 , // 7. Let bestScore be -Infinity. bestScore = - Infinity , // 8. Let bestFormat be undefined. bestFormat , // 9. Let i be 0. i = 0 , // 10. Let len be the result of calling the [[Get]] internal method of formats with argument "length". len = formats . length ; // 11. Repeat while i < len: while ( i < len ) { var // a. Let format be the result of calling the [[Get]] internal method of formats with argument ToString(i). format = formats [ i ] , // b. Let score be 0. score = 0 ; // c. For each property shown in Table 3: for ( var property in $$core$$dateTimeComponents ) { if ( ! $$core$$hop . call ( $$core$$dateTimeComponents , property ) ) continue ; var // i. Let optionsProp be options.[[<property>]]. optionsProp = options [ '[[' + property + ']]' ] , // ii. Let formatPropDesc be the result of calling the [[GetOwnProperty]] internal method of format //     with argument property. // iii. If formatPropDesc is not undefined, then //     1. Let formatProp be the result of calling the [[Get]] internal method of format with argument property. formatProp = $$core$$hop . call ( format , property ) ? format [ property ] : undefined ; // iv. If optionsProp is undefined and formatProp is not undefined, then decrease score by //     additionPenalty. if ( optionsProp === undefined && formatProp !== undefined ) score -= additionPenalty ; // v. Else if optionsProp is not undefined and formatProp is undefined, then decrease score by //    removalPenalty. else if ( optionsProp !== undefined && formatProp === undefined ) score -= removalPenalty ; // vi. Else else { var // 1. Let values be the array ["2-digit", "numeric", "narrow", "short", //    "long"]. values = [ '2-digit' , 'numeric' , 'narrow' , 'short' , 'long' ] , // 2. Let optionsPropIndex be the index of optionsProp within values. optionsPropIndex = $$core$$arrIndexOf . call ( values , optionsProp ) , // 3. Let formatPropIndex be the index of formatProp within values. formatPropIndex = $$core$$arrIndexOf . call ( values , formatProp ) , // 4. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2). delta = Math . max ( Math . min ( formatPropIndex - optionsPropIndex , 2 ) , - 2 ) ; // When the bestFit argument is true, subtract additional penalty where data types are not the same if ( bestFit && ( ( ( optionsProp === 'numeric' || optionsProp === '2-digit' ) && ( formatProp !== 'numeric' && formatProp !== '2-digit' ) || ( optionsProp !== 'numeric' && optionsProp !== '2-digit' ) && ( formatProp === '2-digit' || formatProp === 'numeric' ) ) ) ) score -= diffDataTypePenalty ; // 5. If delta = 2, decrease score by longMorePenalty. if ( delta === 2 ) score -= longMorePenalty ; // 6. Else if delta = 1, decrease score by shortMorePenalty. else if ( delta === 1 ) score -= shortMorePenalty ; // 7. Else if delta = -1, decrease score by shortLessPenalty. else if ( delta === - 1 ) score -= shortLessPenalty ; // 8. Else if delta = -2, decrease score by longLessPenalty. else if ( delta === - 2 ) score -= longLessPenalty ; } } // d. If score > bestScore, then if ( score > bestScore ) { // i. Let bestScore be score. bestScore = score ; // ii. Let bestFormat be format. bestFormat = format ; } // e. Increase i by 1. i ++ ; } // 12. Return bestFormat. return bestFormat ; }
Calculates score for BestFitFormatMatcher and BasicFormatMatcher.
Abstracted from BasicFormatMatcher section.
Calculates score for BestFitFormatMatcher and BasicFormatMatcher . Abstracted from BasicFormatMatcher section .