@j0u1/finity 1.0.1 → 1.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.
- package/README.md +4 -3
- package/index.ts +1 -1
- package/package.json +2 -2
- package/tsconfig.build.json +14 -0
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @j0u1/finity
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@j0u1/finity)
|
|
4
|
+
[](https://wakatime.com/badge/user/42e0f82b-2688-4a48-85af-5eedd1812f70/project/7cf65f9a-042d-4ed8-ac25-717b8b4ff28b)
|
|
4
5
|
|
|
5
6
|
Lightweight finite state machine (FSM) library for TypeScript.
|
|
6
7
|
|
|
@@ -29,8 +30,8 @@ const traffic = createMachine({
|
|
|
29
30
|
traffic.current // "red"
|
|
30
31
|
traffic.next() // "yellow"
|
|
31
32
|
traffic.current // "yellow"
|
|
32
|
-
traffic.
|
|
33
|
-
traffic.
|
|
33
|
+
traffic.canChangeTo("green") // true
|
|
34
|
+
traffic.canChangeTo("red") // false
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
## API
|
|
@@ -48,4 +49,4 @@ Returns an object with:
|
|
|
48
49
|
|
|
49
50
|
- **`current`** — current state
|
|
50
51
|
- **`next()`** — transitions to the next state, returns new state. Throws if no transition exists.
|
|
51
|
-
- **`
|
|
52
|
+
- **`canChangeTo(state)`** — returns `true` if transition to given state is possible from current state
|
package/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function createMachine(config: ConfigType) {
|
|
|
20
20
|
if (!nextState) throw new FinityError(`No transition from "${this.current}"`)
|
|
21
21
|
return this.current = nextState
|
|
22
22
|
},
|
|
23
|
-
|
|
23
|
+
canChangeTo(state: string) {
|
|
24
24
|
return this.transitions[this.current] === state
|
|
25
25
|
}
|
|
26
26
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j0u1/finity",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "bun build ./index.ts --outdir ./dist --format esm --packages external"
|
|
8
|
+
"build": "bun build ./index.ts --outdir ./dist --format esm --packages external && tsc -p tsconfig.build.json"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["ESNext"],
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"emitDeclarationOnly": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["index.ts"]
|
|
14
|
+
}
|