This module was built as both a learning experience and a resource for anyone learning how to handle requests and create their own library. Most of my own code here is not the best, but I hope people are able to take something new away from looking through it.
This module only applies to the DataDragon API at this time. There may be a future update that implement's Riot's other API as well, but for now, that is unavailable at this time.
Install the library by running the following line in the terminal:
$ npm install @skoleosho97/ddragon
Initialize a new class below like so:
// Initialize the class.
const API = require('data-dragon-api');
const DataDragon = new API('en_US');
From here you will be able to use the library's functions and query data. All functions utilize async/await
, so data will have to be properly resolved before it can be used. For example:
// In this example, get all items with the ``Mana`` tag.
const Example = () => {
let items = await DataDragon.item.filter_by_tag('Mana');
console.log(items);
}
Example();
The API's constructor. Sets up the data the other classes will use. Click here for a list of currently supported regions.
Param | Type | Default | Description |
---|---|---|---|
region | string |
'en_US' |
Selected region the API will use. Defaults to 'en_US' if left null. |
The universal fetch function, used by class functions when requesting data.
Param | Type | Default | Description |
---|---|---|---|
endpoint | string |
N/A | Endpoint path to request data from. Set by class functions. |
base | string |
'http://ddragon.leagueoflegends.com/cdn' |
Base endpoint path. |
version | string |
'11.24.1' |
Current version of API. |
For the following classes, each share the same constructor
:
constructor(config) {
this.CONFIG = config;
}
where config
is the data set in new DataDragon()
.
Returns Promise
containing all relevant data for all champions.
Returns Promise
containing square image asset of specified champion.
Param | Type | Default | Description |
---|---|---|---|
champion_name | string |
N/A | Champion name. Case sensitive. |
Returns Promise
containing all relevant data for all items.
Returns Promise
containing square image asset of specified item.
Param | Type | Default | Description |
---|---|---|---|
item_id | string |
N/A | Item ID. |
Returns Promise
containing relevant item data, sorted by their total
price.
Param | Type | Default | Description |
---|---|---|---|
switch_case | number |
0 | Switch case for sorting. 0 : Ascending; 1 : Descending |
Returns Promise
containing relevant item data with the same tag as specified.
Valid tag names: []
Param | Type | Default | Description |
---|---|---|---|
tag_name | string |
N/A | Tag name. Case sensitive. |
Returns Promise
containing all abilities (including passive) for specified champion.
Param | Type | Default | Description |
---|---|---|---|
champion_name | string |
N/A | Champion name. Case sensitive. |