2.5.1 • Published 4 years ago

gw2e-recipe-nesting v2.5.1

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

recipe-nesting

Build Status Coverage Status

Nest an array of recipes into a tree

This is part of gw2efficiency. Please report all issues in the central repository.

Install

npm install gw2e-recipe-nesting

This module can be used for Node.js as well as browsers using Browserify. If you want to calculate the price of the tree generated from this, take a look at gw2e-recipe-calculation.

Usage

import nesting from 'gw2e-recipe-nesting'

// Expects a list of recipes in the API format
// -> https://github.com/arenanet/api-cdi/blob/master/v2/recipes.js
// This needs to include at least the recipe you want to transform
// and all sub-recipes including guild upgrade recipes
// (since we want to build a full tree).
// It is easiest to just pass in all existing recipes. ;)
let recipes = [
  {
    "type": "Refinement",
    "output_item_id": 19713,
    "output_item_count": 1,
    "min_rating": 75,
    "time_to_craft_ms": 2000,
    "disciplines": ["Artificer", "Weaponsmith", "Scribe", "Huntsman"],
    "flags": ["AutoLearned"],
    "ingredients": [{
      "item_id": 19726,
      "count": 2
    }],
    "id": 1,
    "chat_link": "[&CQEAAAA=]"
  },
  // ...
]

// This is a (optional) map of guild upgrade ids to item ids. This should only be used
// for type == Decoration, and resolves all the Basic Decorations needed for scribing
let decorations = {
  42: 1337,
  // ...
}

let nestedRecipes = nesting(recipes, decorations)
// The output is an array consisting of the following:
nestedRecipes = [
  {
    "id": 13243,
    "quantity": 5,
    "output": 1,
    "components": [
      {
        "id": 19712,
        "quantity": 2,
        "output": 1,
        "components": [
          {
            "id": 19725,
            "quantity": 3
          },
          // ...
        ]
      },
      // ...
    ]
  }
  // ...
]

Tests

npm test

Licence

MIT

2.5.0

4 years ago

2.5.1

4 years ago

2.4.3

5 years ago

2.4.2

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.3.1

10 years ago

2.3.0

10 years ago

2.2.1

10 years ago

2.1.0

10 years ago

2.0.4

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

1.0.0

10 years ago