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

swgoh-stat-calc-data-builder

v2.0.7

Published

DataBuilder for the swgoh-stat-calc package

Downloads

12

Readme

swgoh-stat-calc-dataBuilder

Node package to build the 'gameData' object used by the swgoh-stat-calc package, by pulling data from the swgoh.help API.

Setup

Installation

npm install swgoh-stat-calc-dataBuilder

Initialization

Two options:

  • .fromPrefs will create an internal instance of ApiSwgohHelp.
  • .fromApiSwgohHelp will use an instance of ApiSwgohHelp that you create first.

.fromPrefs

const dataBuilder = require('swgoh-stat-calc-data-builder').fromPrefs({
  username: <swgoh.help username>,
  password: <swgoh.help password>
});
let path = __dirname + '/../statCalcData/';
dataBuilder.loadData(path).then( ... );

See the api-swgoh-help package for possible options to provide. Username and password, as shown above, are required.

.fromApiSwgohHelp

const ApiSwgohHelp = require('api-swgoh-help');
const swapi = new ApiSwgohHelp({
  username: <swgoh.help username>,
  password: <swgoh.help password>
});
const dataBuilder = require('swgoh-stat-calc-data-builder').fromApiSwgohHelp(swapi);
let path = __dirname + '/../statCalcData/';
dataBuilder.loadData(path).then( ... );

Allows you to use the same instance of ApiSwgohHelp after loading data.

Methods

  • .loadData(path)
  • .getData()
  • .getVersion()
  • .isUpdated()

async .loadData(path, expectedVersion = null)

Attempts to query swogh.help to collect the data needed and build the 'gameData' object. Will save 'gameData.json' and 'dataVersion.json' files to the given folder.

Parameters

pathString
The path to the folder where the .json files should be saved. Will also use that path to check for and cache temp files in case not all data can be aquired in one go.

expectedVersion Object | Optional
An optional version object to compare against the archived version. Should be of the same form as the object found at https://api.swgoh.help/version. If missing, the dataBuilder will query that link to retrieve version info.

Return Value

true if data was loaded successfully (either current data already found, or fresh data acquired).
false if data failed to load the newest. Stale data may have been loaded in its place in case needed.

.getData()

Returns the currently loaded 'gameData' object.

Parameters

None.

Return Value

The currently loaded 'gameData' object. Before .loadData() is called, this is an empty object. Afterwards, it may contain partial data if .loadData() is still running, and stale data if .loadData() failed. Use .isUpdated() to check the current update status.

.getVersion()

Returns the current version object. Will match the format used by swgoh.help's version endpoint here: https://api.swgoh.help/version Can be compared with their object to determine if data is fully updated.

Parameters

None.

Return Value

The current version object. Before .loadData() is called, this is undefined. It's updated to the current version of swgoh.help's API when .loadData() starts. If .loadData() fails and stale data is loaded, it should revert to the stale version info as well.

.isUpdated()

Returns the current update status.

Parameters

None.

Return Value

undefined if .loadData() has not yet been called.
true if .loadData() successfully updated.
false if .loadData() is in progress, or has failed.

Examples

Assuming this is being used in conjunction with the swgoh-stat-calc package:

const statCalculator = require('swgoh-stat-calc');
const dataBuilder = require('swgoh-stat-calc-data-builder')({
  username: process.env.SWGOH_HELP_UNAME,
  password: process.env.SWGOH_HELP_PASS
});

await databuilder.loadData(__dirname + '/../statCalcData/');
statCalculator.setGameData( dataBuilder.getData() );

If an instance of ApiSwgohHelp should be shared with the dataBuilder and your remaining code:

const ApiSwgohHelp = require('api-swgoh-help');
const swapi = new ApiSwgohHelp({
  username:process.env.SWGOH_HELP_UNAME,
  password:process.env.SWGOH_HELP_PASS
});
const statCalculator = require('swgoh-stat-calc');
const dataBuilder = require('swgoh-stat-calc-data-builder')(swapi);

await databuilder.loadData(__dirname + '/../statCalcData/');
statCalculator.setGameData( dataBuilder.getData() );