Issues (33)

es/mastery.js (3 issues)

1 View Code Duplication
import { getJSON, getRegion } from './utils';
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
2
var SummonerMastery = /** @class */ (function () {
3
    function SummonerMastery(APIKEY, region, summonerId) {
4
        this.summonerId = summonerId;
5
        this.APIKEY = APIKEY;
6
        this.region = region;
7
    }
8
    SummonerMastery.prototype.level = function (callback) {
9
        var url = getRegion(this.region) + "/lol/champion-mastery/v3/scores/by-summoner/"
10
            + (this.summonerId + "?api_key=" + this.APIKEY);
11
        getJSON(url, function (res, err) {
12
            if (err) {
13
                callback(null, err);
14
            }
15
            else {
16
                callback(res.data);
17
            }
18
        });
19
    };
20
    SummonerMastery.prototype.points = function (callback) {
21
        var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
22
            + (this.summonerId + "?api_key=" + this.APIKEY);
23
        getJSON(url, function (res) {
24
            var points = 0;
25
            res.data.forEach(function (champion) {
26
                points += champion.championPoints;
27
            });
28
            callback(points);
29
        });
30
    };
31
    SummonerMastery.prototype.top = function (amount, callback) {
32
        if (amount === void 0) { amount = 0; }
0 ignored issues
show
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
33
        var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
34
            + (this.summonerId + "?api_key=" + this.APIKEY);
35
        getJSON(url, function (res) {
36
            var slice = amount === 0 ? res.data.length : amount;
37
            callback(res.data.slice(0, slice));
38
        });
39
    };
40
    SummonerMastery.prototype.champion = function (champion, callback) {
41
        if (Array.isArray(champion)) {
42
            var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
43
                + (this.summonerId + "?api_key=" + this.APIKEY);
44
            var returner_1 = [];
45
            getJSON(url, function (res) {
46
                res.data.forEach(function (element) {
47
                    if (champion.indexOf(element.championId) !== -1) {
48
                        returner_1.push(element);
49
                    }
50
                });
51
                callback(returner_1);
52
            });
53
        }
54
        else {
55
            var url = getRegion(this.region) + "/lol/champion-mastery/v3/champion-masteries/by-summoner/"
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable url already seems to be declared on line 42. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
56
                + (this.summonerId + "/by-champion/" + champion + "?api_key=" + this.APIKEY);
57
            getJSON(url, function (res, err) {
58
                if (err) {
59
                    callback(null, err);
60
                }
61
                else {
62
                    callback(res.data);
63
                }
64
            });
65
        }
66
    };
67
    return SummonerMastery;
68
}());
69
export { SummonerMastery };
70
//# sourceMappingURL=mastery.js.map