npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@prince_j/tinystate

v1.0.1

Published

A tiny, type-safe state machine with exhaustive event handling.

Readme

tinystate - v1.0.0

A tiny, type-safe state machine with exhaustive event handling.

Features

  • 🎯 Type-safe — Invalid events are caught at compile time
  • 🔒 Immutable — State is frozen in development to prevent mutations
  • 📦 Tiny — Zero dependencies, ~1KB minified
  • 🧩 Exhaustive switches — TypeScript ensures all events are handled
  • 🎭 Flexible — States can have different shapes

Installation

npm install @prince_j/tinystate
# or
bun add @prince_j/tinystate
# or
yarn add @prince_j/tinystate

Getting started

import { createMachine } from 'tinystate'

const counter = createMachine({
  initial: { count: 0 },
  transition: (state, event) => {
    switch (event.type) {
      case 'INCREMENT': return { count: state.count + 1 }
      case 'DECREMENT': return { count: state.count - 1 }
      default: { const _exhaustive: never = event; return state }
    }
  }
})

counter.subscribe(state => console.log(state.count))
counter.send({ type: 'INCREMENT' }) // logs 1

Advanced example

import { createMachine } from 'tinystate'
// A game state machine with different phase shapes
type GameState = 
  | { phase: 'menu' }
  | { phase: 'playing'; score: number; lives: number; position: { x: number; y: number } }
  | { phase: 'gameOver'; finalScore: number }
type GameEvent = 
  | { type: 'START' }
  | { type: 'MOVE'; x: number; y: number }
  | { type: 'SCORE'; points: number }
  | { type: 'LOSE_LIFE' }
  | { type: 'GAME_OVER' }

const game = createMachine<GameState, GameEvent>({
  initial: { phase: 'menu' },
  transition: (state, event) => {
    switch (event.type) {
      case 'START':
        if (state.phase === 'menu' || state.phase === 'gameOver') {
          return { phase: 'playing', score: 0, lives: 3, position: { x: 0, y: 0 } }
        }
        return state
      
      case 'MOVE':
        if (state.phase === 'playing') {
          return { ...state, position: { x: event.x, y: event.y } }
        }
        return state
      
      case 'SCORE':
        if (state.phase === 'playing') {
          return { ...state, score: state.score + event.points }
        }
        return state
      
      case 'LOSE_LIFE':
        if (state.phase === 'playing') {
          const lives = state.lives - 1
          if (lives === 0) {
            return { phase: 'gameOver', finalScore: state.score }
          }
          return { ...state, lives }
        }
        return state
      
      case 'GAME_OVER':
        if (state.phase === 'playing') {
          return { phase: 'gameOver', finalScore: state.score }
        }
        return state
      
      default:
        const _exhaustive: never = event
        return state
    }
  }
})
// Use it
game.subscribe(state => {
  if (state.phase === 'playing') {
    console.log(`Score: ${state.score}, Lives: ${state.lives}`)
  }
})
game.send({ type: 'START' })
game.send({ type: 'SCORE', points: 100 })

Stability

tinystate v1.0.0 follows semantic versioning:

  • PATCH: Internal optimizations, better error messages, documentation fixes, and bug fixes that don't change behavior.

  • MINOR: New optional methods on the actor (e.g. onTransition, reset), new config options (e.g. context, middleware), or additional helper exports. Existing code continues to work unchanged.

  • MAJOR: Changing createMachine signature, removing or renaming getState/send/subscribe, changing send to return a value, breaking the default: never exhaustiveness check, or dropping Node.js 18 support.

The promise: Any code written for v1.0.0 works in all v1.x.x releases.