red-hatchet
v0.0.4
Published
**Red Hatchet** is a lightweight TypeScript library for creating **persistent state objects backed by localStorage**.
Maintainers
Readme
🪓 Red Hatchet
Red Hatchet is a lightweight TypeScript library for creating persistent state objects backed by localStorage.
The idea is simple: create a state object and any change to it is automatically persisted.
No reducers. No boilerplate. No complex state management.
Just a plain object that saves itself.
Installation
npm install red-hatchetor
yarn add red-hatchetBasic Usage
import { hatchet } from "red-hatchet"
const player = hatchet("player", {
hp: 100,
mana: 50
})
player.hp -= 10Any modification to the object is automatically saved to localStorage.
How It Works
When you create a store:
const player = hatchet("player", {
hp: 100,
mana: 50
})Red Hatchet will:
- Check if data exists in
localStorage - Load it if available
- Otherwise use the initial state
- Persist any change automatically
Example
import { hatchet } from "red-hatchet"
const player = hatchet("player", {
hp: 100,
mana: 50,
level: 1
})
player.hp = 80
player.level += 1Stored in localStorage:
{
"hp": 80,
"mana": 50,
"level": 2
}Reset State
player.$reset()This restores the initial state.
Subscribe to Changes
player.$subscribe((state) => {
console.log("state updated:", state)
})TypeScript Support
Types are inferred automatically.
const player = hatchet("player", {
hp: 100,
mana: 50
})
player.hp // number
player.mana // numberNo manual typing required.
React Integration
You can use Red Hatchet directly, but for automatic re-renders you can use a small hook.
import { useHatchet } from "red-hatchet/react"
const player = useHatchet(
hatchet("player", {
hp: 100
})
)Now changes trigger component updates.
Why Red Hatchet?
- 🪶 Lightweight
- ⚡ Extremely simple API
- 🔒 Fully typed with TypeScript
- 💾 Automatic persistence
- 🧠 No reducers or actions
- 🔧 Works with any framework
Roadmap
Planned features:
- Cross-tab synchronization
- sessionStorage support
- Plugin system
- TTL (state expiration)
- Schema validation
- Storage adapters
Future API Example
const settings = hatchet("settings", {
darkMode: false
})
settings.darkMode = trueLicense
MIT
Author
Created to simplify persistent state management with TypeScript.
