<commit_before>import jump from 'jump.js'

export default class Util {
    /**
     * Expand color to full RGBA string
     * 
     * @param raw rgba value
     * @return RGBA string
     */
    static expandColor (num) {
        num >>>= 0;

        var b = num & 0xFF,
            g = (num & 0xFF00) >>> 8,
            r = (num & 0xFF0000) >>> 16,
            a = ((num & 0xFF000000) >>> 24) / 255;
        return "rgba(" + [r, g, b, a].join(",") + ")";
    }
    
    static entityEncode (string) {

        while (string.indexOf("<") !== -1) {
            string = string.replace("<", "&lt;");
        }

        while (string.indexOf(">") !== -1) {
            string = string.replace(">", "&gt;");
        }

        string = string.replace(/\n/g, '<br />');

        return string;
    }

    static generateSnippet (object) {

        if(typeof object.snippet != "undefined")
            return object.snippet;

        let snippet = object.snippet || object.data;
        let type = object.message_type || object.type;
        let mime_type = object.mime_type || "text/plain";
        
        
        snippet = mime_type == "text/plain" ? (snippet) : "<i>Photo</i>";

        if (type != 0 && type != 6 && type != 3 && type != 5)
            snippet = "You: " + snippet;

        return snippet;
        
    }

    static generateContact (id, title, mute, private_notifications, color, accent, ligher, darker) {
        return {
            id: id,
            title: title,
            mute: mute,
            private_notifications: private_notifications,
            colors: {
                default: color,
                accent: accent,
                ligher: ligher,
                darker: darker
            }
        }
    }

    /**
        * Scroll to bottom
        * Scrolls thread to bottom of page; uses tween easing
        *
        * @param speed - default to zero (no animation)
        */
    static scrollToBottom(speed) {

        if (typeof speed == "undefined") // Speed defaults to zero
            speed = 0;

        const docu = document.getElementsByTagName("html")[0].clientHeight
        const body = document.getElementsByTagName("body")[0].clientHeight

        const bottom = Math.max(docu, body); // Calculate bottom

        // Jump to bottom
        jump(bottom, {
            duration: speed,
            easing: (t, b, c, d) => { // easeInOutCubic - @jaxgeller
                if ((t/=d/2) < 1) return c/2*t*t*t + b;
                return c/2*((t-=2)*t*t + 2) + b;
            }
        });
    }

    static snackbar(message) {
        var data = {}

        if(typeof message == "string")
            data = { message: message };
        else
            data = message

        var snackbar = document.querySelector('.mdl-js-snackbar');

        if (typeof snackbar.attributes['hidden'] != "undefined") // ad block work around
            snackbar.attributes.removeNamedItem("hidden");

        snackbar.MaterialSnackbar.showSnackbar(data);
    }<commit_msg>Update scrollToBottom with ES6 style default value<commit_after>import jump from 'jump.js'

export default class Util {
    /**
     * Expand color to full RGBA string
     * 
     * @param raw rgba value
     * @return RGBA string
     */
    static expandColor (num) {
        num >>>= 0;

        var b = num & 0xFF,
            g = (num & 0xFF00) >>> 8,
            r = (num & 0xFF0000) >>> 16,
            a = ((num & 0xFF000000) >>> 24) / 255;
        return "rgba(" + [r, g, b, a].join(",") + ")";
    }
    
    static entityEncode (string) {

        while (string.indexOf("<") !== -1) {
            string = string.replace("<", "&lt;");
        }

        while (string.indexOf(">") !== -1) {
            string = string.replace(">", "&gt;");
        }

        string = string.replace(/\n/g, '<br />');

        return string;
    }

    static generateSnippet (object) {

        if(typeof object.snippet != "undefined")
            return object.snippet;

        let snippet = object.snippet || object.data;
        let type = object.message_type || object.type;
        let mime_type = object.mime_type || "text/plain";
        
        
        snippet = mime_type == "text/plain" ? (snippet) : "<i>Photo</i>";

        if (type != 0 && type != 6 && type != 3 && type != 5)
            snippet = "You: " + snippet;

        return snippet;
        
    }

    static generateContact (id, title, mute, private_notifications, color, accent, ligher, darker) {
        return {
            id: id,
            title: title,
            mute: mute,
            private_notifications: private_notifications,
            colors: {
                default: color,
                accent: accent,
                ligher: ligher,
                darker: darker
            }
        }
    }

    /**
        * Scroll to bottom
        * Scrolls thread to bottom of page; uses tween easing
        *
        * @param speed - default to zero (no animation)
        */
    static scrollToBottom(speed=0) {

        const docu = document.getElementsByTagName("html")[0].clientHeight
        const body = document.getElementsByTagName("body")[0].clientHeight

        const bottom = Math.max(docu, body); // Calculate bottom

        // Jump to bottom
        jump(bottom, {
            duration: speed,
            easing: (t, b, c, d) => { // easeInOutCubic - @jaxgeller
                if ((t/=d/2) < 1) return c/2*t*t*t + b;
                return c/2*((t-=2)*t*t + 2) + b;
            }
        });
    }

    static snackbar(message) {
        var data = {}

        if(typeof message == "string")
            data = { message: message };
        else
            data = message

        var snackbar = document.querySelector('.mdl-js-snackbar');

        if (typeof snackbar.attributes['hidden'] != "undefined") // ad block work around
            snackbar.attributes.removeNamedItem("hidden");

        snackbar.MaterialSnackbar.showSnackbar(data);
    }
{'fraction_non_alphanumeric': 0.13700234192037472, 'fraction_numerical': 0.013549682167949146, 'mean_word_length': 1.6281318681318682, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, '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': '4356471', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1727, 'n_words': 452}