fn-machine
Advanced tools
Comparing version 0.0.15 to 0.0.16
import machine from "./src/fn-machine.js"; | ||
import state from "./src/fn-state.js"; | ||
export { machine, state }; | ||
import { toMermaid } from "./src/util/mermaids.js"; | ||
import { fromMermaid } from "./src/util/mermaids.js"; | ||
export { machine, state, toMermaid, fromMermaid }; |
import machine from './src/fn-machine.js'; | ||
import state from './src/fn-state.js'; | ||
export {machine, state}; | ||
import {toMermaid, fromMermaid} from './src/util/mermaids.js'; | ||
export {machine, state, toMermaid, fromMermaid}; |
{ | ||
"name": "fn-machine", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "a tiny functional state machine", | ||
@@ -12,2 +12,3 @@ "main": "index", | ||
"test": "mocha -r esm", | ||
"test:watch": "mocha -r esm -watch", | ||
"type-check": "tsc --noEmit", | ||
@@ -14,0 +15,0 @@ "release": "npm run type-check && np", |
@@ -90,4 +90,32 @@ # fn-machine | ||
#### mermaid | ||
There are two utility functions to convert to and from mermaid syntax. | ||
```javascript | ||
toMermaid([state('on', {powerOff: 'off'}, state('off', {powerOn: 'on'}))], 'off'); | ||
``` | ||
produces a string like that you can process with mermaidjs to visualize your machine: | ||
``` | ||
stateDiagram-v2 | ||
[*] --> off | ||
on --> off: powerOff | ||
off --> on: powerOn | ||
``` | ||
Or, you can take a mermaid string and output some stub javascript: | ||
```javascript | ||
const mermaidStr = ` | ||
stateDiagram-v2 | ||
[*] --> off | ||
on --> off: powerOff | ||
off --> on: powerOn | ||
`; | ||
fromMermaid(mermaidStr); | ||
``` | ||
which produces: | ||
```javascript | ||
[state('on', {powerOff: 'off'}, state('off', {powerOn: 'on'}))] | ||
``` | ||
These are useful for visualization and initial creation of your machines, but beware that if your machine transitions contain logic, that logic would be lost should you try to go full circle: machine -> mermaid -> machine. | ||
#### Contributing | ||
Yes! PR's are welcome. Tests are written in mocha. Run with `npm run test` or `yarn test`. Typechecking is provided by typescript via JSDoc annotations. |
14739
10
278
121