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

poro

v2.3.0

Published

Leaguepedia API & Riot League of Legends API & CommunityDragon & Data Dragon

Downloads

353

Readme

poro

  • Leaguepedia API
  • Riot League of Legends API
  • Community Dragon
  • Data Dragon

Install

npm i poro

Usage

Leaguepedia

import { CargoClient } from 'poro'

const cargo = new CargoClient()
// specify fields
const teams = await cargo.query({
  tables: ['Teams'],
  fields: ['Teams.Name', 'Teams.Region'],
})
// filter
const g2 = await cargo.query({
  tables: ['Teams'],
  where: 'Teams.Name = "G2 Esports"',
})
// join on
const broadcastMusicUsages = await cargo.query({
  tables: ['BroadcastMusicUsages', 'BroadcastMusicTracks'],
  joinOn: [
    {
      left: 'BroadcastMusicUsages.TrackID',
      right: 'BroadcastMusicTracks.TrackID',
    },
  ],
})
// group
const proplayers = await cargo.query({
  tables: ['Pentakills'],
  groupBy: ['Pentakills.Name'],
  having: 'COUNT(DateDisplay) > 10',
})

Riot

import { RiotClient, Riot } from 'poro'

const riot = new RiotClient({
  auth: 'RIOT-API-KEY',
  platform: Riot.Platform.KR,
  region: Riot.Region.ASIA,
})
const leagueEntries = await riot
  .path('/lol/league-exp/v4/entries/{queue}/{tier}/{division}', {
    queue: Riot.Queue.RANKED_SOLO_5x5,
    tier: Riot.Tier.CHALLENGER,
    division: Riot.Division.I,
  })
  .get({ query: { page: 1 } })

General Data

import { general, Riot } from 'poro'

// https://static.developer.riotgames.com/docs/lol/gameModes.json
const gameModes = await axios<Riot.General.GameModes>(general.doc('gameModes'))

// https://ddragon.leagueoflegends.com/realms/na.json
const realm = await axios<Riot.General.Realm>(general.realm('na'))

Data Dragon

import { DataDragon, Riot } from 'poro'

const ddragon = new DataDragon('11.16.1', 'en_US')

// https://ddragon.leagueoflegends.com/cdn/11.16.1/data/en_US/summoner.json
const summoner = await axios<Riot.Data.SummonerJSON>(ddragon.meta('summoner'))

Community Dragon

import { CommunityDragon, Riot } from 'poro'

const cdragon = new CommunityDragon('latest', 'default')

// https://raw.communitydragon.org/latest/plugins/rcp-fe-lol-static-assets/global/default/images/ranked-mini-regalia/challenger.png
cdragon.tier(Riot.Tier.CHALLENGER)

APIs

CargoClient and RiotClient are designed for server side and use axios to send requests.

Types are out of box, so you don't have to define them yourself.

Leaguepedia

You can get the axios instance with cargo.axiosInstance.

interface CargoClientOptions {
  // Prefix to field names starting with '_' (like '_ID', '_pageName', etc.)
  metadataPrefix?: string
}

See the parameters needed for a query in Cargo query (or API sandbox)

See all fields of a table in Cargo tables.

interface CargoQueryParameter {
  tables: Table[]
  fields?: Field[] // defaults to all fields
  where?: string
  joinOn?: JoinOn[]
  groupBy?: Field[]
  having?: string
  orderBy?: OrderBy[] // defaults to `[{ field: `${tables[0]}._pageName` }]`
  limit?: number // defaults to `Number.MAX_SAFE_INTEGER`
  offset?: number // defaults to `0`
  format?: string // defaults to 'json'
}

interface JoinOn {
  left: Field
  right: Field
}

interface OrderBy {
  field: Field
  desc?: boolean // defaults to `false`
}

Riot

You can get the axios instance with riot.axiosInstance.

interface RiotClientConfig extends LimiterConfig {
  // Riot API KEY
  auth: string
  // Instance-scoped platform
  platform?: Platform
  // Instance-scoped region
  region?: Region
}

interface LimiterConfig {
  // Concurrency for each region
  concurrency?: number
  // If `true`, display debug info.
  // If 'mock', display debug info and mock requests.
  debug?: boolean | 'mock'
}

Sometime you need method-scoped platform and region. Add it as the last parameter in path method and it will override the instance-scoped one.

riot.path(
  '/lol/summoner/v4/summoners/{encryptedSummonerId}',
  { encryptedSummonerId: '...' },
  Riot.Platform.KR,
)

Credits

The Riot API client is inspired by Building Strongly Typed REST Clients with TypeScript (repository).