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

@byloth/micro-ecs

v1.0.29

Published

A simple & lightweight ECS (Entity Component System) library for JavaScript and TypeScript. ๐Ÿ•น

Downloads

157

Readme

ฮผECS ๐Ÿ•น

NPM Version Codecov NPM release GPR release NPM Downloads License

A simple & lightweight ECS (Entity Component System) library for JavaScript and TypeScript.


Overview

ฮผECS (micro-ecs) is a headless library, completely agnostic to any graphics or rendering library.

Traditional ECS architectures excel in low-level contexts with direct memory control (C++, Rust, etc.).
JavaScript doesn't offer this level of control, so ฮผECS takes a pragmatic approach: it brings only the ECS benefits that translate well to a high-level environment, leaving behind optimizations that would require direct memory management.

Design Philosophy

The library is built on three pillars:

  • DX-first: Developer Experience is prioritized over raw performance.
    The library doesn't use TypedArrays which would be faster but significantly hurt ergonomics.
    A pleasant API is more valuable than squeezing out every microsecond.
  • Familiarity: The API should feel natural to any JavaScript developer.
    This means using recognizable patterns: ES6 classes, getters/setters, pub/sub events, and typical OOP idioms common in the JS ecosystem.
  • Speed over Memory: When trade-offs are necessary, execution speed is preferred over memory consumption.
    Using extra memory is acceptable if it yields performance benefits at runtime.

Features

  • World โ€” Central container managing Entities, Systems, Resources, and Services
  • Entity โ€” Container for Components, can be enabled/disabled
  • Component โ€” Data attached to Entities, with independent enable/disable
  • System โ€” Logic operating on entities/components, with priority-based execution
  • Resource โ€” Singleton data shared across the world
  • Service โ€” A System that can be used as a Resource dependency
  • QueryManager โ€” Efficient component queries with cached views
  • QueryView โ€” Cached, auto-updating view of entities matching a query
  • Contexts โ€” Dependency injection for Systems (WorldContext) and Components (EntityContext)
  • Events โ€” Built-in pub/sub system via Publisher

Installation

# npm
npm install @byloth/micro-ecs @byloth/core

# pnpm
pnpm add @byloth/micro-ecs @byloth/core

# yarn
yarn add @byloth/micro-ecs @byloth/core

# bun
bun add @byloth/micro-ecs @byloth/core

Note: This library requires @byloth/core as a peer dependency.


Quick Start

import { World, Entity, Component, System } from "@byloth/micro-ecs";
import type { ReadonlyQueryView } from "@byloth/micro-ecs";

// Define Components
class Position extends Component {
  public x = 0;
  public y = 0;
}
class Velocity extends Component {
  public vx = 0;
  public vy = 0;
}

// Define a System
class MovementSystem extends System {
  private view?: ReadonlyQueryView<[Position, Velocity]>;

  public override onAttach(world: World): void {
    this.view = world.getComponentView(Position, Velocity);
  }
  public override update(deltaTime: number): void {

    for (const [position, velocity] of this.view!.components) {
      position.x += velocity.vx * deltaTime;
      position.y += velocity.vy * deltaTime;
    }
  }
}

// Create the World
const world = new World();

// Add Systems and Entities
world.addSystem(new MovementSystem());

const entity = new Entity();
entity.addComponent(new Position());
entity.addComponent(new Velocity());
world.addEntity(entity);

// Game loop
function gameLoop(deltaTime: number) {
  world.update(deltaTime);
}

Architecture

Core Classes

Component   โ€” Data attached to Entities (standalone class)
Resource    โ€” Singleton data, attachable to World
โ”œโ”€โ”€ Entity  โ€” Container for Components
โ””โ”€โ”€ System  โ€” Logic with update(), priority, enable/disable

QueryManager

Efficiently queries entities by component types:

// Get first component of type
world.getFirstComponent(Position);

// Get first entity with all component types
world.getFirstComponents(Position, Velocity);

// Iterate all matching entities
world.findAllComponents(Position, Velocity);

// Get cached view that auto-updates
world.getComponentView(Position, Velocity);

Contexts

WorldContext โ€” Provided to Systems for:

  • Event subscription (on, once, wait, off)
  • Event emission (emit)
  • Resource dependency management (useResource, releaseResource)

EntityContext โ€” Provided to Components for:

  • Component dependency management (useComponent, releaseComponent)

Roadmap

๐Ÿ”ด Critical Implementations

Issues that block or compromise production usage.

Luckily, none at the moment.


๐ŸŸ  Known Bugs & Limitations

Known issues and current limitations to be aware of.

Inexplicably, none at the moment.


๐ŸŸก Improvements

Optimizations and refinements that improve quality and performance.

  • [ ] Automatic View garbage collection

    Implement an automatic clean-up system for QueryManager that detects and removes Views no longer referenced or used, avoiding memory accumulation over time.


๐ŸŸข Future Considerations

Ideas and possible evolutions to evaluate based on needs.

  • [ ] Object pooling

    Implement a pooling system for Entity and Component to reduce Garbage Collector pressure in scenarios with high creation/destruction frequency (e.g., particle systems, projectiles).

    โš ๏ธ Evaluate carefully: could complicate the API and go against the project's "DX-first" philosophy.

  • [ ] Archetypes

    Consider an archetype system to group entities with the same component "signature", optimizing queries.

    โš ๏ธ In a JavaScript context, the traditional benefits of archetypes (cache locality, contiguous memory) are not exploitable.
    The cached View system already present in QueryManager covers part of these advantages. Actual utility to be evaluated.


๐Ÿ”ต Nice to Have

Features that would be beneficial but are not critical.

  • [ ] Advanced Query System

    Rewrite the query system from scratch to allow users to define queries using, chaining and nesting logical operators: and, or and not.


License

Apache 2.0