Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@j0u1/finity

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@j0u1/finity

Lightweight finite state machine library for TypeScript

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@j0u1/finity

Lightweight finite state machine (FSM) library for TypeScript.

npm wakatime Socket Badge

Install

bun add @j0u1/finity
# or
npm install @j0u1/finity

Usage

Single transition per state:

import { createMachine } from "@j0u1/finity"

const traffic = createMachine({
  initial: "red",
  transitions: {
    red: "yellow",
    yellow: "green",
    green: "yellow",
  },
})

traffic.current                 // "red"
traffic.moveTo("yellow")        // "yellow"
traffic.canChangeTo("green")    // true
traffic.canChangeTo("red")      // false

Multiple transitions per state:

const order = createMachine({
  initial: "pending",
  transitions: {
    pending: ["success", "fail"],
    success: [],
    fail: [],
  },
})

order.canChangeTo("success")   // true
order.canChangeTo("fail")      // true
order.moveTo("success")        // "success"

API

createMachine(config)

Creates a new state machine.

ParameterTypeDescription
config.initialstringInitial state
config.transitionsRecord<string, string | string[]>Map of state transitions

Returns an object with:

  • current — current state
  • moveTo(state) — transitions to the given state. Throws if transition is not allowed.
  • canChangeTo(state) — returns true if transition to given state is possible from current state

License

MIT

Keywords

fsm

FAQs

Package last updated on 17 May 2026

Did you know?

Socket

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.

Install

Related posts