<commit_before>/*! Kernel CI Dashboard | Licensed under the GNU GPL v3 (or later) */
define([
    'utils/date'
], function() {
    'use strict';
    var dateFormat,
        format,
        numFormat,
        sizes;

    format = {};

    try {
        dateFormat = new Intl.DateTimeFormat(
            ['en-US'], {month: 'long', year: 'numeric'});
    } catch (ignore) {
        /*
         * WebKit does not have the Intl library implementation.
         * So do the mobile browsers.
        */
        dateFormat = {
            format: function(value) {
                return value.toCustomISODate();
            }
        };
    }

    try {
        numFormat = new Intl.NumberFormat(['en-US']);
    } catch (ignore) {
        /*
         * WebKit does not have the Intl library implementation.
         * So do the mobile browsers.
        */
        numFormat = {
            format: function(value) {
                return value;
            }
        };
    }

    sizes = [
        'bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'
    ];

    /**
     * Round a value down to 2 decimal positions.
     *
     * @private
     * @param {Number} value: The value to round.
     * @return {Number} The rounded value.
    **/
    function roundToTwo(value) {
        return +(Math.round(value + 'e+2') + 'e-2');
    }

    /**
     * Format a number through the Intl library.
     *
     * @param {Number} value: The number to format.
     * @return {String} The formatted number as a string.
    **/
    format.number = function(value) {
        return numFormat.format(value);
    };


    /**
     * Format a bytes number into a human-readable form.
     *
     * @param {Number} bytes: The bytes number to format.
     * @return {String} The formatted number as a string.
    **/
    format.bytes = function(bytes) {
        var calcBase;
        var idx;
        var retVal;

        calcBase = 1024;
        if (bytes === 0 || isNaN(bytes)) {
            retVal = '0 bytes';
        } else {
            idx = Math.floor(Math.log(bytes) / Math.log(calcBase));
            retVal = numFormat.format(
                roundToTwo(
                    bytes / Math.pow(calcBase, idx))) + ' ' + sizes[idx];
        }

        return retVal;<commit_msg>Add float formatting function<commit_after>/*! Kernel CI Dashboard | Licensed under the GNU GPL v3 (or later) */
define([
    'utils/date'
], function() {
    'use strict';
    var dateFormat,
        format,
        numFormat,
        sizes;

    format = {};

    try {
        dateFormat = new Intl.DateTimeFormat(
            ['en-US'], {month: 'long', year: 'numeric'});
    } catch (ignore) {
        /*
         * WebKit does not have the Intl library implementation.
         * So do the mobile browsers.
        */
        dateFormat = {
            format: function(value) {
                return value.toCustomISODate();
            }
        };
    }

    try {
        numFormat = new Intl.NumberFormat(['en-US']);
    } catch (ignore) {
        /*
         * WebKit does not have the Intl library implementation.
         * So do the mobile browsers.
        */
        numFormat = {
            format: function(value) {
                return value;
            }
        };
    }

    sizes = [
        'bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'
    ];

    /**
     * Round a value down to 2 decimal positions.
     *
     * @private
     * @param {Number} value: The value to round.
     * @return {Number} The rounded value.
    **/
    function roundToTwo(value) {
        return +(Math.round(value + 'e+2') + 'e-2');
    }

    /**
     * Format a number through the Intl library.
     *
     * @param {Number} value: The number to format.
     * @return {String} The formatted number as a string.
    **/
    format.number = function(value) {
        return numFormat.format(value);
    };

    /**
     * Format a fload number rounding it to two decimals.
     * Formatting is done through the Intl libray.
     *
     * @param {Number} value: The floating point number to format.
     * @return {String} The formatted number as a string.
    **/
    format.float = function(value) {
        return numFormat.format(roundToTwo(value));
    };

    /**
     * Format a bytes number into a human-readable form.
     *
     * @param {Number} bytes: The bytes number to format.
     * @return {String} The formatted number as a string.
    **/
    format.bytes = function(bytes) {
        var calcBase;
        var idx;
        var retVal;

        calcBase = 1024;
        if (bytes === 0 || isNaN(bytes)) {
            retVal = '0 bytes';
        } else {
            idx = Math.floor(Math.log(bytes) / Math.log(calcBase));
            retVal = numFormat.format(
                roundToTwo(
                    bytes / Math.pow(calcBase, idx))) + ' ' + sizes[idx];
        }

        return retVal;
{'fraction_non_alphanumeric': 0.12675483214649033, 'fraction_numerical': 0.004069175991861648, 'mean_word_length': 1.643010752688172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5618108', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1433, 'n_words': 425}