{"name":"stable-hash","version":"0.0.2","author":{"name":"Shu Ding"},"license":"MIT","_id":"stable-hash@0.0.2","homepage":"https://github.com/shuding/stable-hash#readme","bugs":{"url":"https://github.com/shuding/stable-hash/issues"},"dist":{"shasum":"a909deaa5b9d430b100ca0a10132a533f2665e94","tarball":"http://registry-npm.ywwl.com/stable-hash/download/stable-hash-0.0.2.tgz","fileCount":4,"integrity":"sha512-tPwQ3c1rLIwbJpq59duoznegEbmgfV630C2n4R4G96LKBFljgK8j+O9AxjqB6cAzu4gE7s4pByrLWtZel8E+Mg==","signatures":[{"sig":"MEUCIQCZMZ9G8oub07+TAc4rwuBp/i6XUbZCvrUxKIx+VrK+RAIgZDctFWwoSZ7x2UkhrnMf7bSxzgYJ1i9pB20KxC1TkLg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4901,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh277KCRA9TVsSAnZWagAAMWoP/3dvUPtLErzEcmYK7xfm\n5jqlVMDL1Fbm0gY77DP8nDH67v/JVb3y1fZq8SRdIb+MvdcU7Z6wG1C/D5HC\n08h9MnazX8WVqidHON3iQtpk7HTPAXgevg86lbJOwyY6YAEgchJ3Z6w6wxpT\nIsyN0u78W+4aR5wQ1fLYChWSyuPi7u2L4AQkDT1933gMlzn61KREPJ5pXLFr\n1Sy23NJ4QhBSR1ktiUY+78vuabc/t8cS7dKx7St/jNaq1v4VMyzaWgIU7FOl\nfbZzd1DqHqjZh3wYeFc07sa4df8/RVOtZHpupEi3uI32/TtTn6kx1Zmq1aNE\nyoZpdoq11XkOzAuu8N7GFLfKheCZpwFk7aHdq8bqXkSykl+DceJmzJCIDoe7\nTy4rTL4xWx5jge/iAmExEWXNi9EwrQRguA4icv0xG4UYok09HJS45Q4MPsyU\n4eK1MAwQ5TmSosOilIODSE4oCdCGzGQiCglTf06px9YiFKMaaNygPynZlbyc\nl64BfI+kgr3/vHPbg1w6NOB8lH0YxjTtZ2vUZGyQxq2ovD+vDOAIHlMuulvF\nGwHDdMbZ5ovYN8a4mUSyZKLMkOGUWwjkgmhImI2OvwROB+TXMSXxY309QLpd\nQ/tgMHnjRlFFD25GKEOc4+Mfgjj4RVfsxNraWQvP1NTVimQuiNJvVI51fhMe\noLSV\r\n=masI\r\n-----END PGP SIGNATURE-----\r\n","size":2084,"noattachment":false,"key":"/stable-hash/-/stable-hash-0.0.2.tgz"},"main":"./dist/index.js","module":"./dist/index.mjs","gitHead":"65b4e97f062e638074879525ceb21b5f25ddc280","scripts":{"build":"yarn build:mjs && yarn build:cjs","build:cjs":"esbuild src/index.ts --minify --target=es6 --outdir=dist --format=cjs","build:mjs":"esbuild src/index.ts --minify --target=es6 --outdir=dist --out-extension:.js=.mjs"},"_npmUser":{"name":"quietshu","email":"ds303077135@gmail.com"},"prettier":{"semi":false},"repository":{"url":"git+https://github.com/shuding/stable-hash.git","type":"git"},"_npmVersion":"7.20.3","description":"Stable JS value hash.","directories":{},"_nodeVersion":"14.16.0","_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.12.28"},"_npmOperationalInternal":{"tmp":"tmp/stable-hash_0.0.2_1631886993883_0.017489791433481505","host":"s3://npm-registry-packages"},"readme":"# stable-hash\n\nA tiny and fast (481b <sup>[unpkg](https://unpkg.com/stable-hash@0.0.3/dist/index.mjs)</sup>) lib for \"stably hashing\" a JavaScript value. Originally created for [SWR](https://github.com/vercel/swr).\n\nIt's similar to `JSON.stringify(value)`, but:\n1. Supports any JavaScript value (BigInt, NaN, Symbol, function, class, ...)\n2. Sorts object keys (stable)\n3. Supports circular objects\n\n## Use\n\n```bash\nyarn add stable-hash\n```\n\n```js\nimport hash from 'stable-hash'\n\nhash(anyJavaScriptValueHere) // returns a string\n```\n\n## Examples\n\n### Primitive Value\n\n```js\nhash(1)\nhash('foo')\nhash(true)\nhash(undefined)\nhash(null)\nhash(NaN)\n```\n\nBigInt:\n\n```js\nhash(1) === hash(1n)\nhash(1) !== hash(2n)\n```\n\nSymbol:\n\n```js\nhash(Symbol.for('foo')) === hash(Symbol.for('foo'))\nhash(Symbol.for('foo')) === hash(Symbol('foo'))\nhash(Symbol('foo')) === hash(Symbol('foo'))\nhash(Symbol('foo')) !== hash(Symbol('bar'))\n```\n\n_Since Symbols cannot be serialized, stable-hash simply uses its description as the hash._\n\n### Regex\n\n```js\nhash(/foo/) === hash(/foo/)\nhash(/foo/) !== hash(/bar/)\n```\n\n### Date\n\n```js\nhash(new Date(1)) === hash(new Date(1))\n```\n\n### Array\n\n```js\nhash([1, '2', [new Date(3)]]) === hash([1, '2', [new Date(3)]])\nhash([1, 2]) !== hash([2, 1])\n```\n\nCircular:\n\n```js\nconst foo = []\nfoo.push(foo)\nhash(foo) === hash(foo)\n```\n\n### Object\n\n```js\nhash({ foo: 'bar' }) === hash({ foo: 'bar' })\nhash({ foo: { bar: 1 } }) === hash({ foo: { bar: 1 } })\n```\n\nStable:\n\n```js\nhash({ a: 1, b: 2, c: 3 }) === hash({ c: 3, b: 2, a: 1 })\n```\n\nCircular:\n\n```js\nconst foo = {}\nfoo.foo = foo\nhash(foo) === hash(foo)\n```\n\n### Function, Class, Set, Map, Buffer...\n\n`stable-hash` guarantees reference consistency (`===`) for objects that the constructor isn't `Object`.\n\n```js\nconst foo = () => {}\nhash(foo) === hash(foo)\nhash(foo) !== hash(() => {})\n```\n\n```js\nclass Foo {}\nhash(Foo) === hash(Foo)\nhash(Foo) !== hash(class {})\n```\n\n```js\nconst foo = new Set([1])\nhash(foo) === hash(foo)\nhash(foo) !== hash(new Set([1]))\n```\n\n## Notes\n\nThis function does something similar to `JSON.stringify`, but more than it. It doesn't generate a secure checksum, which usually has a fixed length and is hard to be reversed. With `stable-hash` it's still possible to get the original data. Also, the output might include any charaters, not just alphabets and numbers like other hash algorithms. So:\n\n- Use another encoding layer on top of it if you want to display the output. \n- Use another crypto layer on top of it if you want to have a secure and fixed length hash.\n\n```js\nimport crypto from 'crypto'\nimport hash from 'stable-hash'\n\nconst weakHash = hash(anyJavaScriptValueHere)\nconst encodedHash = Buffer.from(weakHash).toString('base64')\nconst safeHash = crypto.createHash('MD5').update(weakHash).digest('hex')\n```\n\nAlso, the consistency of this lib is sometimes guaranteed by the singularity of the WeakMap instance. So it might not generate the consistent results when running in different runtimes, e.g. server/client or parent/worker scenarios.\n\n## License\n\nCreated by Shu Ding. Released under the MIT License.\n","publish_time":1631886994073,"maintainers":[{"name":"quietshu","email":"g@shud.in"}],"_cnpm_publish_time":1631886994073,"dist-tags":{"latest":"0.0.6"}}