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

spacing-guild

v1.0.0-alpha.0

Published

A collection of features for spacetraders.io

Downloads

4

Readme

Spacing Guild

GitHub package.json version

A library of useful features for SpaceTraders API


Contents


Installation

npm i spacing-guild --save


Usage

Using Navigator

import { Navigator, ITradeRoute } from "spacing-guild";

// ...

const edric: Navigator = new Navigator(locations, ship);
const route: ITradeRoute = edric.navigate();

Example result

{
  "destination": "OE-PM",
  "cargo": [
    { "good": "FUEL", "quantity": 3, "totalVolume": 3 },
    { "good": "METALS", "quantity": 10, "totalVolume": 10 },
    { "good": "DRONES", "quantity": 2, "totalVolume": 4 },
    { "good": "FUEL", "quantity": 33, "totalVolume": 33 }
  ]
}

Using Mentat

import { Mentat } from "spacing-guild";

// ...

const distance: number = Mentat.calculateLocationDistance(locationA, locationB);
const inRange: number = Mentat.validateRange(ship, range, location);

Build

npm i

npm run build


Documentation

Navigator

The Navigator class is will decide the most profitable, possible trade from the ship's current location

It will return an object with 2 properties: Destination and Cargo

  • Destination is a location type object that can be used when setting the flight plan.
  • Cargo contains all the goods that should be bought from current marketplace and in what quantities, as well as the FUEL required for the trip. These goods should then be sold at the destination's marketplace.

Navigator class takes 2 arguments

  • locations : A list of location objects to parse through
  • ship : The ship object

Once a Navigator object is created, it automatically parses the locations and sets a list of all available trades. This list will then be used in the navigate() method to narrow down the possible trades based on the method's arguments.

note: In the following table, the column Type will contain some custom interfaces. Please refer to the Interfaces typescript file for information

| Methods | Arguments | Type | Description | | ------------------- | ------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | updateLocationsData | | void | | | | locations | ILocations[] | The list of locations | | updateShipData | | void | | | | ship | IShip | The ship object | | navigate | | returns ITradeRoute | | | | params (optional) | {range: number, fuelMargin: number} | | | | | | range is a number to limit the search for trade routes | | | | | fuelMargin is a number representing a percentage (ex. 5 is 5%) to include as error margin when calculating the FUEL needed for a trip | | | strict (optional) | boolean (default false) | Default is false. If true it throws errors instead of returning void in cases where trades are impossible |

NOTES

  • If one of the profitable trades happens to be FUEL, it adds an extra entry with FUEL.
  • This should not be sold as it can be used for further traveling and save costs because it was bought in a better price.
  • If there is space left and no more available trades on destination, the remaining space will be empty.
  • Currently this only works within the ship's system. Intersystem route plotting is the future. #TODO

Mentat

The Mentat class is solely responsible for various calculations. All methods are public static and return either a number or a boolean.

note: In the following table, the column Type will contain some custom interfaces. Please refer to the Interfaces typescript file for information

| Methods | Arguments | Type | Description | | ---------------------------------- | ------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | calculateFuelToTravel | | returns number | Calculates the amount of fuel required to travel from location to destination | | | ship | IShip | | | | location | ILocation | | | | destination | ILocation | | | calculateFuelQuantity | | returns number | Calculates the remaining fuel needed to reach the quantity required for travel. Considers existing fuel in the ship. Adds extra fuel depending on the margin. | | | ship | IShip | | | | fuelToTravel | number | | | | margin | number (optional) | | | calculateDistance | | returns number | Calculates the distance between 2 points | | | ax | number | | | | ay | number | | | | bx | number | | | | by | number | | | calculateLocationDistance | | returns number | Calculates the distance between 2 locations | | | a | ILocation | | | | b | ILocation | | | calculatePricePerVolume | | returns number | Calculates the price per volume of a good. (Ex.If a unit of MACHINERY is 2 volumes and is priced at 10, then the price per volume is 5) | | | pricePerUnit | number | | | | volumePerUnit | number | | | calculateGoodProfitPerVol | | returns number | Calculates the profit per volume of a good bought in local marketplace and sold on another marketplace | | | a | IGood | | | | b | IGood | | | calculateGoodProfit | | returns number | Calculates the gross gain of selling a good | | | good | IGood | | | | amount | number | | | calculateGoodCost | | returns number | Calculates the cost of buying a good | | | good | IGood | | | | amount | number | | | calculateFuelToTravelCost | | returns number | Calculates the cost of fuel | | | amount | number | | | | unitCost | number | | | calculateCargoVolume | | returns number | Calculates the total volume of a good | | | good | IGood | | | | ship | IShip | | | calculateGoodQuantity | | returns number | Calculates the quantity of a good based on the available cargo space | | | space | number | | | | volumePerUnit | number | | | calculateProfitPerDU | | returns number | Calculates the profit per Distance Unit based on fuel cost, goods profit and distance to marketplace from the ship's position. The Profit per DU metric is used to sort the trades. The highest PpDU route is the best trade available | | | aGood | IGood | | | | bGood | IGood | | | | ship | IShip | | | | location | ILocation | | | | destination | ILocation | | | | fuelUnitCost | number | | | calculateFuelToTravelVolume | | returns number | Calculates the volume of FUEL | | | amount | number | | | calculateGoodVolume | | returns number | Calculates the volume of a good's quantity | | | amount | number | | | | good | IGood | | | calculateRemainingSpaceAfterRefuel | | returns number | Calculates the available cargo space after buying the fuel necessary for the route | | | ship | IShip | | | | fuelQuantity | number | | | validateRange | | returns boolean | Validates if a location is within the given range of the ship | | | ship | IShip | | | | range | number | | | | location | ILocation | |