Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/gw2efficiency/recipe-nesting
- Owner: gw2efficiency
- License: mit
- Created: 2016-02-29T17:37:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-19T21:00:20.000Z (5 months ago)
- Last Synced: 2024-10-12T13:35:38.526Z (2 months ago)
- Topics: maintained, npm-package
- Language: TypeScript
- Homepage:
- Size: 207 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
recipe-nesting
Nest an array of crafting recipes into a tree.
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)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!## License
MIT