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

galeforce

v0.6.1

Published

A customizable, promise-based, and command-oriented TypeScript library for the Riot Games API.

Downloads

17

Readme

Galeforce


NPM

npm Node CI CodeQL Codacy Badge codecov shields.io dependencies GitHub last commit

A customizable, promise-based, and command-oriented TypeScript library and fluent interface for the Riot Games API.

Features

  • Full API support for all Riot games, Data Dragon (LoL and LoR), and the Live Client Data API
    • Environment variable config integration for API keys and other values on both the desktop and platforms including Heroku
  • Customizable rate limiting with Redis clustering support and automated retries
  • Fully-typed DTOs and parameters for all endpoints
  • Fluent interface for seamless method chaining
  • Built-in, informative debugging using debug

Automatically-generated documentation is available here, and code examples can be found the section below.

Table of Contents


Examples

If you're using ES6/TypeScript, simply add

import GaleforceModule from 'galeforce';

const galeforce = new GaleforceModule(/* config */);

to use the library. Or, if you're using CommonJS and require(), add Galeforce to your project like this:

const GaleforceModule = require('galeforce');

const galeforce = new GaleforceModule(/* config */);
const summoners = ['a', 'b', 'c'];
const promises = summoners.map(summoner => galeforce.lol.summoner()
  .region(galeforce.region.lol.NORTH_AMERICA)
  .name(summoner)
  .exec()
); // list of request promises
Promise.all(promises).then((result) => {
  console.log(result); // [{ name: 'a', ... }, ...]
});
const matchIds = await galeforce.lol.match.list()
  .region(galeforce.region.riot.AMERICAS)
  .puuid(puuid)
  .exec();
const matchData = await galeforce.lol.match.match()
  .region(galeforce.region.riot.AMERICAS)
  .matchId(matchId)
  .exec();
const totalMasteryPoints = (await galeforce.lol.mastery.list()
  .region(galeforce.region.lol.NORTH_AMERICA)
  .summonerId(summonerId)
  .exec())
  .reduce((previous, current) => previous + current.championPoints, 0);

Guide

Actions

Each endpoint in the Galeforce library is an instance of an Action containing the following methods:

Executes the Action with the parameters set by methods such as .region(), .summonerId(), etc., returning a Promise.

Example

/* Gets Valorant platform and status data. */
galeforce.val.status() // Target the /val/status/v1/platform-data endpoint
  .region(galeforce.region.val.NORTH_AMERICA) // See below for documentation.
  .exec() // Sends a Valorant server status request to the val-status-v1 endpoint
  .then((data) => { // Use the returned data
    /* manipulate status data */
  });

Returns the endpoint URL associated with the Action and its previously-set parameters.

Example

/* Gets the Data Dragon URL associated with the Galeforce icon. */
const galeforceURL = galeforce.lol.ddragon.item.art() // Fetch item icon art from Data Dragon
  .version('11.9.1') // See the .<property>() section for documentation. Sets the version to retrieve data from.
  .assetId(6671) // See below for documentation. Get the icon for the Galeforce item.
  .URL(); // Get the encoded URL corresponding with the selected endpoint as a string.

console.log(galeforceURL); // 'https://ddragon.leagueoflegends.com/cdn/11.9.1/img/item/6671.png'

Sets the property (region, summonerId, puuid, etc.) in the Action request payload. Different methods are exposed for each endpoint depending on the required path, query, and body parameters.

Example

/* Gets current game info for a specific summonerId. */
const currentGameInfo = await galeforce.lol.spectator.active() // Target the /lol/spectator/v4/active-games/by-summoner/{summonerId} endpoint
  .region(galeforce.region.lol.NORTH_AMERICA) // Sets the request region to 'na1' (i.e., target the NA server)
  .summonerId('summonerId') // Sets the request summonerId to 'summonerId'
  .exec(); // See .exec() above.

.<property>() methods may only be called once and are removed from the Action after being used.

/* Gets current game info for a specific summonerId. */
const currentGameInfo = await galeforce.lol.spectator.active() // Target the /lol/spectator/v4/active-games/by-summoner/{summonerId} endpoint
  .region(galeforce.region.lol.NORTH_AMERICA) // Sets the request region to 'na1' (i.e., target the NA server)
  .region(galeforce.region.lol.KOREA) // galeforce.lol.spectator.active(...).region(...).region is not a function

Sets multiple properties (region, summonerId, puuid, etc.) in the Action request payload simultaneously.

Example

/* Gets league entries for a given Teamfight Tactics ranked league. */
const TFTLeagueInfo = await galeforce.tft.league.entries() // Target the /tft/league/v1/entries/{tier}/{division} endpoint
  .set({ // Set multiple Action payload properties simultaneously
    region: galeforce.region.lol.NORTH_AMERICA, // Sets the request region to 'na1' (i.e., target the NA server)
    tier: galeforce.tier.DIAMOND, // Sets the request tier to 'DIAMOND' (i.e., search for players in Diamond)
    division: galeforce.division.IV, // Sets the request division to 'IV' (i.e., search for players in division IV of their tier)
  })
  .exec(); // See .exec() above.

Using DTOs

Galeforce includes DTOs for all Riot API responses as TypeScript interfaces. Although all actions already return an object typed with the corresponding DTO, these can be accessed explicitly via GaleforceModule.dto or as another export:

import GaleforceModule from 'galeforce';

const summonerData: GaleforceModule.dto.SummonerDTO = ... 
// get summoner data
import GaleforceModule, { dto } from 'galeforce';

const summonerData: dto.SummonerDTO = ...
// get summoner data

Config structure

When initializing Galeforce, a config object (JSON) or a path to a YAML file may optionally be passed to the GaleforceModule() constructor as an argument:

const galeforce = new GaleforceModule(/* optional config file path or object */);

Omitting the config will prevent Galeforce from being able to interface with the Riot Games API (as no API key will be specified), although Data Dragon and the Live Client Data API will still be available.

Template string-like values (such as ${RIOT_KEY}) will be evaluated using environment variables in process.env. The configuration file may contain any of the following structure (all top-level fields are optional):

riot-api:
  key: 'RGAPI-???' # (string) Your Riot API key from https://developer.riotgames.com
rate-limit:
  type: 'bottleneck' # (string) The type of rate limiter Galeforce should use ('bottleneck', 'null')
  cache:
    type: ${CACHE_TYPE} # (string) What kind of cache to use ('redis', 'internal')
    uri: ${CACHE_URI} # (string) The cache URI to connect to (required for 'redis' cache)
    key-id: 'galeforce' # (string) The key ID to use for rate-limiting keys in the Redis cache
  options:
    intervals: # (key <seconds>: value <number of requests>) Manually-set local rate limits, applied per region
      120: 100
      1: 20
    max-concurrent: null # (null | number) The maximum number of concurrent requests allowed. Setting to null allows unlimited concurrent requests.
    min-time: 0 # (number) The minimum amount of time between consecutive requests
    retry-count-after-429: 3 # (number) The number of retry attempts after an HTTP 429 error is received, delayed by response header
debug: [] # A list containing any of 'action', 'payload', 'rate-limit', 'riot-api', '*' (all)

Documentation

See here for further documentation and a complete list of methods.


Disclaimer

Galeforce isn't endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially involved in producing or managing League of Legends. League of Legends and Riot Games are trademarks or registered trademarks of Riot Games, Inc. League of Legends © Riot Games, Inc.