Skip to main content

State Machine

A lightweight, type-safe state machine library for JavaScript/TypeScript

Build robust, predictable applications with a modern, type-safe state machine library. Perfect for complex workflows, UI state management, and business logic orchestration.

< 5KBBundle Size
100%TypeScript
ZeroDependencies
Quick Example
import { StateMachine } from '@jewel998/state-machine';
const machine = new StateMachine.definitionBuilder()
.state('idle')
.state('loading')
.state('success')
.state('error')
.transition('idle', 'loading', 'FETCH')
.transition('loading', 'success', 'SUCCESS')
.transition('loading', 'error', 'ERROR')
.initialState('idle')
.build();
// Use it
machine.processEvent('idle', 'FETCH', {});

Why Choose Our State Machine?

Everything you need to build robust, predictable applications with confidence

Type-Safe & Modern

Built with TypeScript from the ground up. Get full type safety, IntelliSense support, and catch errors at compile time, not runtime.

Lightweight & Fast

Less than 5KB gzipped with zero dependencies. Optimized for performance with minimal memory footprint and blazing-fast state transitions.

Developer Experience

Intuitive builder pattern, comprehensive error handling, and extensive documentation. Get productive immediately with excellent tooling support.

Flexible Architecture

Support for guards, actions, middleware, and complex state hierarchies. Adapt to any use case from simple UI states to complex business workflows.

Production Ready

Battle-tested with comprehensive test coverage, error handling, and transaction support. Ready for mission-critical applications.

Framework Agnostic

Works with React, Vue, Angular, Svelte, or vanilla JavaScript. No framework lock-in, use it anywhere JavaScript runs.

Perfect For

UI State Management

Loading states, form validation, modal flows, and complex user interactions

Business Workflows

Order processing, approval chains, document lifecycles, and process automation

API Integration

Request states, retry logic, authentication flows, and data synchronization