
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
A JavaScript finite state machine with a more natural fashion.
<script src="path/to/state.js"></script>
var myState = StateJS.create(/* ... */);
var State = require('state-js');
var myState = State.create(/* ... */);
Creates and returns a state machine object according to configuration defined in config.
config: A JavaScript object literal defining the state machine.A config object should be in the following form:
{
name: [{
entry: 'Hello world', // `entry` specifies state entry conditions
onEnter: function (newVal, oldVal) {
// `onEnter` specifies the callback function to be invoked when entering the state.
// `newVal`: current value.
// `oldVal`: previous value.
},
onLeave: function (newVal, oldVal) {
// `onLeave` specifies the callback function to be invoked when leaving the state.
// `newVal`: current value.
// `oldVal`: previous value.
}
}, {
entry: 'StateJS', // Here is another state.
onEnter: function () {/* ... */},
onLeave: function () {/* ... */}
}],
version: {
value: 1, // By wrapping state in an object literal, you can use `value` to define its default/initial value.
states: [{ // Then use `states` to define states.
entry: function (val) { return Math.floor(val) === 100 }, // `entry` can also be a function returning true or false.
onEnter: function () {/* ... */},
onLeave: function () {/* ... */}
}]
}
}
After create a state machine, you can change/get by:
var state = StateJS(/* ... */);
console.log(state.name); // To get.
state.name = 'StateJS'; // To set/change. May trigger onEnter and onLeave callbacks.
You can add states by calling .add(config). To remove states, call .remove([stateName1, stateName2, ...]).
In current version, entry cannot be either object or array. However, you can compare/manipulate such types by defining entry as a function and then access object/array through the passed argument.
MIT
FAQs
A JavaScript finite state machine with a more natural fashion.
We found that state-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.