# state-transition

> Simple state machine library

Latest version **0.0.6** (published 2018-09-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install state-transition
pnpm add state-transition
yarn add state-transition
bun add state-transition
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2018-09-26 |
| First published | 2018-08-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | kapetan |

## Links

- npm: https://www.npmjs.com/package/state-transition
- Repository: https://github.com/kapetan/state-transition
- Homepage: https://github.com/kapetan/state-transition#readme
- Issues: https://github.com/kapetan/state-transition/issues
- npm.io page: https://npm.io/package/state-transition

## Recent versions

- 0.0.6 (latest) — 2018-09-26
- 0.0.5 — 2018-08-31
- 0.0.4 — 2018-08-30
- 0.0.3 — 2018-08-29
- 0.0.2 — 2018-08-29
- 0.0.1 — 2018-08-29

## README

# state-transition

Simple state machine library.

    npm install state-transition

# Usage

First argument to the constructor is the initial state followed by the state transitions.

```javascript
var StateMachine = require('state-transition')

var sm = new StateMachine('idle', {
  start: [
    { from: 'idle', to: 'analyzing' }
  ],
  stop: [
    { from: 'analyzing', to: 'advisory', condition: () => some_condition }
  ],
  cancel: [
    { from: ['analyzing', 'advisory'], to: 'idle' }
  ],
  advisory: [
    { from: '*', to: 'advisory' }
  ]
})

sm.onEnter('analyzing', function () {
  console.log('analyzing started')
})

sm.onLeave('analyzing', function () {
  console.log('analyzing finished')
})

sm.onError(function (err) {
  console.error('error', err)
})

sm.trigger('start')
```

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