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

objecs

v0.1.2

Published

ECS

Readme

objECS

A lightweight, type-safe Entity Component System (ECS) for TypeScript game development.

npm version npm downloads

Features

  • Simple API - Entities are plain JavaScript objects, components are just properties
  • Type-safe - Full TypeScript support with inferred types for queries
  • Zero dependencies
  • Small footprint - ~2KB minified
  • Archetype-based queries - Efficient entity filtering with component matching
  • Reactive archetypes - Queries automatically update when entities change

Live Demos

Check out the demo site featuring several example games and simulations, including a full shoot-em-up game.

View demo source code

Installation

npm install objecs

Quick Start

import { World } from "objecs";

// 1. Define your entity type with all possible components
type Entity = {
	position?: { x: number; y: number };
	velocity?: { x: number; y: number };
	health?: number;
	player?: true;
	enemy?: true;
};

// 2. Create a world
const world = new World<Entity>();

// 3. Create entities with components
const player = world.createEntity({
	position: { x: 100, y: 100 },
	velocity: { x: 0, y: 0 },
	health: 100,
	player: true,
});

world.createEntity({
	position: { x: 200, y: 50 },
	velocity: { x: -50, y: 0 },
	health: 30,
	enemy: true,
});

// 4. Create archetypes (queries) to filter entities
const movables = world.archetype("position", "velocity");
const enemies = world.archetype("position", "health", "enemy");

// 5. Use archetypes in your systems
function movementSystem(dt: number) {
	for (const entity of movables.entities) {
		// TypeScript knows entity has position and velocity
		entity.position.x += entity.velocity.x * dt;
		entity.position.y += entity.velocity.y * dt;
	}
}

API Reference

World

The container for all entities and archetypes.

const world = new World<Entity>();

world.createEntity(components?)

Creates a new entity, optionally with initial components.

const entity = world.createEntity({
	position: { x: 0, y: 0 },
	sprite: { texture: "player.png" },
});

world.deleteEntity(entity)

Removes an entity from the world and all archetypes.

world.deleteEntity(entity);

world.archetype(...components)

Creates an archetype query that matches entities with all specified components. The returned archetype's entities set automatically stays in sync as entities are added/removed/modified.

const renderables = world.archetype("position", "sprite");

for (const entity of renderables.entities) {
	// entity.position and entity.sprite are guaranteed to exist
}

world.addEntityComponents(entity, component, value)

Adds a component to an existing entity.

world.addEntityComponents(entity, "velocity", { x: 10, y: 0 });

world.removeEntityComponents(entity, ...components)

Removes components from an entity.

world.removeEntityComponents(entity, "velocity", "acceleration");

Archetype

Archetypes are queries that match entities with specific components.

archetype.entities

A ReadonlySet of entities matching the archetype.

archetype.without(...components)

Creates a new archetype that excludes entities with certain components.

// Get all enemies that are NOT invulnerable
const vulnerableEnemies = world
	.archetype("position", "health", "enemy")
	.without("invulnerable");

Patterns

Systems as Functions

objECS doesn't prescribe how to structure systems. A simple pattern is factory functions:

function createMovementSystem(world: World<Entity>) {
	const movables = world.archetype("position", "velocity");

	return function movementSystem(dt: number) {
		for (const entity of movables.entities) {
			entity.position.x += entity.velocity.x * dt;
			entity.position.y += entity.velocity.y * dt;
		}
	};
}

// Usage
const movementSystem = createMovementSystem(world);

function gameLoop(dt: number) {
	movementSystem(dt);
	// ... other systems
}

Component Tags

Use true as a component value for tag components:

type Entity = {
	player?: true;
	enemy?: true;
	invulnerable?: true;
};

world.createEntity({ player: true, invulnerable: true });

Acknowledgments

Inspired by miniplex.

License

MIT