# min-state

> Simple finite state machine library for javascript

Latest version **1.2.0** (published 2016-08-24) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2016-08-24 |
| First published | 2016-08-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ftft1885 |

## Links

- npm: https://www.npmjs.com/package/min-state
- npm.io page: https://npm.io/package/min-state

## Dependencies (2)

- [min-util](https://npm.io/package/min-util.md) ^2.0.0
- [min-event](https://npm.io/package/min-event.md) ^1.2.0

## Recent versions

- 1.2.0 (latest) — 2016-08-24
- 1.1.0 — 2016-08-23
- 1.0.0 — 2016-08-23

## README

min-state
===

[![NPM version][npm-image]][npm-url]
[![Downloads][downloads-image]][downloads-url]
[![Dependency Status][david-image]][david-url]
[npm-image]: https://img.shields.io/npm/v/min-state.svg?style=flat-square
[npm-url]: https://npmjs.org/package/min-state
[downloads-image]: http://img.shields.io/npm/dm/min-state.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/min-state
[david-image]: http://img.shields.io/david/chunpu/min-state.svg?style=flat-square
[david-url]: https://david-dm.org/chunpu/min-state


Simple finite state machine library for javascript

Installation
---

```sh
npm i min-state
```

Api
---

Constructor

```js
var state = new State({
	start: 'idle', // default state name
	end: 'ended' // if set, can never be set again
})
```

method

- `state.is(stateName)` return true if current state name is val
- `state.set(stateName)` set state current state
- `state.get()` get state current state
- `state.setEvent(stateName, from, to)` set event which can only transition from stateA to stateB
- `state.setEvents({stateName: {from: stateA, to: stateB}})` multiply set event

> use '*' for from which can transition from any state

events

- `enter, state`
- `exit, state`
- `statechange, {from: stateA, to: stateB}`
- `invalid, eventName`

example

check `example.js` for example

License
---

[![License][license-image]][license-url]

[license-image]: http://img.shields.io/npm/l/min-state.svg?style=flat-square
[license-url]: #

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