xwing-list-loader
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

xwing-list-loader

A simple Node module that takes squad builder URLs and returns the matching XWS JSON object.

Motivation

In several X-Wing projects I wanted to resolve a squad builder url to that squad's XWS object. I found myself copy-pasting snippets of code between projects that I later had to update every time I wanted to support a new endpoint. This wouldn't work in the long run so I created this module so I can build it once and re-use it everywhere.

Installation

Install using yarn or npm:

$ yarn add xwing-list-loader
$ npm install xwing-list-loader --save

API

load(url)

  • url A string representing the squad's URL
  • Returns: Promise<Object|False>

This method will first check if url matches any of the supported integrations. If so, it will parse the url, turn it into an URL that points to the XWS and perform a HTTP(S) request.

If valid XWS can be loaded from the given URL the promise will resolve with the XWS object.

The promise will resolve with false if:

  • The given URL does not match any of the supported integrations
  • The given URL does not return a valid XWS JSON object (= has no pilots or faction field)
  • The request to fetch the XWS was unsuccessful (a response with status code != 2xx)

The promise will be rejected if:

  • There are network/permission issues
  • The response cannot be parsed as JSON

Example:

import listLoader from 'xwing-list-loader';
 
const url =
  'https://raithos.github.io/?f=Galactic%20Republic&d=v8ZsZ200Z273XW2W201WY278XWW200WY333X123WWW&sn=Ani%2FObi%2FRic&obs=gascloud1,gascloud2,gascloud3';
 
// Using promises
listLoader.load(url).then(
  xws => {
    console.log(xws);
  },
  err => {
    console.error(err);
  }
);
 
// Using async/await
(async () => {
  try {
    const xws = await listLoader.load(url);
    console.log(xws);
  } catch (err) {
    console.error(err);
  }
})();

Supported integrations

URLs will be matched against the following endpoints (in order):

Second Edition:

  1. (Yet Another) Squad Builder 2
  2. Launch Bay Next (Android / iOS)
  3. Official FFG Squadbuilder
  4. Meta-Wing2

First Edition:

  1. (Yet Another) Squad Builder
  2. Voidstate
  3. Fab's Squadrons Generator
  4. Meta-Wing

License

MIT


Star Wars, X-Wing: The Miniatures Game and all related properties are owned by Fantasy Flight Games, Lucasfilm Ltd., and/or Disney.

Readme

Keywords

none

Package Sidebar

Install

npm i xwing-list-loader

Weekly Downloads

0

Version

3.0.0

License

MIT

Unpacked Size

50.3 kB

Total Files

61

Last publish

Collaborators

  • guidokessels