it-fsm/README.md

63 lines
1.5 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
2022-06-21 16:56:49 +03:00
# Why it-fsm?
2021-08-23 11:33:55 +03:00
- 🚯 333 LOC - 0 dependencies
- 🍒 Sophisticated object-oriented design
2019-10-17 13:54:15 +03:00
2022-06-21 16:56:49 +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
2022-06-21 16:56:49 +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
2022-06-21 16:56:49 +03:00
You can find the full example in the [examples](./examples/) folder.
2019-10-17 13:54:15 +03:00
2022-06-21 16:56:49 +03:00
# Installation
2022-11-17 18:55:00 +03:00
## Deno
2022-06-21 16:56:49 +03:00
if you use the [Deno](https://deno.land), just add following to your
`import_map.json`
2021-08-20 01:32:01 +03:00
2022-06-21 16:56:49 +03:00
```json
{
"imports": {
2022-11-17 18:55:00 +03:00
"it-fsm": "https://git.pleshevski.ru/pleshevskiy/it-fsm/src/commit/e3796c92639e3483a2a2a01a89912561561e796f/fsm.ts"
2022-06-21 16:56:49 +03:00
}
}
2021-08-23 11:33:55 +03:00
```
2021-08-20 01:32:01 +03:00
2022-11-17 18:55:00 +03:00
or you can use branch instead
2022-06-21 16:56:49 +03:00
`https://git.pleshevski.ru/pleshevskiy/paren/raw/branch/main/`
2021-08-20 01:32:01 +03:00
2022-11-17 18:55:00 +03:00
> **Note**: I recommend to use a specific commit instead of branch
## Node.js
2021-08-20 01:32:01 +03:00
2022-06-21 16:56:49 +03:00
If you use the Node.js or in a browser as ES module, you may need to install it
as follows, and additionally you can add import maps for client side.
2021-08-20 01:32:01 +03:00
2021-08-23 11:33:55 +03:00
`npm install --save it-fsm`
2022-06-21 16:56:49 +03:00
# License
GNU General Public License v3.0 or later
See [COPYING](./COPYING) to see the full text.