Immutability primitives for JavaScript — from freeze to isolated snapshots.
npm install constancyNode.js >= 20 · zero dependencies · ESM + CJS
import { deepFreeze, immutableView, snapshot } from 'constancy'
// Freeze in place
const config = deepFreeze({ host: 'localhost', nested: { port: 3000 } })
config.nested.port = 9000 // TypeError
// Proxy view — original still mutable
const view = immutableView(data)
view.x = 1 // TypeError (through view)
// Independent frozen clone
const snap = snapshot(data) // snap and data are separateFull docs — English · Tieng Viet
Start here: Choose the Right Model — 5 APIs, 1 minute to pick the right one.
| Model | Use when |
|---|---|
| Freeze | You own the data, modify in place |
| View | Shared reference, prevent mutation through it |
| Snapshot | Independent frozen copy |
| Isolation | No mutable reference may ever escape |
| Verification | Detect tampering at runtime |
SLSA 3 provenance · pinned action SHAs · fuzz tested · 228+ tests · OpenSSF Scorecard.
See Security Policy.
See CONTRIBUTING.md.
MIT — see LICENSE.