Skip to content

Repository files navigation

Constancy

Immutability primitives for JavaScript — from freeze to isolated snapshots.

npm version npm downloads zero dependencies Node.js CI CodeQL OSV Scanner OpenSSF Best Practices Quality Gate Status Fuzz Testing SLSA 3 Socket Badge OpenSSF Scorecard codecov license

Install

npm install constancy

Node.js >= 20 · zero dependencies · ESM + CJS

Hello World

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 separate

Documentation

Full docsEnglish · Tieng Viet

Start here: Choose the Right Model — 5 APIs, 1 minute to pick the right one.

5 mental models

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

Supply chain

SLSA 3 provenance · pinned action SHAs · fuzz tested · 228+ tests · OpenSSF Scorecard.

See Security Policy.

Contributing

See CONTRIBUTING.md.

License

MIT — see LICENSE.

Funding

About

Make constancy for a value

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages