# inventory

> item inventory management

Latest version **2.0.0** (published 2016-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install inventory
pnpm add inventory
yarn add inventory
bun add inventory
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-02-15 |
| First published | 2013-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | deathcap |
| Keywords | game, items, piles, group, itempile, itemstack, inventory |

## Links

- npm: https://www.npmjs.com/package/inventory
- Repository: https://github.com/deathcap/inventory
- Homepage: https://github.com/deathcap/inventory#readme
- Issues: https://github.com/deathcap/inventory/issues
- npm.io page: https://npm.io/package/inventory

## Dependencies (2)

- [itempile](https://npm.io/package/itempile.md) ^2.0.0
- [deep-equal](https://npm.io/package/deep-equal.md) ^1.0.0

## Recent versions

- 2.0.0 (latest) — 2016-02-15
- 1.0.0 — 2015-02-23
- 0.1.3 — 2014-06-15
- 0.1.2 — 2014-03-28
- 0.1.1 — 2014-02-25
- 0.1.0 — 2013-12-31
- 0.0.2 — 2013-12-19

## README

# inventory

Simple finite stackable item inventories (for games).

[![Build Status](https://travis-ci.org/deathcap/inventory.png)](https://travis-ci.org/deathcap/inventory)

Requires a ES6-compatible environment (tested on Node v4.2.4)

## Creation

A new inventory can be created given its desired size (number of slots):

    var Inventory = require('inventory');
    var inv = new Inventory(5);

If omitted, defaults to 10. You can pass two arguments for 2D inventory:

    new Inventory(3, 2)

creates a 3x2 = 6 slot inventory (3 columns, 2 rows). Internally it still
stored as one-dimensional, but other modules can query the dimensions
(width and height).

## Adding items

Items are added to an inventory using `give`, passing an [itempile](https://github.com/deathcap/itempile) instance:

    inv.give(new ItemPile('dirt', 42));

will add 42 dirt to `inv`, returning the quantity that could not be added if the inventory is full.
`give` first searches for existing piles and attempts to merge if possible, otherwise it will occupy an
empty slot. 

This merging algorithm can be demonstrated by repeatingly giving 42 dirt and calling `toString` to see the contents:

    42:dirt
    64:dirt	20:dirt
    64:dirt	62:dirt
    64:dirt	64:dirt	40:dirt
    etc.

The items pile up to `ItemPile.maxPileSize`, default 64. Note you can also give over-sized piles and the items
will be distributed in the inventory identically (giving e.g., 42 * 3, same as giving 42 three times).

## Removing items

Similarly, `take` removes items:

    inv.take(new ItemPile('dirt', 1));

returns a new `ItemPile` of 1 dirt, if present, and removes the same quantity from `inv`. If called on the
inventory in the above example, the new contents will be:

    63:dirt	64:dirt	40:dirt

For more examples see the unit tests.

## Displaying items

This module only manages the inventory data structure. For graphical user interfaces to the inventory, check out:

* [voxel-inventory-toolbar](https://github.com/deathcap/voxel-inventory-toolbar)
* [inventory-window](https://github.com/deathcap/inventory-window)

## License

MIT

---
_Source: https://npm.io/package/inventory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
