npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@strauteka/space-utilization

v0.1.0

Published

Empty-space tracking for 3D bin packing: split and merge the free space in a container as boxes are added, to build your own packing algorithm.

Readme

@strauteka/space-utilization

npm ci license

The hard part of a 3D bin packing algorithm is keeping track of the empty space left in a container as boxes go in. This package does that, so you can write your own packing algorithm on top. TypeScript, no dependencies, runs anywhere.

It's the space-utilization core from my master's thesis on 3D container packing, ported from the Java original, 3d-bin-space-utilization. For a ready-made algorithm built on it, see @strauteka/bin-packing.

Install

npm install @strauteka/space-utilization

The idea

  • A Bin is a container with the cargo placed so far and a list of empty spaces.
  • When you add a Cargo (a box, or a block of identical boxes) inside one of those spaces, every space it touches is split into up to six maximal spaces: left, right, front, rear, top and bottom of the cargo.
  • Maximal spaces may overlap each other, so no usable space is lost.
  • Spaces fully inside another are dropped, and neighbouring spaces are merged (see stacking settings).

Your algorithm only has to decide which space and which box, in which rotation. The core keeps the spaces correct.

Notation follows the thesis:

  • l = length, h = height (vertical), w = width.
  • A space starts at l_, h_, w_ and ends at l__, h__, w__.
  • Coordinates start at (0, 0, 0), the bottom-rear-left corner.
  • Use any unit, as long as it's the same everywhere.

Write your own algorithm

A complete greedy packer, in about 15 lines: each box goes into the lowest, rearmost space it fits in.

import { Bin, Cargo, ROTATIONS, fits, rotate, type Dim } from '@strauteka/space-utilization';

function greedy(container: Dim, boxes: { id: string; size: Dim }[]): Bin<string> {
  let bin = new Bin<string>(container);
  for (const box of boxes) {
    const spaces = [...bin.spaces].sort((a, b) => a.h_ - b.h_ || a.l_ - b.l_ || a.w_ - b.w_);
    for (const space of spaces) {
      const rotation = ROTATIONS.find((r) => fits(space, rotate(box.size, r)));
      if (rotation) {
        bin = bin.add(new Cargo(box.id, box.size, rotation, space.position));
        break;
      }
    }
  }
  return bin;
}

const bin = greedy({ l: 1000, h: 600, w: 800 }, [{ id: 'a', size: { l: 300, h: 200, w: 400 } }]);
bin.cargo; // placed cargo: position (l_, h_, w_), size, rotation, ref
bin.spaces; // empty spaces left

Bin is immutable: add returns a new bin, so you can try several moves and keep the best (backtracking, random restarts and so on). The core doesn't check for collisions: place cargo at the position of one of bin.spaces, and only where it fits.

API

| Export | What it is | |---|---| | Bin | Container with cargo, spaces, usedVolume, usedHeight; add(cargo, disableTop?) returns a new bin | | Cargo | A box, or a block of stack.l × stack.h × stack.w identical boxes, in one rotation at a position; ref is your identifier | | Space | An empty space: split, canMerge, merge, overlap, overlay, overlapSize | | ROTATIONS, UPRIGHT_ROTATIONS, rotate | The six orientations; upright ones keep the height vertical | | fits, volume, subtract | Size helpers | | DEFAULT_STACK_CONFIG, StackConfig | Merging settings, below |

Stacking settings

Pass a StackConfig to new Bin(size, config). Neighbouring empty spaces on the same level are merged, so a later box can span both. With over-stacking, a box may also overhang a narrow gap below it, which would otherwise be wasted.

| Setting | Meaning | |---|---| | narrowLength / narrowWidth | A space below counts as narrow when it's at most this long or wide | | overhangLength / overhangWidth | How far a merged space may stick out over a narrow gap | | heightTolerance | Floors whose heights differ by at most this count as level | | minSpaceSide | Drop spaces with any side at or below this. Merging is O(n²) in the number of spaces, so set this to about your smallest box side for speed | | disableMerge | Turn merging and over-stacking off |

The defaults are all 0 (exact, no over-stacking). For a shipping container in mm, the thesis used 100 for the four length/width settings, 5 for heightTolerance and 100 for minSpaceSide.

License

Apache-2.0, the same as the original Java project. See LICENSE and NOTICE.