@gw2efficiency/recipe-nesting
v3.2.1
Published
Nest an array of crafting recipes into a tree
Downloads
220
Readme
Installation
yarn add @gw2efficiency/recipe-nesting
If you want to calculate the price of the tree generated from this, take a look at
@gw2efficiency/recipe-calculation
.
Usage
import { nestRecipes } from '@gw2efficiency/recipe-nesting'
// Expects a list of crafting recipes in the API format. This needs to include at least
// the recipe you want to transform and all sub-recipes including guild upgrade recipes.
const 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.
const decorationsToItemsMap = {
42: 1337,
// ...
}
const nestedRecipes = nestRecipes(recipes, decorationsToItemsMap)
// -> [
// {
// "id": 13243,
// "quantity": 5,
// "output": 1,
// "components": [
// {
// "id": 19712,
// "quantity": 2,
// "output": 1,
// "components": [
// {
// "id": 19725,
// "quantity": 3
// },
// // ...
// ]
// },
// // ...
// ]
// }
// // ...
// ]
Contributors
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
License
MIT