
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
An entity component system library for JavaScript.
ecs) or create isolated EntityMap managers, providing get, set, remove and more api functions.npm install --save ecsjs
<script type="application/javascript" src="./some-path/ecs.js"></script>
<script>
// define a component
class Position {
constructor(x, y) {
this.x = x
this.y = y
}
}
// register the component
ecs.register(Position)
// create an entity
const entityId = ecs.getNextId()
// add or update the entity data
ecs.set(entityId, new Position(25, 25))
</script>
import { ecs } from 'ecsjs'
// define a component
class Position {
constructor(x, y) {
this.x = x
this.y = y
}
}
// register the component
ecs.register(Position)
// create an entity
const entityId = ecs.getNextId()
// add or update the entity data
ecs.set(entityId, new Position(25, 25))
The primary interface for managing entities and components is the EntityMap class. A global instance ecs is exported for convenience, but you can also create your own instances.
Full Api Reference Documentation
ecs.register(...ComponentClasses)Registers one or more component classes. Components must be registered before they can be used with an entity.
ComponentTypeKeyMissing if a class name is missing (e.g., anonymous classes).ComponentAlreadyRegistered if a class is already registered.ecs.register(Position, Velocity)ecs.getNextId()Generates a unique entity identifier (a simple number). It reclaims IDs from destroyed entities when possible.
numberecs.set(entityId, ...componentInstances)Adds or updates one or more component instances for a specific entity.
ecs.set(entityId, new Position(10, 20))ecs.getMap(ComponentClass)Returns the underlying ComponentMap for a specific component class.
ComponentMap<T> | undefinedecs.get(entityId, ...ComponentClasses)Retrieves component data for an entity.
ecs.firstKey(KeyComponent, ...RelatedComponents)Returns the entity ID for the first entity that matches the KeyComponent. If related components are provided, returns [id, ...relatedData].
ecs.firstValue(KeyComponent, ...RelatedComponents)Returns the component data for the first entity that matches the KeyComponent.
const [player, pos] = ecs.firstValue(Player, Position) ?? []ecs.firstEntry(KeyComponent, ...RelatedComponents)Similar to firstValue, but also returns the entityId as the first element in the array.
const [id, player, pos] = ecs.firstEntry(Player, Position) ?? []ecs.firstEntity(KeyComponent)Returns an array of all components for the first entity associated with the KeyComponent.
ecs.entityValues(KeyComponent)Returns an array of component arrays (all data) for every entity associated with the KeyComponent.
ecs.has(entityId, ComponentClass)Checks if an entity has a specific component.
ComponentNotRegistered if the component class is not registered.booleanecs.hasAll(entityId, ...ComponentClasses)Checks if an entity has all of the specified components.
ComponentNotRegistered if any of the component classes are not registered.ecs.hasAny(entityId, ...ComponentClasses)Checks if an entity has at least one of the specified components.
ComponentNotRegistered if any of the component classes are not registered.ecs.remove(entityId, ...ComponentClasses)Removes one or more components from an entity.
ecs.destroyEntity(...entityIds)Removes all components from the specified entities and reclaims their IDs for future use.
ecs.clearComponents()Removes all entity data and reclaims all IDs, but keeps the registered component classes.
ecs.clear()Resets everything, including removing all registered component classes.
ecs.iterator(KeyComponent, ...RelatedComponents)Returns an iterator for entities matching the KeyComponent.
for (const [id, pos, vel] of ecs.iterator(Position, Velocity)) {
// process
}
ecs.query(KeyComponent, ...RelatedComponents)Creates a reusable query for entities that possess at least the KeyComponent.
ComponentQuery object that can be iterated or used to fetch specific results.ecs.printTable(components?, properties?)Prints component maps to the console in a tabular format for debugging.
ecs.printEntity(entityId, properties?)Prints all component data for a specific entity to the console in a tabular format.
EntityMap.parse(json) (static)Restores an EntityMap instance from a JSON string.
EntityMap.createWithTracing(funcFilter?) (static)Creates a new EntityMap wrapped in a Proxy that logs all method calls to the console for debugging.
Licensed under GNU GPL v3
Copyright © 2013+ contributors
FAQs
An entity component system library for JavaScript
The npm package ecsjs receives a total of 147 weekly downloads. As such, ecsjs popularity was classified as not popular.
We found that ecsjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.