aboutsummaryrefslogtreecommitdiff
path: root/build/util.js
blob: 4c7fe64a58f3e65977bc1f3f5a139f456bbdc6f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
/* Utility functions (not related to Hypixel) */
Object.defineProperty(exports, "__esModule", { value: true });
exports.colorCodeFromName = exports.minecraftColorCodes = exports.shuffle = exports.jsonToQuery = exports.queryToJson = exports.undashUuid = void 0;
function undashUuid(uuid) {
    return uuid.replace(/-/g, '');
}
exports.undashUuid = undashUuid;
function queryToJson(queryString) {
    var query = {};
    var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
    for (var i = 0; i < pairs.length; i++) {
        var pair = pairs[i].split('=');
        query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
    }
    return query;
}
exports.queryToJson = queryToJson;
function jsonToQuery(data) {
    return Object.entries(data || {}).map(e => e.join('=')).join('&');
}
exports.jsonToQuery = jsonToQuery;
function shuffle(a) {
    for (let i = a.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [a[i], a[j]] = [a[j], a[i]];
    }
    return a;
}
exports.shuffle = shuffle;
exports.minecraftColorCodes = {
    '0': '#000000',
    '1': '#0000be',
    '2': '#00be00',
    '3': '#00bebe',
    '4': '#be0000',
    '5': '#be00be',
    '6': '#ffaa00',
    '7': '#bebebe',
    '8': '#3f3f3f',
    '9': '#3f3ffe',
    'a': '#3ffe3f',
    'b': '#3ffefe',
    'c': '#fe3f3f',
    'd': '#fe3ffe',
    'e': '#fefe3f',
    'f': '#ffffff',
    'black': '#000000',
    'dark_blue': '#0000be',
    'dark_green': '#00be00',
    'dark_aqua': '#00bebe',
    'dark_red': '#be0000',
    'dark_purple': '#be00be',
    'gold': '#ffaa00',
    'gray': '#bebebe',
    'dark_gray': '#3f3f3f',
    'blue': '#3f3ffe',
    'green': '#3ffe3f',
    'aqua': '#3ffefe',
    'red': '#fe3f3f',
    'light_purple': '#fe3ffe',
    'yellow': '#fefe3f',
    'white': '#ffffff',
};
/**
 * Converts a color name to the code
 * For example: blue -> 9
 * @param colorName The name of the color (blue, red, aqua, etc)
 */
function colorCodeFromName(colorName) {
    const hexColor = exports.minecraftColorCodes[colorName.toLowerCase()];
    for (const key in exports.minecraftColorCodes) {
        const value = exports.minecraftColorCodes[key];
        if (key.length === 1 && value === hexColor)
            return key;
    }
}
exports.colorCodeFromName = colorCodeFromName;