Kokuin is a zero-dependency TypeScript library for deterministic JSON hashing
A developer has released Kokuin, a lightweight (~200 lines of code) TypeScript library that generates deterministic SHA-256 hashes from any JSON-compatible value using a single hash() function. The library addresses common pitfalls of the naive JSON.stringify-plus-hash approach, which fails on unordered object keys, circular references, and edge-case types like BigInt and undefined. Kokuin normalizes key ordering so that objects with identical content but different key sequences produce the same hash, while deliberately rejecting unreliable types such as Map, Set, Date, and functions with explicit errors. It uses a hand-written pure JavaScript SHA-256 implementation, making it compatible across Node, Bun, Deno, and browser environments without any external dependencies. The library is aimed at use cases such as cache key generation, idempotency checks, and payload deduplication across distributed services.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in