npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

legends

v1.1.0

Published

A tiny League of Legends API library for Node.js and browsers.

Downloads

17

Readme

Legends is a very tiny (~6KB minified) League of Legends API Library for Node.js and browsers. It based on promises, making it very fast and robust. The full Riot API is available and it also includes human readable names for maps and queues.

Installation and Usage

Node.js

Install the NPM module:

$ npm install legends

Then require and use:

var legends = require("legends")("MY_SECRET_API_KEY", "na");

Browsers

Include dist/legends.js or dist/legends.min.js on your page:

<script type="text/javascript" src="legends.min.js"></script>

And use:

var legends = Legends("MY_SECRET_API_KEY", "na");

NOTE: Using this library in the browser will require you to reveal your API key to end users. This is not reccomended for obvious reasons. Check out https://developer.riotgames.com/best-practices for best practices with the API.

Example

This example uses traditional callbacks to get a summoner's ranked stats knowing only their username.

var legends = Legends("MY_SECRET_API_KEY", "na");

legends.getSummonerByName("meteos", function(err, data) {
	if (err != null) return console.error(err);

	legends.getRankedStats(data.id, function(err, stats) {
		if (err != null) console.error(err);
		else console.log(stats);
	});
});

This can also be rewritten using promises.

var legends = Legends("MY_SECRET_API_KEY", "na");

legends.getSummonerByName("meteos")
	.then(function(data) { return legends.getRankedStats(data.id); })
	.then(function(data) {
		console.log(data);
	}, function(error) {
		console.error(error);
	});

API

Constructor

new Legends( API_KEY, [ REGION ] )

Creates a new Legends instance. API_KEY is your secret api key given to you by Riot. Go to https://developer.riotgames.com/ to obtain a key. REGION is any valid region code: na, euw, eune, br, or tr. A Legend instance can also be created without using the new keyword.

Class Methods and Properties

Legends.request( [ OPTIONS ], [ CALLBACK ] )

Makes a request to the Roit API. OPTIONS is a dictionary with any of the fields listed below. CALLBACK is an optional function that is called with two arguments, error and data. Returns a promise. This method is useful for making custom API requests.

Available Options
  • method: Url method, appended to the base API url.
  • region: A valid LoL region code: na, euw, eune, br, or tr.
  • version: API version. Generally 1.1, 1.2, 2.1, or 2.2.
  • key: API Key to be prepended to the url query.
  • params: A dictionary of additional url query parameters.
  • extract: The key to extract from the returned data.

Legends.MATCH_MAKING_QUEUES

A dictionary pairing queue ids to human readable names.

Legends.MAP_NAMES

A dictionary pairing map ids to human readable names and notes.

Legends.REGIONS

An array of valid LoL region codes.

Instance Methods

legends.request( [ OPTIONS ], [ CALLBACK ] )

A shortcut for Legends.request. Defaults the options key and region to those provided to the instance when it was created.

legends.getChampions( [ FREE_TO_PLAY ], [ CALLBACK ] )

Retrieves the list of champions. FREE_TO_PLAY is a boolean. https://developer.riotgames.com/api/methods#!/311/1059

legends.getRecentGames( SUMMONER_ID, [ CALLBACK ] )

Retrieves information on the last ten games played. https://developer.riotgames.com/api/methods#!/313/1061

legends.getLeagues( SUMMONER_ID, [ CALLBACK ] )

Retrieves leagues data for summoner, including leagues for all of summoner's teams. https://developer.riotgames.com/api/methods#!/307/1055

legends.getSummaryStats( SUMMONER_ID, [ CALLBACK ] )

Retrieves player stats summaries. https://developer.riotgames.com/api/methods#!/317/1075

legends.getRankedStats( SUMMONER_ID, [ CALLBACK ] )

Retrieves player ranked stats. https://developer.riotgames.com/api/methods#!/317/1074

legends.getSummonerById( SUMMONER_ID, [ CALLBACK ] )

Retrieves basic summoner info by id. https://developer.riotgames.com/api/methods#!/315/1069

legends.getSummonerByName( NAME, [ CALLBACK ] )

Retrieves basic summoner info by name. https://developer.riotgames.com/api/methods#!/315/1067

legends.getRunes( SUMMONER_ID, [ CALLBACK ] )

Retrieves player runes pages. https://developer.riotgames.com/api/methods#!/315/1070

legends.getMasteries( SUMMONER_ID, [ CALLBACK ] )

Retrieves player mastery pages. https://developer.riotgames.com/api/methods#!/315/1071

legends.getNames( [ SUMMONER_IDS, ... ], [ CALLBACK ] )

Retrieves summoners' names by list of ids. Ids can be passed as seperate arguments, as an array of ids, or a combination of the two. Riot limits 40 summoner ids to one request. If more than 40 ids are passed, the method will automatically split it into multiple calls. https://developer.riotgames.com/api/methods#!/315/1068

legends.getTeams( SUMMONER_ID, [ CALLBACK ] )

Retrieves a summoner's teams. https://developer.riotgames.com/api/methods#!/310/1058

This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.