{"name":"stable-hash","version":"0.0.3","author":{"name":"Shu Ding"},"license":"MIT","_id":"stable-hash@0.0.3","homepage":"https://github.com/shuding/stable-hash#readme","bugs":{"url":"https://github.com/shuding/stable-hash/issues"},"dist":{"shasum":"0078583e684d56ca0ece08f7c588b19f88955698","tarball":"http://registry-npm.ywwl.com/stable-hash/download/stable-hash-0.0.3.tgz","fileCount":5,"integrity":"sha512-c63fvNCQ7ip1wBfPv54MflMA5L6OE5J0p6Fg13IpKft4JAFoNal8+s/jtJ8PibrwqXm4onnbeQsADs8k0NQGUA==","signatures":[{"sig":"MEUCIF1RJZ6pfGLjaPXP1sW0jZlXlMh5JvycOf3o5Si/pzGPAiEA4gjcjxdkvIjgmBgbmTyKqc/0lufXeWugGgK6BVdxQ4c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5540,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjm063ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpywQ/+JjG8T785YQvGVSoKvIRBwdLopWez+fV3MtJuiiYPtqA0libi\r\nbyZ5viHEu+blG5XKylFDjsDKTBOogl0T76wSnNubbxBuf1+HejMaGh8ExK70\r\nxMcFYHXmCFMjk8uwxok/nVi35Oihgm/xAkxWtTyDSX/wpnqWNAth5YBqwbma\r\nc/uHg4k6Ym6mUUiijty/KTNBYQPQqgO6puqRXrye+917TJ9+rsUinhf7m5UJ\r\nZiRxg02/6l6LDtHuTJkbDHpF8DZJiJL3zgoOPlCoHSdglFr9MM+aXFb2gUtq\r\nWKzshaM2pIcmEccj9U7fU/xnDjpKy9oRfk413GXUxDWNkv5h5RIRxy8eTwBg\r\nr9V3nczVcsoHhFnVI+m1affprOzgic3d7Z+wE2jQxGEBB072vTpyEOqiU/7s\r\nm9hjaEwpXRWhnkT45NQSDZNoP2nOUyiO3EXFeWYhfzqz5YdTLsvdVF04DyIF\r\nCrE4XDAKVQi+l0Cu5798QjLt4tI750i5XTZND/ttotA1V/YDW7tjxupSSssf\r\nL3pskbXhWdNeOLj3ndEAJ+XYEgRLt1WqY1GkWdH1Rn9q7llmjfuUBEeiizRs\r\nEl6YuooMPp2fUGdRYQurp7Ku+tOQTFMbNdq3YA40TXpDIlY+du682rJAjvFI\r\nvhgvhFzDAgUBGWi+xlHiBqqi0BE78HuJtOk=\r\n=XsVO\r\n-----END PGP SIGNATURE-----\r\n","size":2486,"noattachment":false,"key":"/stable-hash/-/stable-hash-0.0.3.tgz"},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{"import":"./dist/index.mjs","require":"./dist/index.js"},"gitHead":"be2acc38568ab553cdb79485676b71ac1db00431","scripts":{"test":"jest","build":"yarn build:mjs && yarn build:cjs && yarn build:types","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","build:types":"tsc --emitDeclarationOnly --declaration -p tsconfig.build.json"},"_npmUser":{"name":"quietshu","email":"g@shud.in"},"prettier":{"semi":false},"repository":{"url":"git+https://github.com/shuding/stable-hash.git","type":"git"},"_npmVersion":"7.20.1","description":"Stable JS value hash.","directories":{},"_nodeVersion":"16.14.2","_hasShrinkwrap":false,"devDependencies":{"jest":"^28.1.1","esbuild":"^0.12.28","flattie":"^1.1.0","ts-jest":"^28.0.5","hash-obj":"^4.0.0","prettier":"^2.7.1","nanobench":"^2.1.1","base64-url":"^2.3.3","typescript":"^4.7.4","@types/jest":"^28.1.3","json-stringify-deterministic":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/stable-hash_0.0.3_1671122615789_0.7831061515878903","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":1671122615926,"maintainers":[{"name":"quietshu","email":"g@shud.in"}],"_cnpm_publish_time":1671122615926,"dist-tags":{"latest":"0.0.6"}}