it-fsm/README.md

59 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
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": {
"it-fsm": "https://git.pleshevski.ru/pleshevskiy/it-fsm/src/commit/c182728810e9fabcb6bb2b3091bbeabf439bef2d/fsm.ts"
}
}
2021-08-23 11:33:55 +03:00
```
2021-08-20 01:32:01 +03:00
2022-06-21 16:56:49 +03:00
or you can use branch
`https://git.pleshevski.ru/pleshevskiy/paren/raw/branch/main/`
2021-08-20 01:32:01 +03:00
2022-06-21 16:56:49 +03:00
> **Note**: Use always a specific commit instead of branch
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.