cache-key is a lightweight library for creating stable, deterministic cache keys from complex JavaScript objects. Version 1.0.0 targets Node.js >=16, ships TypeScript definitions, and provides a single function `hashCacheKey` that returns a JSON-stringified representation, sorting object keys alphabetically for consistency. Unlike JSON.stringify or libraries like object-hash, cache-key focuses on simplicity: it does not hash into short strings but retains the structure as a string for readability. Ideal for memoization and simple caching scenarios where inputs are arrays of mixed values and keys must be order-aware but property-order-independent.
npm install cache-keyNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Generates stable cache keys from an array of values, handling nested objects with sorted keys.
Sort the array manually before calling hashCacheKey if order-independent keys are desired.
Consider passing the result through a hashing function like crypto.createHash('sha256') for shorter keys.Ensure objects passed in have enumerable string keys. Symbols or non-enumerable properties are ignored.
Use a library like 'json-stable-stringify' with circular reference support or remove circular references before calling.
Remove or replace circular references before passing to hashCacheKey, e.g., by using a deep clone library that handles circulars.
Add "type": "module" to your package.json or use dynamic import with await import('cache-key').Use default import: import hashCacheKey from 'cache-key' or named import: import { hashCacheKey } from 'cache-key'.No dependency data recorded yet.