{"name":"ohash","version":"2.0.2","license":"MIT","_id":"ohash@2.0.2","maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"homepage":"https://github.com/unjs/ohash#readme","bugs":{"url":"https://github.com/unjs/ohash/issues"},"dist":{"shasum":"f71440ea65146004d908e5d5f11ddb5965a54b8c","tarball":"http://registry-npm.ywwl.com/ohash/download/ohash-2.0.2.tgz","fileCount":13,"integrity":"sha512-A2CLcYHM2RlOWMz4jKKfAMO9rz7gJ4EV5XbI2CfHMv1hWm24Gc4JqkoA4Dps1H8rD2cbiqXrwLO6mxoIZNyf1Q==","signatures":[{"sig":"MEQCIHSOAZTEK6TGgPrKaKvdpT+vlb6a2O4HJ9n3yEP3McY1AiA/bodOpePYRJso3X+gGj88VmDAvG94nZ93mllJoERDYg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19236,"size":7493,"noattachment":false,"key":"/ohash/-/ohash-2.0.2.tgz"},"type":"module","_from":"file:ohash-2.0.2.tgz","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./utils":{"types":"./dist/utils/index.d.mts","default":"./dist/utils/index.mjs"},"./crypto":{"node":{"types":"./dist/crypto/node/index.d.mts","default":"./dist/crypto/node/index.mjs"},"default":{"types":"./dist/crypto/js/index.d.mts","default":"./dist/crypto/js/index.mjs"}}},"scripts":{"dev":"vitest dev","lint":"eslint . && prettier -c src test","test":"pnpm lint && vitest run --coverage && pnpm test:types","bench":"vitest bench","build":"unbuild","release":"pnpm test && changelogen --release --push && pnpm publish","lint:fix":"automd && eslint --fix . && prettier -w src test","test:types":"tsc --noEmit"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"_resolved":"/private/var/folders/hq/c07mx_4n6tg50tlvwps5l8600000gn/T/d0a4f7754ba03c265bea6f28d5756795/ohash-2.0.2.tgz","_integrity":"sha512-A2CLcYHM2RlOWMz4jKKfAMO9rz7gJ4EV5XbI2CfHMv1hWm24Gc4JqkoA4Dps1H8rD2cbiqXrwLO6mxoIZNyf1Q==","repository":{"url":"git+https://github.com/unjs/ohash.git","type":"git"},"_npmVersion":"10.9.2","description":"Simple object hashing, serialization and comparison utils.","directories":{},"sideEffects":false,"_nodeVersion":"22.13.0","_hasShrinkwrap":false,"devDependencies":{"automd":"^0.3.12","eslint":"^9.20.1","mitata":"^1.0.34","vitest":"^3.0.6","esbuild":"^0.25.0","unbuild":"^3.3.1","prettier":"^3.5.1","typescript":"^5.7.3","@types/node":"^22.13.4","changelogen":"^0.5.7","eslint-config-unjs":"^0.4.2","@vitest/coverage-v8":"^3.0.6"},"_npmOperationalInternal":{"tmp":"tmp/ohash_2.0.2_1740011300297_0.5285481373076888","host":"s3://npm-registry-packages-npm-production"},"readme":"# #️ ohash\n\n<!-- automd:badges bundlephobia codecov -->\n\n[![npm version](https://img.shields.io/npm/v/ohash)](https://npmjs.com/package/ohash)\n[![npm downloads](https://img.shields.io/npm/dm/ohash)](https://npm.chart.dev/ohash)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/ohash)](https://bundlephobia.com/package/ohash)\n[![codecov](https://img.shields.io/codecov/c/gh/unjs/ohash)](https://codecov.io/gh/unjs/ohash)\n\n<!-- /automd -->\n\nSimple object hashing, serialization and comparison utils.\n\n> [!NOTE]\n> ohash v2 is the current release. For the previous API, see the [v1 branch](https://github.com/unjs/ohash/tree/v1) and the [v2.0.1 release notes](https://github.com/unjs/ohash/releases/tag/v2.0.1) for migration.\n\n## Usage\n\nInstall [`ohash`](https://www.npmjs.com/package/ohash):\n\n```sh\n# ✨ Auto-detect (npm, yarn, pnpm, bun or deno)\nnpx nypm i ohash\n```\n\n**Import:**\n\n```js\n// ESM import\nimport { hash, serialize, digest, isEqual } from \"ohash\";\nimport { diff } from \"ohash/utils\";\n\n// Dynamic import\nconst { hash, serialize, digest, isEqual } = await import(\"ohash\");\nconst { diff } = await import(\"ohash/utils\");\n```\n\n<details>\n  <summary>Import from CDN</summary>\n\n```js\nimport { hash, serialize, digest, isEqual } from \"https://esm.sh/ohash\";\nimport { diff } from \"https://esm.sh/ohash/utils\";\n\n// Dynamic import\nconst { hash, serialize, digest, isEqual } = await import(\n  \"https://esm.sh/ohash\"\n);\nconst { diff } = await import(\"https://esm.sh/ohash/utils\");\n```\n\n</details>\n\n## `hash(input)`\n\nHashes any JS value into a string.\n\nThe input is first [serialized](#serializeinput) then it is [hashed](#digeststr).\n\n```js\nimport { hash } from \"ohash\";\n\n// \"g82Nh7Lh3CURFX9zCBhc5xgU0K7L0V1qkoHyRsKNqA4\"\nconsole.log(hash({ foo: \"bar\" }));\n```\n\n## `serialize(input)`\n\nSerializes any input value into a string for hashing.\n\n> [!IMPORTANT]\n> `serialize` method uses best efforts to generate stable serialized values; however, it is not designed for security purposes. Keep in mind that there is always a chance of intentional collisions caused by user input.\n\n```js\nimport { serialize } from \"ohash\";\n\n// \"{foo:'bar'}\"\nconsole.log(serialize({ foo: \"bar\" }));\n```\n\n## `digest(str)`\n\nHashes a string using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm and encodes it in [Base64URL](https://base64.guru/standards/base64url) format.\n\n```ts\nimport { digest } from \"ohash\";\n\n// \"f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk\"\nconsole.log(digest(\"Hello World!\"));\n```\n\n## `isEqual(obj1, obj2)`\n\nCompare two objects using `===` and then fallbacks to compare based on their [serialized](#serializeinput) values.\n\n```js\nimport { isEqual } from \"ohash\";\n\n// true\nconsole.log(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }));\n```\n\n## `diff(obj1, obj2)`\n\nCompare two objects with nested [serialization](#serializeinput-options). Returns an array of changes.\n\nThe returned value is an array of diff entries with `$key`, `$hash`, `$value`, and `$props`. When logging, a string version of the changelog is displayed.\n\n```js\nimport { diff } from \"ohash/utils\";\n\nconst createObject = () => ({\n  foo: \"bar\",\n  nested: {\n    y: 123,\n    bar: {\n      baz: \"123\",\n    },\n  },\n});\n\nconst obj1 = createObject();\nconst obj2 = createObject();\n\nobj2.nested.x = 123;\ndelete obj2.nested.y;\nobj2.nested.bar.baz = 123;\n\nconst changes = diff(obj1, obj2);\n\n// Removed `nested.y`\n// Changed `nested.bar.baz` from `\"123\"` to `123`\n// Added   `nested.x`\nconsole.log(changes.join(\"\\n\"));\n```\n\n## Contribute\n\n- Clone this repository\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## License\n\nMade with 💛 Published under [MIT License](./LICENSE).\n\nObject serialization originally based on [puleos/object-hash](https://github.com/puleos/object-hash) by [Scott Puleo](https://github.com/puleos/).\n\nsha256 implementation originally based on [brix/crypto-js](https://github.com/brix/crypto-js).\n\n## Migration from v1\n\n| v1 | v2 |\n| --- | --- |\n| `objectHash(value)` (stable digest string like `object:1:string:3:foo:...`) | `serialize(value)` for a stable string, or `hash(value)` for a SHA-256 hash |\n| `hash(value)` | Still `hash(value)` (implementation changed; output format differs) |\n\nThere is no v2 helper that reproduces the exact v1 `objectHash` string format. Use `serialize` when you need a stable structural string, and `hash` when you need a short digest.\n","publish_time":1740011300501,"_cnpm_publish_time":1740011300501,"dist-tags":{"1x":"1.1.6","latest":"2.0.12"}}