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

pubg-api-wrapper

v0.2.2

Published

JS Wrapper for PUBGAPI

Downloads

6

Readme

PUBGAPI

A simple wrapper for the PUBG API. Uses kitsu to interact with the api and transform complex responses to a more traditional format.

Installation

yarn add pubg-api-wrapper --save
npm install pubg-api-wrapper --save

Usage

Importing

The best way to use the wrapper is to import it with ES6 style syntax. I personally like to alias the package to another name for readability.

import { pubgApiWrapper as PUBG } from 'pubg-api-wrapper';

Actually using the thing

The wrapper has been written as an ES6 class. That means you get fancy stuff like constructors! So, to get an instance of this puppy, try the following:

const api = new pubgApiWrapper('a_pubg_api_token_here');

Remember, PUBG API tokens are non-expiring and non-domain attached, so keep yours super secret and never publish it where someone can access it. This wrapper is meant for use in server side javascript contexts, not client side.

Now, api is available to call any of the functions made available through the wrapper.

Check them out below:

Reference

getStatus()

Fetch the status of the API

Params:

  • none

Returns:

Status data from the PUBG API in the following format if successful:

{
    id: string,
    releasedAt: datetime,
    type: string,
    version: string
}

If the API fails, you'll get the error from the API passed through to your app. Use catch to process it.

getMatches(shard, filters, offset, limit, sort)

Fetch match objects from the API, applying filters as needed

Params:

  • shard - the shard you'd like matches from. See the PUBG API for more details
  • filters - an optional object containing key value pairs to filter the matches. You can use any of the filters from the PUBG API documentation for matches. Ex: [{"gameMode": "squad"}]
  • offset - an optional int used in paging for offseting the results to return
  • limit - an optional int used to cap the number of results returned in the request
  • sort - an optional string used to determine the order of the returned results. Check the API documentation for options: PUBG API documentation for matches

Returns:

A pretty complex array of match objects:

[
    {
        "type": string,
        "id": string,
        "links": {
            "schema": string,
            "self": string
        },
        "assets": [
            {
                "type": string,
                "id": string,
                "URL": string,
                "createdAt": datetime,
                "description": string,
                "name": string
            }
        ],
        "rosters": [
            {
                "type": string,
                "id": string,
                "participants": [
                    {
                        "type": string,
                        "id": string,
                        "actor": string,
                        "shardId": string,
                        "stats": {
                            "DBNOs": int,
                            "assists": int,
                            "boosts": int,
                            "damageDealt": int,
                            "deathType": string,
                            "headshotKills": int,
                            "heals": int,
                            "killPlace": int,
                            "killPoints": int,
                            "killPointsDelta": double,
                            "killStreaks": int,
                            "kills": int,
                            "lastKillPoints": int,
                            "lastWinPoints": int,
                            "longestKill": int,
                            "mostDamage": int,
                            "name": string,
                            "playerId": string,
                            "revives": int,
                            "rideDistance": int,
                            "roadKills": int,
                            "teamKills": int,
                            "timeSurvived": int,
                            "vehicleDestroys": int,
                            "walkDistance": double,
                            "weaponsAcquired": int,
                            "winPlace": int,
                            "winPoints": int,
                            "winPointsDelta": double
                        }
                    }
                ],
                "shardId": string,
                "stats": {
                    "rank": int,
                    "teamId": int
                },
                "won": string
            }
        ],
        "rounds": [],
        "spectators": [],
        "createdAt": datetime,
        "duration": int,
        "gameMode": string,
        "patchVersion": string,
        "shardId": string,
        "stats": null,
        "tags": null,
        "titleId": string
    }
]

getMatch(shard, id)

Fetch match object from the API by id

Params:

Returns:

A match object:

{
    "type": string,
    "id": string,
    "links": {
        "schema": string,
        "self": string
    },
    "assets": [
        {
            "type": string,
            "id": string,
            "URL": string,
            "createdAt": datetime,
            "description": string,
            "name": string
        }
    ],
    "rosters": [
        {
            "type": string,
            "id": string,
            "participants": [
                {
                    "type": string,
                    "id": string,
                    "actor": string,
                    "shardId": string,
                    "stats": {
                        "DBNOs": int,
                        "assists": int,
                        "boosts": int,
                        "damageDealt": int,
                        "deathType": string,
                        "headshotKills": int,
                        "heals": int,
                        "killPlace": int,
                        "killPoints": int,
                        "killPointsDelta": double,
                        "killStreaks": int,
                        "kills": int,
                        "lastKillPoints": int,
                        "lastWinPoints": int,
                        "longestKill": int,
                        "mostDamage": int,
                        "name": string,
                        "playerId": string,
                        "revives": int,
                        "rideDistance": int,
                        "roadKills": int,
                        "teamKills": int,
                        "timeSurvived": int,
                        "vehicleDestroys": int,
                        "walkDistance": double,
                        "weaponsAcquired": int,
                        "winPlace": int,
                        "winPoints": int,
                        "winPointsDelta": double
                    }
                }
            ],
            "shardId": string,
            "stats": {
                "rank": int,
                "teamId": int
            },
            "won": string
        }
    ],
    "rounds": [],
    "spectators": [],
    "createdAt": datetime,
    "duration": int,
    "gameMode": string,
    "patchVersion": string,
    "shardId": string,
    "stats": null,
    "tags": null,
    "titleId": string
}

Examples

Fetching all recent matches for pc-na:

import { pubgApiWrapper as PUBG } from 'pubg-api-wrapper';

const api = new PUBG('my_super_secret_token');

let matches;

api.getMatches('pc-na').then((data) => {
    matches = data;
}).catch((err) => {
    throw err;
});