Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gw2efficiency/recipe-nesting

Nest an array of crafting recipes into a tree.
https://github.com/gw2efficiency/recipe-nesting

maintained npm-package

Last synced: about 2 months ago
JSON representation

Nest an array of crafting recipes into a tree.

Awesome Lists containing this project

README

        


recipe-nesting


Nest an array of crafting recipes into a tree.



Package Version


Build Status


Code Coverage



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


Installation β€’
Usage β€’
Contributors β€’
License


## Installation

```bash
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`](https://github.com/gw2efficiency/recipe-calculation).

## Usage

```ts
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](https://allcontributors.org/docs/en/emoji-key)):



David Reeß

πŸ’» πŸ“– ⚠️

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!

## License

MIT