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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fennecs

v0.0.6

Published

Lazy ECS library

Downloads

6

Readme

Fennecs

🦊 A lazy ECS library

Setup

yarn add fennecs

Basic usage

import { createWorld, Entity } from fennecs
import { LazinessComponent, napSystem } from './below'

const world = createWorld()

world
  .createEntity()
  .addComponent(new LazinessComponent(3))

world.addSystem([LazinessComponent], napSystem);

// game loop...
world.update(1)
world.update(1)
world.update(1)

Components are basic constructors:

class LazinessComponent {
  time
  constructor(n: number) {
    this.time = n
  }
}

Systems are functions that take an array of Entities and the time since the last update:

function napSystem(entities: Entity[], dt: number) {
  entities.forEach((ent: Entity) => {
    const laziness = ent.getComponent(LazinessComponent)
    laziness.time -= dt
    if (laziness.time <= 0) {
      ent.removeComponent(LazinessComponent)
      console.log('Woke up!')
    }
  })
}

API

Fennecs exports a single named export createWorld() that creates a new World to place your entities and systems in.

World

world.createEntity(fn?)

Creates and adds a new Entity to the world. If a initialiser is passed, it will be called with the new entity to allow for very basic assemblage creation.

world.createFamily(filter[])

Creates and adds (or retrieves a cached version of) an Entity Family to the world. Takes an array of Component constructors to use as a filter, and returns a Family object that automatically keeps track of matching entities.

world.addSystem(filter[], fn)

Adds a System to the world. Takes an array of Component constructors to use as a filter, and a callback function that receives the array of matching entities and the time since the last update.

world.addGlobalSystem(fn)

Adds a global System to the world. This runs every world update like regular systems, but does not receive any entities to operate on.

world.getSystems(name?)

Returns all registered systems. Optionally takes a tag name to filter by.

world.update(dt)

Update the world for one step. This triggers all Systems to update. The first argument is the time since that last update.

world.on(name, fn)

Listens for events.

world.emit(name, ...data)

Emits a new event.

Entity

entity.addComponent(componentInstance)

Adds a component to the entity.

entity.addTag(name)

Adds a tag to the entity. Basically a component without any data.

entity.removeComponent(component)

Removes the component from the entity.

entity.removeTag(name)

Removes the tag from the entity.

entity.hasComponent(component)

Returns whether the entity has the component.

entity.getComponent(component)

Returns the component attached to the entity.

entity.hasTag(name)

Returns whether the entity has the tag.

entity.on(name, fn)

Listens for events. Alias for world.on.

entity.emit(name, ...data)

Emits a new event. Alias for world.emit.

entity.destroy()

Destroys the entity from the world.

Family

family.getSize()

Returns the number of matching entities in the Family.

family.getEntities()

Returns all matching entities (updates automatically when Entities or Components are added or removed).

family.destroy()

Destroys the Family so Entities are no longer being tracked and matched against it.

System

system.tag(name)

Adds a tag to the system.

system.destroy()

Permanently removes the system from the world.

system.pause()

Pause execution of the system.

system.resume()

Resume execution of the system.