
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
A lightweight finite state machine library for typescript based on t-state
pnpm add light-fsm
Use the createFSM function to create a new state machine.
import { createFSM } from 'light-fsm';
const lightFSM = createFSM<{
states: 'green' | 'yellow' | 'red' | 'emergency';
events: { type: 'TIMER_END' | 'EMERGENCY' };
}>({
initial: 'green',
states: {
green: {
on: {
TIMER_END: 'yellow',
},
},
yellow: {
on: {
TIMER_END: 'red',
EMERGENCY: 'emergency',
},
},
red: {
on: {
TIMER_END: 'green',
},
},
emergency: {
final: true,
},
},
});
Use the send method to send events to the state machine.
lightFSM.send({ type: 'TIMER_END' });
stateGet the current state of the state machine.
const state = lightFSM.state;
console.log(state); // 'green'
snapshotGet a snapshot of the state machine.
const snapshot = lightFSM.snapshot;
console.log(snapshot.value); // { value: 'green', prev: undefined, done: false, lastEvent: undefined }
storeGet the internal t-state store. Allowing you to subscribe to the state machine ou use it in your react application. See the t-state documentation for more information.
const store = lightFSM.store;
store.subscribe(({ current, prev }) => {
console.log(current, prev);
});
Guards are functions that can be used to determine it a transition should be allowed or not. You should use guards instead of simple conditions in order to the dev validations work.
import { createFSM } from 'light-fsm';
const lightFSM = createFSM<{
states: 'form' | 'submitting' | 'submitted' | 'error';
events: { type: 'SUBMIT' | 'SUBMIT_DONE' };
guards: 'isFormValid';
}>({
initial: 'form',
guards: {
isFormValid: () => checkIfFormIsValid(),
},
states: {
form: {
on: {
SUBMIT: [
{ guard: 'isFormValid', target: 'submitting' },
{ target: 'error' },
],
},
},
submitting: {
on: {
SUBMIT_DONE: 'submitted',
},
},
error: {
final: true,
},
submitted: {
final: true,
},
},
});
You can also use inline guards:
const machine = createFSM<{
states: 'A' | 'B';
events: { type: 'NEXT' };
}>({
initial: 'A',
states: {
A: {
on: {
NEXT: {
guard: () => canGoToB(),
target: 'B',
},
},
},
B: {
final: true,
},
},
});
FAQs
A lightweight finite state machine library
We found that light-fsm demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.