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

spatial-hash

v0.0.4

Published

Spatial hash package for node.js

Readme

spatial-hash

spatial hash package for node.js. Forked from https://www.npmjs.com/package/spatialhash-2d

item requirements

Example of an item:

var item = {
    range: {
        x: 0,
        y: 0,
        width: 100,
        height: 150
    },
    __b: undefined
};
  • item must contain a .range object. The .range object also must have x, y, width and height variables/properties.
  • item must not have a .__b object defined.

Constructor

const SpatialHash = require('spatial-hash');
var hash = new SpatialHash(range, cellSize);

range object

An item containing x, y, width and height variables/properties. The same functionality as item.range object.

{
    x: /* X (top-left) */
    y: /* Y (top-left) */,
    width: /* width */,
    height: /* height */
}

cellSize

A number that represents the width and height of a cell in the spatial hash.

Variables

.cellSize

The second argument passed in the constructor.

.itemCount

The amount of items currently in the map.

The maximum item count is 900 000 000 000 000.

.hash

The map. See remarks for more info.

._horizontalCells

Amount of horizontal Cells in the map. See remarks for more info.

._verticalCells

Amount of vertical Cells in the map. See remarks for more info.

.cellCount

Amount of cells in the map.

Functions

.insert(item)

Inserts an item.

See item requirements that need to be met.

The maximum item count is 900 000 000 000 000.

The .insert(item) function creates a .__b item in the item.

.remove(item)

Removes an item.

The .remove(item) function will not remove items that do not have a .__b item inside them.

.removeAll()

remove all items.

.update(item)

Removes then inserts the item.

items that are moving need to be updated.

.query(rangeObj, [selector])

Searches the map for items in a specified rangeObj then returns an array of found items.

If any item is found to be intersecting the rangeObj, the class will call selector(item) if selector is provided.

If selector(item) returns false the array will not include the item.

.any(rangeObj)

Searches the map for items in a specified rangeObj.

Returns a boolean whether an item was found or not.

If any item is found to be intersecting the rangeObj, it will immediately return true. Otherwise returns false.

.find(rangeObj, [callback])

Searches the map for items in a specified rangeObj.

If any item is found to be intersecting the rangeObj, the class will call callback(item) if callback is provided.

Remarks

item.__b.id number may overlap with some other id.

This is due to the class just adding 1 to the next number. However, 1 800 000 000 000 000 item's must be added before a collision is possible.