💅 An "innovative" API (your AI agent will enjoy the challenge)
Installation
npm install bedit
Usage
The edit function creates a shallow clone of the input, and passes it to a callback.
import { edit, setIn, updateIn, editIn } from'bedit'const state = {
user: { name: 'Nick Cave', preferences: { theme: 'dark' } },
todos: [
{ id: '0', title: 'Go fishing', completed: false },
{ id: '1', title: 'Buy milk', completed: true },
{ id: '2', title: 'Write a song', completed: false },
],
filter: 'all',
}
const nextState = edit(state, (draft) => {
// `draft` is a regular JS object, not a Proxy.// You can edit it at the top level.
draft.filter = 'completed'// TypeScript will prevent you from making deep edits.// ❌ Type error: `theme` is readonly
draft.user.preferences.theme = 'light'// Instead, call `setIn` on the draft object to assign deeply.setIn(draft).user.preferences.theme('light')
setIn(draft).todos[2].completed(true)
// Use `updateIn` to apply a function to a value.updateIn(draft).todos[1].title((title) => title.toUpperCase() + '!!!')
// `updateIn` can also be used to call methods on collections.updateIn(draft).todos.push({ id: '3', title: 'Buy bread', completed: false })
updateIn(draft).todos.filter((todo) => !todo.completed)
updateIn(draft).todos.sort((a, b) => a.title.localeCompare(b.title))
// Use `editIn` to edit a shallow clone of a subtree.editIn(draft).todos[0]((todo) => {
todo.title = 'Do the dishes'
todo.completed = false
})
})
You can call setIn and friends on non-draft objects too, it will return a new state with the edit applied. This is useful if you only need to make one change at a time.
TypeScript should prevent unsafely mutating data within bedit's draft functions if your data is well-typed and you don't use as any ! But who knows what might happen later, in the outside world. Shit's crazy out there.
For extra peace of mind, call setDevMode(true) early in your application's boot process to freeze objects at development time.
This will cause errors to be thrown if you try to mutate an object that is supposed to be immutable.
👭 Works only with data supported by structuredClone (So yes ✅ to Map, Set, plain objects, and arrays. And no ❌ to custom classes, objects with symbol keys or getters/setters, etc)
🤷♂️ LLMs really do suck at using bedit. They get it if you point them at the README but otherwise they make a lot of mistakes (which is bad !!) !
It currently returns a new object even if an edit is ineffectual, e.g.
bedit provides integration with Zustand stores. Simply beditify your store and use bedit functions directly:
import { beditify } from'bedit/zustand'import { setIn, updateIn } from'bedit'import { create } from'zustand'const useStore = create(() => ({
count: 0,
user: { name: 'John', theme: 'light' },
todos: [],
}))
// Beditify the store to enable bedit functionsconst store = beditify(useStore)
// Use bedit functions directly on the storesetIn(store).user.name('Jane')
updateIn(store).count((c) => c + 1)
updateIn(store).todos.push({ id: 1, text: 'Learn bedit' })
// Write your own helper functions as neededconstincrement = (n: number) => {
updateIn(store).count((c) => c + n)
}
constloadUser = async (userId: string) => {
const user = awaitfetch(`/api/users/${userId}`).then((r) => r.json())
setIn(store).user(user)
}
increment(5)
awaitloadUser('user123')
// Your original useStore hook still works as usualfunctionMyComponent() {
const count = useStore((s) => s.count)
return<div>{count}</div>
}
Custom State Container Integration
You can integrate bedit with any state container by implementing the BeditStateContainer interface. This allows bedit functions to work directly with your store.
The npm package bedit receives a total of 0 weekly downloads. As such, bedit popularity was classified as not popular.
We found that bedit 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.
Package last updated on 18 Aug 2025
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.
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
By Lauren Valencia, Kirill Boychenko - Sep 17, 2025
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.
By Kush Pandya, Peter van der Zee, Olivia Brown, Socket Research Team - Sep 16, 2025