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

easyecs

v1.0.1

Published

Entity-Component-System for Javascript-ES6

Readme

EasyECS - Entity-Component-System for Javascript ES6+

Intro

EasyECS is the Entity-Component-System package, that implements all features of the modern Entity–component–system.

ECS is the architectural pattern that follows the "composition over inheritance" principle. It allows much greater readability, extensibility and loose module coupling compared to the inheritance-based object designs.

  • Entity - a collection of components that has unique id;
  • Component - plain data structure;
  • Assemblage - helper: a predefined group of components forming pseudo-entity;
  • Query - a rule that describess a selection of entities satisfying some criteria - similar to SQL query;
  • System - code logic module that runs over a set of entities selected by Query(-ies). Systems may add/remove components, or modify component data of a specific entity. Also, Systems may add entities to or remove entities from ECS.

Implementation details:

  • Written using JavaScript ES6;
  • Unlike many Javascript ECS systems, this one does not apply updates immediately, but queues them for 'after-tick' batch processing. This allows to apply Systems in parallel;
  • Implements shared Queues for efficient Entity grouping/processing;
  • Components, Assemblages, Entities, Queries are all simple structures, no classes => store in any format!
  • Implements easy serialization / deserialization of ECS state;
  • Tested to work well with older browsers if transpiled by Babel;
  • Includes basic logging library (see src/Log.js) for easier debugging;

Core concepts

ECS initialization

    import { EasyECS, System } from 'easyecs';
    let ecs = new EasyECS();

Component definitions

    let components = [
      [ 'position', { x: 0, y: 0 } ],
      [ 'speed',  { vx: 0, vy: 0 } ],
    ];
    ecs.registerComponents( components );

Assemblage definitions

NOTE: all components referred to by Assemblage must be registered with ECS first!

    let assemblages = [
      {
        name: 'moving_object',
        components: {
          position: { x: 0, y: 0 },
          speed: { vx: 0, vy: 0 },
        }
      }
    ];
    ecs.registerComponentAssemblages( assemblages );

Entity definitions

    let circle = {
      position: { x: 1, y: 1 },
      speed: { vx: 1.5, vy: 0.5 }
    };
    // ...or...
    let circle = ecs.getComponentAssemblage( "moving_object" );
    // ...or, assemblage with defaults...
    let circle = ecs.getComponentAssemblage( "moving_object", { speed: { vx: 1.5, vy: 0.5 } } );
    ecs.addEntities([ circle ]);

Query definitions

Query definition: ( name, list of component names that MUST present, list of component names that MUST NOT present, is query reactive? ); [ '', [ ''...'" ], [ '' ... '' ], true/false ]

    let queries = [
      [ 'query_movable', ['position','speed'], [] ],
      [ 'query_static', ['position'], ['speed'] ],
      [ 'query_display', [ 'position', 'display' ], [], true ]
    ];
    ecs.registerQueries( queries );

System definitions

NOTE: each System must request one or more Queries, that will provide Entity lists!

    // simple system:
    let SystemMove = new System('SystemMove')
      .on_queries(['query_movable'])
      .on_tick( function( entityManager, componentManager ) {
        this.queries.query_movable.get().forEach( entity => {
          let dx = entity.speed.x, dy = entity.speed.y;
          entityManager.update( entity, 'position', { x: dx, y: dy } );
        });
      });

    // a system that uses reactive query:
    let SystemDisplay = new System('SystemDisplay')
      .on_queries(['query_display'])
      .on_tick( function( entityManager, componentManager ) {
        // a system that intercepts insert/delete/move of entities, and acts accordingly
        if ( this.queries.query_display.is_changed() ) {
          // new entries added or old ones removed
          this.queries.query_display.entities_inserted.forEach( entity => {
            // new entity just inserted, let's add a sprite to screen here
          });
          this.queries.query_display.entities_deleted.forEach( entity => {
            // entity scheduled for removal, remove sprite from screen
          });
        }
        if ( this.queries.query_display.is_updated() ) {
          this.queries.query_display.entities_updated.forEach( ( components, entity, map ) => {
            // some entity component was updated, let's move sprite
          });
        }
      });
    ecs.registerSystems([ SystemMove, SystemDisplay ]);

Basic ECS loop

    while( 1 ) {
      await ecs.tick();
    }

ECS state save / load

    // save ECS state to JSON-encoded string:
    let json_string = ecs.serialize();
    
    // then, sometime later, restore ECS state:
    ecs.clear();
    ecs.deserialize( json_string );

How-To

Installation

EasyECS package could be installed via NPM:

    $> npm install easyecs
    

Usage

Please see "examples" directory for a tutorial(s) on EasyECS

License

EasyECS is covered under the terms of MIT License