# pack

> lightweight rectangle packer

Latest version **2.2.0** (published 2018-12-16) · MIT license · 0 weekly downloads

## Install

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

## 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.2.0 |
| Published | 2018-12-16 |
| First published | 2010-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Author | semibran |
| Maintainers | semibran |
| Keywords | rectangle packing, bin packing, combinatorial optimization |

## Links

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

## Recent versions

- 2.2.0 (latest) — 2018-12-16
- 2.1.0 — 2018-01-31
- 2.0.0 — 2018-01-30
- 1.2.0 — 2018-01-08
- 1.1.2 — 2018-01-04
- 1.1.1 — 2018-01-03
- 1.1.0 — 2018-01-03
- 1.0.0 — 2018-01-02
- 0.2.8 — 2014-12-04
- 0.2.7 — 2011-04-28
- 0.2.6 — 2011-04-28
- 0.2.5 — 2011-04-28
- 0.2.4 — 2011-01-04
- 0.2.3 — 2010-12-21
- 0.2.2 — 2010-12-21
- … 6 more at https://npm.io/package/pack/versions

## README

# pack
> lightweight rectangle packer

[View the demo!](https://semibran.github.io/pack)

![boxes](img/boxes.png)

`pack` is a [box packing algorithm](https://en.wikipedia.org/wiki/Bin_packing_problem) which attempts to determine the most compact configuration for a set of rectangles. To this end, it employs the first-fit decreasing (FFD) algorithm to place the boxes, using the length of the layout's shortest side length as a heuristic.

Unlike traditional bin packing algorithms, the boxes here are placed in a single container that grows appropriately as they are packed inside. This property makes it ideal for assembling spritesheets given a list of images.

## usage
[![npm](https://nodei.co/npm/pack.png?mini)](https://www.npmjs.com/package/pack "View npm package")

### `pack(sizes) -> layout`
Arranges a list of `[ width, height ]` pairs into the most compact `layout` possible. The result will be reminiscent of the following data structure:
```js
var layout = {
  size: [ 13, 8 ],
  boxes: [
    { size: [ 5, 3 ], position: [ 0, 0 ] },
    { size: [ 6, 5 ], position: [ 0, 3 ] }
    { size: [ 5, 4 ], position: [ 6, 0 ] },
    { size: [ 2, 4 ], position: [ 11, 0 ] },
    { size: [ 7, 4 ], position: [ 6, 4 ] },
    { size: [ 1, 3 ], position: [ 5, 0 ] },
  ]
}
```

## kudos
* [leo](https://github.com/leo) - for donating the package name

## license
[MIT](https://opensource.org/licenses/MIT) © [Brandon Semilla](https://git.io/semibran)

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