<commit_before>var utils = require("./utils");
var util = require("util");

var convertPlugTimeToDate = function(plugTime) {
    var res = /(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+).(\d+)/g.exec(plugTime);
    var time = "Invalid Date";

    if(res === null)
        return time;

    for(var i = res.length - 1; i >= 0; i--) {
        // clean array from unnecessary info
        if(isNaN(res[i]) && !isFinite(res[i]))
            res.splice(i, 1);
    }

    if(res.length === 3) {
        res.unshift("%s-%s-%s");
        time = util.format.apply(util, res);
    } else if(res.length === 6) {
        res.unshift("%s-%s-%sT%s:%s:%sZ");
        time = util.format.apply(util, res);
    } else if(res.length === 7) {
        res.unshift("%s-%s-%sT%s:%s:%s.%sZ");
        time = util.format.apply(util, res);
    }

    return time;
};

var serializeMedia = function(data) {
    data = data || {};
    var title = utils.splitTitle(data.title);

    if(typeof data.id !== "string")
        data.id = String(data.id);

    return {
        id: 0,
        format: (!data.hasOwnProperty("artwork_url") ? 1 : 0),
        cid: data.id || "",
        author: title[0] || "",
        title: title[1] || "",
        image: (!data.hasOwnProperty("artwork_url") ?
            "https://i.ytimg.com/vi/" + data.id + "/default.jpg" :
            data.artwork_url),
        duration: (!data.hasOwnProperty("artwork_url") ?
            0 :
            Math.round((data.duration ? data.duration : 0) / 1000))
    };
};

var serializeMediaObjects = function(data) {
    data = data || {};
    var arr = [];

    for(var i = 0, l = data.length; i < l; i++)
        arr[i] = serializeMedia(data[i]);

    return arr;
};

var parseSelf = function(data) {
    data = data || {};

    return {
        joined: convertPlugTimeToDate(data.joined),
        username: utils.decode(data.username) || "",
        avatarID: data.avatarID || "base01",
        language: data.language || "en",
        blurb: utils.decode(data.blurb) || "",
        slug: data.slug || "",
        notifications: data.notification || [],
        settings: data.settings || {
            chatTimestamps: 12,
            notifyFriendJoin: true,
            notifyScore: true,
            chatImages: true,
            videoOnly: true,
            tooltips: true,
            notifyDJ: true,
            emoji: true,
        },
        ignores: data.ignores || [],
        friends: data.friends || [],
        pw: data.pw || false,
        level: data.level || 0,
        gRole: data.gRole || 0,
        badge: data.badge || "",
        role: data.role || 0,
        vote: data.vote || 0,
        sub: data.sub || 0,
        xp: data.xp || 0,
        pp: data.pp || 0,
        id: data.id || -1
    };
};<commit_msg>removed vote in parseSelf<commit_after>var utils = require("./utils");
var util = require("util");

var convertPlugTimeToDate = function(plugTime) {
    var res = /(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+).(\d+)/g.exec(plugTime);
    var time = "Invalid Date";

    if(res === null)
        return time;

    for(var i = res.length - 1; i >= 0; i--) {
        // clean array from unnecessary info
        if(isNaN(res[i]) && !isFinite(res[i]))
            res.splice(i, 1);
    }

    if(res.length === 3) {
        res.unshift("%s-%s-%s");
        time = util.format.apply(util, res);
    } else if(res.length === 6) {
        res.unshift("%s-%s-%sT%s:%s:%sZ");
        time = util.format.apply(util, res);
    } else if(res.length === 7) {
        res.unshift("%s-%s-%sT%s:%s:%s.%sZ");
        time = util.format.apply(util, res);
    }

    return time;
};

var serializeMedia = function(data) {
    data = data || {};
    var title = utils.splitTitle(data.title);

    if(typeof data.id !== "string")
        data.id = String(data.id);

    return {
        id: 0,
        format: (!data.hasOwnProperty("artwork_url") ? 1 : 0),
        cid: data.id || "",
        author: title[0] || "",
        title: title[1] || "",
        image: (!data.hasOwnProperty("artwork_url") ?
            "https://i.ytimg.com/vi/" + data.id + "/default.jpg" :
            data.artwork_url),
        duration: (!data.hasOwnProperty("artwork_url") ?
            0 :
            Math.round((data.duration ? data.duration : 0) / 1000))
    };
};

var serializeMediaObjects = function(data) {
    data = data || {};
    var arr = [];

    for(var i = 0, l = data.length; i < l; i++)
        arr[i] = serializeMedia(data[i]);

    return arr;
};

var parseSelf = function(data) {
    data = data || {};

    return {
        joined: convertPlugTimeToDate(data.joined),
        username: utils.decode(data.username) || "",
        avatarID: data.avatarID || "base01",
        language: data.language || "en",
        blurb: utils.decode(data.blurb) || "",
        slug: data.slug || "",
        notifications: data.notification || [],
        settings: data.settings || {
            chatTimestamps: 12,
            notifyFriendJoin: true,
            notifyScore: true,
            chatImages: true,
            videoOnly: true,
            tooltips: true,
            notifyDJ: true,
            emoji: true,
        },
        ignores: data.ignores || [],
        friends: data.friends || [],
        pw: data.pw || false,
        level: data.level || 0,
        gRole: data.gRole || 0,
        badge: data.badge || "",
        role: data.role || 0,
        sub: data.sub || 0,
        xp: data.xp || 0,
        pp: data.pp || 0,
        id: data.id || -1
    };
};
{'fraction_non_alphanumeric': 0.186, 'fraction_numerical': 0.010727272727272728, 'mean_word_length': 1.9121228163049233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3412472', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1827, 'n_words': 378}