Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fn-machine

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-machine - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

src/util/mermaids.d.ts

4

index.d.ts
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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc