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

battlefield-stats

v1.0.8

Published

A node api for collection and analysis of battlefield 1 and battlefield 4 statistics.

Downloads

464

Readme

battlefield stats (bf1, bf4)

A node api that allows you to collect, analyze, and serve battlefield 1 and battlefield 4 statistics. This fully makes use of the battlefield tracker network - https://battlefieldtracker.com/

Quick start

npm install battlefield-stats
// API_KEY from https://battlefieldtracker.com/site-api
const bf = new BattlefieldStats(API_KEY);
const params = { personaId: xxxxxxxxx, platform: bf.Platforms.PC }
// bf.Server.quickServerInfo({platform: 3}, console.log);
bf.Api.request('/Stats/BasicStats', params, responseCallback)

Getting started

Get your API Key from the battlefield tracker network here: https://battlefieldtracker.com/site-api

Install battlefield-stats using npm by running using npm install battlefield-stats

Example

npm install battlefield-stats
const BattlefieldStats = require('battlefield-stats');
const API_KEY = 'YourAPIKeyFromBfTracker' // from https://battlefieldtracker.com/site-api
const bf = new BattlefieldStats(API_KEY);

// All params mirror params listed at http://docs.trnbattlefield.apiary.io/#
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YourOriginUserName  // Or you can use personaId
}

// Proxies to all api routes found http://docs.trnbattlefield.apiary.io/#
const route = '/Stats/BasicStats';

bf.Api.request(route, params, (error, response) => {
  // response callback
  if (!error && response) {
    console.log(response);
  }
})

Usage with Express

You can use battlefield-stats-express which adds hooks and functionality to express middleware with this module.

npm install battlefield-stats-express
const express = require('express');
const battlefieldStats = require('battlefield-stats-express');
const app = express();

// Get or use your key from https://battlefieldtracker.com/site-api`
const bfs = battlefieldStats(YOUR_API_TOKEN);

app.use('/api', bfs)
app.listen(3000);

Now you can see results when you navigate to http://localhost:3000/api/Stats/DetailedStats?platform=3&displayName=Ravic

For more information see battlefield-stats-express on github.

API Documentation

This API closely follows the REST Api documentation found at http://docs.trnbattlefield.apiary.io/#

Common Parameters

All API calls require platform and either personaId or displayName, and optionally may use the game parameter.

Platform

All the requests require a platform query parameter. The following values are allowed: 1 for Xbox, 2 for PlayStation, and 3 for Origin. Alternatively, you can use Platforms.XBOX, Platforms.PS4, Platforms.PC respectively.

Personas

Each request will also need either the personaId or displayName parameter, if specified.

If you're using the displayName variable be warned that for Xbox One and PlayStation 4 the api can only retrieve data if the player has played Battlefield 4 or Hardline.

Game

Certain requests can have an optional game parameter. The default value is tunguska, which is the codename for Battlefield 1. It's possible to set this to bf4 to get data from Battlefield 4.

Platforms

This is just an enum to allow for more human readable code and is completely optional.

Platforms.XBOX: 1 Platforms.PS4: 2 Platforms.PC: 3

Api.request

A generic request can be made to obtain anything from the api, however at this time all are covered with the rest of the apis.

const route = '/Stats/CareerForOwnedGames';
const params = { platform: bf.Platforms.XBOX, personaId: xxxxxxxxx };
bf.Api.request(route, params, console.log);

The route argument may be any of the Request Routes mentioned in this documentation.

Stats

Stats.careerForOwnedGames

Parameters: platform, personaId, displayName

Request Route: /Stats/CareerForOwnedGames

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YourOriginUserName, // Or you can use personaId
}
bf.Stats.careerForOwnedGames(params, (error, response) => {
  // handle response...
})

Stats.basicStats

Parameters: platform, personaId, displayName, game

Request Route: /Stats/BasicStats

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YourOriginUserName, // Or you can use personaId
  game: 'tunguska' // default is tunguska, can be changed to bf4
}
bf.Stats.basicStats(params, (error, response) => {
  // handle response...
})

Stats.detailedStats

Parameters: platform, personaId, displayName, game

Request Route: /Stats/DetailedStats

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YourOriginUserName, // Or you can use personaId
  game: 'tunguska' // default is tunguska, can be changed to bf4
}
bf.Stats.detailedStats(params, (error, response) => {
  // handle response...
})

Progression

Progression.getCodex

Parameters: platform, game

Request Route: /Progression/GetCodex

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  game: 'tunguska' // default is tunguska, can be changed to bf4
}
bf.Progression.getCodex(params, (error, response) => {
  // handle response...
})

Progression.getFilteredCodex

Parameters: platform, personaId, displayName, game

Request Route: /Progression/GetFilteredCodex

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getFilteredCodex(params, (error, response) => {
  // handle response...
})

Progression.getKitRanksMap

Parameters: platform, personaId, displayName, game

Request Route: /Progression/GetKitRanksMap

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getKitRanksMap(params, (error, response) => {
  // handle response...
})

Progression.getMedals

Parameters: platform, personaId, displayName, game

Request Route: /Progression/GetMedals

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getMedals(params, (error, response) => {
  // handle response...
})

Progression.getVehicle

Parameters: platform, vehicleId, personaId, displayName, game

Request Route: /Progression/GetVehicle

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  vehicleId: VEHICLE_ID,
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getVehicle(params, (error, response) => {
  // handle response...
})

Progression.getVehicles

Parameters: platform, personaId, displayName, game

Request Route: /Progression/GetVehicles

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getVehicles(params, (error, response) => {
  // handle response...
})

Progression.getWeapon

Parameters: platform, weaponId, personaId, displayName, game

Request Route: /Progression/GetWeapon

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  weaponId: WEAPON_ID,
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getWeapon(params, (error, response) => {
  // handle response...
})

Progression.getWeapons

Parameters: platform, personaId, displayName, game

Request Route: /Progression/GetWeapons

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
  displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getWeapons(params, (error, response) => {
  // handle response...
})

Loadout

Loadout.getItems

Parameters: platform, game

Request Route: /Loadout/GetWeapons

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
}

bf.Loadout.getWeapons(params, (error, response) => {
  // handle response...
})

Loadout.getItemGates

Parameters: platform, game

Request Route: /Loadout/getItemGates

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PC, // also you can use XBOX or PS4
}

bf.Loadout.getItemGates(params, (error, response) => {
  // handle response...
})

Loadout.getPresets

Parameters: platform, personaId, displayName, game

Request Route: /Loadout/GetPresets

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PS4, // also you can use XBOX or PC
  displayName: YOUR_DISPLAY_NAME
}

bf.Loadout.getItemGates(params, (error, response) => {
  // handle response...
})

Loadout.getEquippedDogtags

Parameters: platform, personaId, displayName, game

Request Route: /Loadout/GetEquippedDogtags

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PS4, // also you can use XBOX or PC
  displayName: YOUR_DISPLAY_NAME
}

bf.Loadout.getEquippedDogtags(params, (error, response) => {
  // handle response...
})

Server

Server.quickServerInfo

Parameters: platform, game

Request Route: /quick-server-info

Usage:

const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
  platform: bf.Platforms.PS4, // also you can use XBOX or PS4
  game: 'tunguska' // default is tunguska, can be changed to bf4
}
bf.Server.quickServerInfo(params, (error, response) => {
  // handle response...
})