@j0u1/finity 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +43 -7
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -1,15 +1,51 @@
1
- # finity
1
+ # @j0u1/finity
2
2
 
3
- To install dependencies:
3
+ [![npm](https://img.shields.io/npm/v/@j0u1/finity)](https://www.npmjs.com/package/@j0u1/finity)
4
+
5
+ Lightweight finite state machine (FSM) library for TypeScript.
6
+
7
+ ## Install
4
8
 
5
9
  ```bash
6
- bun install
10
+ bun add @j0u1/finity
11
+ # or
12
+ npm install @j0u1/finity
7
13
  ```
8
14
 
9
- To run:
15
+ ## Usage
10
16
 
11
- ```bash
12
- bun run index.ts
17
+ ```ts
18
+ import { createMachine } from "@j0u1/finity"
19
+
20
+ const traffic = createMachine({
21
+ initial: "red",
22
+ transitions: {
23
+ red: "yellow",
24
+ yellow: "green",
25
+ green: "yellow",
26
+ },
27
+ })
28
+
29
+ traffic.current // "red"
30
+ traffic.next() // "yellow"
31
+ traffic.current // "yellow"
32
+ traffic.can("green") // true
33
+ traffic.can("red") // false
13
34
  ```
14
35
 
15
- This project was created using `bun init` in bun v1.3.13. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
36
+ ## API
37
+
38
+ ### `createMachine(config)`
39
+
40
+ Creates a new state machine.
41
+
42
+ | Parameter | Type | Description |
43
+ |---|---|---|
44
+ | `config.initial` | `string` | Initial state |
45
+ | `config.transitions` | `Record<string, string>` | Map of state transitions |
46
+
47
+ Returns an object with:
48
+
49
+ - **`current`** — current state
50
+ - **`next()`** — transitions to the next state, returns new state. Throws if no transition exists.
51
+ - **`can(state)`** — returns `true` if transition to given state is possible from current state
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@j0u1/finity",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "module": "index.ts",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "bun build ./index.ts --outdir ./dist --format esm --packages external"
9
9
  },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/j0u1/finity"
13
+ },
10
14
  "devDependencies": {
11
15
  "@types/bun": "latest"
12
16
  },
13
17
  "peerDependencies": {
14
18
  "typescript": "^5"
15
19
  }
16
- }
20
+ }