# easy-fsm

> An easy-to-use finite state machine system for JavaScript/TypeScript.

Latest version **2.2.2** (published 2024-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install easy-fsm
pnpm add easy-fsm
yarn add easy-fsm
bun add easy-fsm
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.2 |
| Published | 2024-06-06 |
| First published | 2018-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | oldj |
| Maintainers | oldj |
| Keywords | fsm |

## Links

- npm: https://www.npmjs.com/package/easy-fsm
- Repository: https://github.com/oldj/easy-fsm
- Homepage: https://github.com/oldj/easy-fsm#readme
- Issues: https://github.com/oldj/easy-fsm/issues
- npm.io page: https://npm.io/package/easy-fsm

## Recent versions

- 2.2.2 (latest) — 2024-06-06
- 2.2.1 — 2024-05-26
- 2.2.0 — 2024-05-24
- 2.1.7 — 2024-05-24
- 2.1.6 — 2024-05-24
- 2.1.5 — 2024-05-24
- 2.1.4 — 2024-05-23
- 2.1.3 — 2024-05-23
- 2.1.2 — 2024-03-23
- 2.1.1 — 2024-03-23
- 2.1.0 — 2024-03-23
- 2.0.3 — 2024-03-23
- 2.0.2 — 2024-03-22
- 2.0.1 — 2024-03-22
- 2.0.0 — 2024-03-22
- … 1 more at https://npm.io/package/easy-fsm/versions

## README

# easy-fsm

An easy-to-use finite state machine system for JavaScript.

## install

```bash
npm install easy-fsm
```

## usage

```TypeScript
import EasyFSM from 'easy-fsm'

let fsm = new EasyFSM({
  initial: 'init',
  states: {
    init: {
      on: {
        loaded: 'ready'
      }
    },
    ready: {}
  }
})

console.log(fsm.getState()) // init
await fsm.fire('loaded')
console.log(fsm.getState()) // ready
```

## APIs

You can use `new EasyFSM(options)` to create a finite state machine.

- **send(event)**

Send an event on current state.

- **sendAndWait(event)**

Send an event on current state and wait for all listeners to finish.

- **canSend(event)**

Detect if the specified `event` can be sent.

- **[getter] state**

Get the current state.

- **[getter] previous_state**

Get the previous state.

- **onEnter(state, callback)**

Execute `callback` when entering `state`.

- **onLeave(state, callback)**

Execute `callback` when leaving `state`.

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