it-fsm/README.md

45 lines
1.1 KiB
Markdown
Raw Normal View History

2019-10-11 10:54:07 +03:00
# IT FSM
2021-08-20 02:49:47 +03:00
[![ci](https://github.com/icetemple/it-fsm/actions/workflows/ci.yml/badge.svg)](https://github.com/icetemple/it-fsm/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/icetemple/it-fsm/badge.svg?branch=master)](https://coveralls.io/github/icetemple/it-fsm?branch=master)
2019-10-19 20:27:06 +03:00
2021-08-23 11:33:55 +03:00
Simple full-featured finite state machine for your project
2019-10-17 13:54:15 +03:00
2021-08-23 11:33:55 +03:00
### Why it-fsm?
- 🚯 333 LOC - 0 dependencies
- 🍒 Sophisticated object-oriented design
2019-10-17 13:54:15 +03:00
2021-08-23 11:33:55 +03:00
### Getting started
2019-10-17 13:54:15 +03:00
2021-08-20 01:32:01 +03:00
```ts
import { StateMachineBuilder } from "it-fsm";
2019-10-17 13:54:15 +03:00
2021-08-23 11:33:55 +03:00
const [locked, unlocked] = ['locked', 'unlocked'] as const;
2019-10-17 13:54:15 +03:00
2021-08-23 11:33:55 +03:00
const sm = new StateMachineBuilder()
.withStates([locked, unlocked])
2021-08-20 01:32:01 +03:00
.withTransitions([
2021-08-23 11:33:55 +03:00
[locked, { coin: unlocked }],
[unlocked, { push: locked }],
])
.build(locked);
```
2019-10-17 13:54:15 +03:00
2021-08-23 11:33:55 +03:00
or with deno
2019-10-17 13:54:15 +03:00
2021-08-23 11:33:55 +03:00
```ts
import { StateMachineBuilder } from "https://raw.githubusercontent.com/icetemple/it-fsm/master/fsm.ts";
2021-08-20 01:32:01 +03:00
2021-08-23 11:33:55 +03:00
// ...
```
2021-08-20 01:32:01 +03:00
2021-08-23 11:33:55 +03:00
You can find the full example in the examples folder.
2021-08-20 01:32:01 +03:00
2021-08-23 11:33:55 +03:00
### Install
2021-08-20 01:32:01 +03:00
2021-08-23 11:33:55 +03:00
If you want to use it in Node.js or the browser, you may need to install it as follows
2021-08-20 01:32:01 +03:00
2021-08-23 11:33:55 +03:00
`npm install --save it-fsm`