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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bytenecs

v1.0.0

Published

Efficient entity component system (ECS) focused on networking / online game development in TypeScript

Readme

bytenecs

Networking focused entity component system (ECS) for TypeScript.

Features

  • Optimized for networking with serialization
  • First class TypeScript support
  • Cached queries
  • Typed components with ArrayBuffer support
  • Enter/Exit query support
  • Change detection
  • 0 dependencies

Installation

npm install bytenecs

Quick Start

import {
  createWorld,
  defineComponent,
  addEntity,
  addComponent,
  Types,
} from "bytenecs";
// Create a world where entities are stored and queries are run
const world = createWorld("game");

// Define components, the first argument is the name of the component which is used for serialization
const Position = defineComponent("position", {
  x: Types.f32,
  y: Types.f32,
});
const Velocity = defineComponent("velocity", {
  x: Types.f32,
  y: Types.f32,
});
// Register components
registerComponents(world, [Position, Velocity]);

// Create an entity
const player = addEntity(world);

// Add registered components to entity
addComponent(world, Position, player);
addComponent(world, Velocity, player);

// Set component values
Position.x[player] = 100;
Position.y[player] = 200;
Velocity.x[player] = 5;
Velocity.y[player] = 10;

Core Concepts

Components

Components are defined using defineComponent with a schema that specifies the type of each field:

const Position = defineComponent("position", {
  x: Types.f32,
  y: Types.f32,
});

// Array types are also supported
const Inventory = defineComponent("inventory", {
  items: [Types.ui8, 10], // Array of 10 uint8 values
});

Available types:

  • i8, i16, i32 - Signed integers
  • ui8, ui16, ui32 - Unsigned integers
  • f32, f64 - Floating point numbers

Queries

Query entities based on their components:

import { defineQuery, Not, Changed } from "bytenecs";

// Query entities with both Position and Velocity
const movingEntities = defineQuery(Position, Velocity);

// Query entities with Position but without Velocity
const staticEntities = defineQuery(Position, Not(Velocity));

// Query entities with changed Position values
const changedPositions = defineQuery(Changed(Position));

// Use queries
const entities = movingEntities(world);

Enter/Exit Queries

Track when entities enter or leave a query:

const query = defineQuery(Position, Velocity);
const enterQuery = enterQuery(query);
const exitQuery = exitQuery(query);

function gameLoop() {
  const newEntities = enterQuery(world); // Entities that just matched the query
  const removedEntities = exitQuery(world); // Entities that no longer match

  const currentEntities = query(world); // All current matching entities
}

Networking & Serialization

Serialize and deserialize entities for networking:

// Serialize a single entity
const data = serializeEntity(world, entityId);

// Deserialize entity data
deserializeEntity(world, data);

// Create custom serializers for specific components
const serializePosition = defineSerializer([Position]);
const deserializePosition = defineDeserializer([Position]);

// Serialize multiple entities
const data = serializePosition(world, entities);
deserializePosition(world, data); // this will deserialize the entities into the world

const serialized = serialize(world, entity);
const deserialized = deserialize(world, serialized);

Systems

Systems are pure functions that operate on entities:

import { defineSystem } from "bytenecs";
const movementSystem = defineSystem((state) => {
  const entities = movingEntities(world);
  for (const eid of entities) {
    Position.x[eid] += Velocity.x[eid];
    Position.y[eid] += Velocity.y[eid];
  }
  return state;
});

Performance

  • Uses TypedArrays for component storage
  • Query caching
  • Optimized for bulk operations
  • Maximum 3000 entities per world

License

MIT