Gathering detailed insights and metrics for javascript-state-machine
Gathering detailed insights and metrics for javascript-state-machine
Gathering detailed insights and metrics for javascript-state-machine
Gathering detailed insights and metrics for javascript-state-machine
npm install javascript-state-machine
Typescript
Module System
Node Version
NPM Version
JavaScript (99.56%)
HTML (0.44%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8,735 Stars
165 Commits
968 Forks
260 Watchers
3 Branches
11 Contributors
Updated on Jul 10, 2025
Latest Version
3.1.0
Package Id
javascript-state-machine@3.1.0
Size
17.02 kB
NPM Version
5.6.0
Node Version
8.9.4
Published on
Jul 12, 2018
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A library for finite state machines.
VERSION 3.0 Is a significant rewrite from earlier versions. Existing 2.x users should be sure to read the Upgrade Guide.
In a browser:
1 <script src='state-machine.js'></script>
after downloading the source or the minified version
Using npm:
1 npm install --save-dev javascript-state-machine
In Node.js:
1 var StateMachine = require('javascript-state-machine');
A state machine can be constructed using:
1 var fsm = new StateMachine({ 2 init: 'solid', 3 transitions: [ 4 { name: 'melt', from: 'solid', to: 'liquid' }, 5 { name: 'freeze', from: 'liquid', to: 'solid' }, 6 { name: 'vaporize', from: 'liquid', to: 'gas' }, 7 { name: 'condense', from: 'gas', to: 'liquid' } 8 ], 9 methods: { 10 onMelt: function() { console.log('I melted') }, 11 onFreeze: function() { console.log('I froze') }, 12 onVaporize: function() { console.log('I vaporized') }, 13 onCondense: function() { console.log('I condensed') } 14 } 15 });
... which creates an object with a current state property:
fsm.state
... methods to transition to a different state:
fsm.melt()
fsm.freeze()
fsm.vaporize()
fsm.condense()
... observer methods called automatically during the lifecycle of a transition:
onMelt()
onFreeze()
onVaporize()
onCondense()
... along with the following helper methods:
fsm.is(s)
- return true if state s
is the current statefsm.can(t)
- return true if transition t
can occur from the current statefsm.cannot(t)
- return true if transition t
cannot occur from the current statefsm.transitions()
- return list of transitions that are allowed from the current statefsm.allTransitions()
- return list of all possible transitionsfsm.allStates()
- return list of all possible statesA state machine consists of a set of States
A state machine changes state by using Transitions
A state machine can perform actions during a transition by observing Lifecycle Events
A state machine can also have arbitrary Data and Methods.
Multiple instances of a state machine can be created using a State Machine Factory.
Read more about
You can Contribute to this project with issues or pull requests.
See RELEASE NOTES file.
See MIT LICENSE file.
If you have any ideas, feedback, requests or bug reports, you can reach me at jake@codeincomplete.com, or via my website: Code inComplete
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/27 approved changesets -- score normalized to 1
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
82 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More