
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.
#Entity Component System
Simple system to create and utilize objects in the right way.
##Create objects
var factory = require('ecos').factory;
var entityFactory = factory.create({
props: ['x', 'y'],
name: 'my_entity'
});
var entity = entityFactory.create();
console.log(entity);
{
x: undefined,
y: undefined,
id: 0,
type: 'my_entity'
}
##Get objects
var objects = require('ecos').objects;
var entity = objects.get(0);
console.log(entity);
{
x: undefined,
y: undefined,
id: 0,
type: 'my_entity'
}
##Ideas behind this library
ecos.objects and accessible by its idecos.objects.get(childId);methods and extenders and inherit same behaviour without prototype inheritance##Instalation
As npm package:
npm install ecos --save
As bower package:
bower install ecos --save
##Documentation
###Factory
To create an entity first you need to create a factory that will produce entities:
var factory = require('ecos').factory;
var entityFactory = factory.create(options);
####Options:
undefined, [ string ]factory.registerMethod, [ string ]factory.registerExtender, [ string ]factory.registerPreset. [ string ]props options, { propName: propValue }props and default options, is entity with this set will be accessible through entityFactory.customEntity() call, { customEntityName: { propName: propValue } }####Create basic entity: Will create entity with fields.
var factory = require('ecos').factory;
var entityFactory = factory.create({
props: [ 'x', 'y' ],
name: 'example'
});
entityFactory.create();
Result:
{
type: 'example',
x: undefined,
y: undefined,
id: 0
}
If you pass object with fields to entity constructor then factory will create entity with specified fields defined:
entityFactory.create({x: 100, y: 200});
Result:
{
type: 'example',
x: 100,
y: 200,
id: 0
}
####Create entity with method:
Use factory.registerMethod to register method that can be assigned to entity:
factory.registerMethod('console', function(text){
console.log(text);
});
var entityFactory = factory.create({
methods: ['console'],
name: 'example'
});
entityFactory.create();
Result:
{
type: 'example',
console: function
id: 0
}
####Create entity with GETSET extender: This extender will create field with defined getter and setter.
var extenders = require('ecos').extenders;
factory.registerExtender('value-extender', {
get: function(){
return this._value;
},
set: function(val){
this._value = val;
console.log('Value set to ' + val);
},
name: 'value',
type: extenders.GETSET
});
var entityFactory = factory.create({
extend: ['value-extender'],
name: 'example'
});
entityFactory.create();
entity.value = Math.random();
Result:
Value set to 0.758898114
If you wont specify get or set function in extender definition then resulting field wont have getter or setter defined.
####Create entity with FUNCTION extender: This extender will run custom function on object creation.
factory.registerExtender('function-extender', {
type: extenders.FUNCTION,
handler: function(thisObject){
console.log('Creating ' + JSON.stringify(thisObject));
}
});
var entityFactory = factory.create({
extend: ['function-extender'],
name: 'example'
});
entityFactory.create();
Result:
Creating {"type":"example", "id":0}
FAQs
Entity Component System
The npm package ecos receives a total of 6 weekly downloads. As such, ecos popularity was classified as not popular.
We found that ecos demonstrated a not healthy version release cadence and project activity because the last version was released 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.