# micro-ecs

> A small ECS framework, with focus on TypeScript

Latest version **0.3.0** (published 2019-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install micro-ecs
pnpm add micro-ecs
yarn add micro-ecs
bun add micro-ecs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2019-04-30 |
| First published | 2019-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Lúcás Meier |
| Maintainers | cronokirby |
| Keywords | gamedev, ecs, typescript |

## Links

- npm: https://www.npmjs.com/package/micro-ecs
- Repository: https://github.com/cronokirby/micro-ecs
- Homepage: https://github.com/cronokirby/micro-ecs#readme
- Issues: https://github.com/cronokirby/micro-ecs/issues
- npm.io page: https://npm.io/package/micro-ecs

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2019-04-30
- 0.2.0 — 2019-04-30
- 0.1.0 — 2019-04-28

## README

# micro-ecs
A small ECS framework that works best with TypeScript.

I made this for a game I'm making.

## Testing
The unit tests for the project can be run with `npm run test`.

## Example Usages
First, let's set up the world and Model we'll be using:

```ts
interface Model {
    name: string,
    age: number
}

const world = new World<Model>();
const baseQuery = query<Model>();
```

### Adding entities
```ts
world.addEntities(
    {name: 'john'},
    {age: 10},
    {name: 'both', age: 20}
);
```

### Selecting all entities with certain keys
```ts
const nameAndAge = baseQuery.select('name', 'age').forEach(console.log);
world.run(nameAndAge);
```

### Selecting on certain keys and then filtering
```ts
const namedAdults = baseQuery
    .select('name', 'age')
    .filter(x => x.age >= 18)
    .forEach(console.log);
world.run(namedAdults);
```

### Selecting just the first matching item
```ts
const firstAdult = baseQuery
    .select('age')
    .filter(x => x.age >= 18) 
    .first()
    .forEach(console.log);
world.run(namedAdults);
```

### Deleting a key from all entities
```ts
const deleteAge = baseQuery.select('age').map(_ => {age: undefined});
world.run(deleteAge);
```

### Deleting all entities
```ts
const deleteAll = baseQuery.select().map(_ => undefined);
world.run(deleteAll);
```

---
_Source: https://npm.io/package/micro-ecs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
