{"id":13483134,"url":"https://github.com/puleos/object-hash","last_synced_at":"2025-05-13T20:13:24.498Z","repository":{"id":14758706,"uuid":"17480011","full_name":"puleos/object-hash","owner":"puleos","description":"Generate hashes from javascript objects in node and the browser.","archived":false,"fork":false,"pushed_at":"2024-07-23T00:23:59.000Z","size":1644,"stargazers_count":1444,"open_issues_count":40,"forks_count":148,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-05T14:44:54.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/puleos.png","metadata":{"files":{"readme":"readme.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-06T14:16:56.000Z","updated_at":"2025-05-05T03:08:09.000Z","dependencies_parsed_at":"2024-01-13T18:21:06.155Z","dependency_job_id":"da49319c-85e3-4f78-b159-bc7fba575945","html_url":"https://github.com/puleos/object-hash","commit_stats":{"total_commits":206,"total_committers":31,"mean_commits":6.645161290322581,"dds":0.6990291262135923,"last_synced_commit":"1dbd457bf4b73e010e4a5b658792f5a1de9192ad"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puleos%2Fobject-hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puleos%2Fobject-hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puleos%2Fobject-hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puleos%2Fobject-hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puleos","download_url":"https://codeload.github.com/puleos/object-hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253241355,"owners_count":21876806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:08.504Z","updated_at":"2025-05-13T20:13:19.491Z","avatar_url":"https://github.com/puleos.png","language":"JavaScript","readme":"# object-hash\n\nGenerate hashes from objects and values in node and the browser.  Uses node.js\ncrypto module for hashing.  Supports SHA1 and many others (depending on the platform)\nas well as custom streams (e.g. CRC32).\n\n[![NPM](https://nodei.co/npm/object-hash.png?downloads=true\u0026downloadRank=true)](https://www.npmjs.com/package/object-hash)\n\n[![CI](https://github.com/puleos/object-hash/actions/workflows/main.yml/badge.svg)](https://github.com/puleos/object-hash/actions/workflows/main.yml)\n[![Coverage Status](https://coveralls.io/repos/puleos/object-hash/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/puleos/object-hash?branch=master)\n\n* Hash values of any type.\n* Supports a keys only option for grouping similar objects with different values.\n\n```js\nvar hash = require('object-hash');\n\nhash({foo: 'bar'}) // =\u003e '67b69634f9880a282c14a0f0cb7ba20cf5d677e9'\nhash([1, 2, 2.718, 3.14159]) // =\u003e '136b9b88375971dff9f1af09d7356e3e04281951'\n```\n\n## Versioning Disclaimer\n\nStarting with version `1.1.8` (released April 2017), new versions will consider\nthe exact returned hash part of the API contract, i.e. changes that will affect\nhash values will be considered `semver-major`. Previous versions may violate\nthat expectation.\n\nFor more information, see [this discussion](https://github.com/puleos/object-hash/issues/30).\n\n## hash(value, options)\n\nGenerate a hash from any object or type.  Defaults to sha1 with hex encoding.\n\n* `algorithm` hash algo to be used: 'sha1', 'md5', 'passthrough'. default: sha1\n  * This supports the algorithms returned by `crypto.getHashes()`. Note that the default of SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.\n  * This also supports the `passthrough` algorith, which will return the information that would otherwise have been hashed.\n* `excludeValues` {true|false} hash object keys, values ignored. default: false\n* `encoding` hash encoding, supports 'buffer', 'hex', 'binary', 'base64'. default: hex\n* `ignoreUnknown` {true|*false} ignore unknown object types. default: false\n* `replacer` optional function that replaces values before hashing. default: accept all values\n* `respectFunctionProperties` {true|false} Whether properties on functions are considered when hashing. default: true\n* `respectFunctionNames` {true|false} consider `name` property of functions for hashing. default: true\n* `respectType` {true|false} Whether special type attributes (`.prototype`, `.__proto__`, `.constructor`)\n   are hashed. default: true\n* `unorderedArrays` {true|false} Sort all arrays before hashing. Note that this affects *all* collections,\n   i.e. including typed arrays, Sets, Maps, etc. default: false\n* `unorderedSets` {true|false} Sort `Set` and `Map` instances before hashing, i.e. make\n  `hash(new Set([1, 2])) == hash(new Set([2, 1]))` return `true`. default: true\n* `unorderedObjects` {true|false} Sort objects before hashing, i.e. make `hash({ x: 1, y: 2 }) === hash({ y: 2, x: 1 })`. default: true\n* `excludeKeys` optional function for excluding specific key(s) from hashing, if true is returned then exclude from hash. default: include all keys\n\n## hash.sha1(value)\n\nHash using the sha1 algorithm.\n\nNote that SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.\n\n*Sugar method, equivalent to* `hash(value, {algorithm: 'sha1'})`\n\n## hash.keys(value)\n\nHash object keys using the sha1 algorithm, values ignored.\n\n*Sugar method, equivalent to* `hash(value, {excludeValues: true})`\n\n## hash.MD5(value)\n\nHash using the md5 algorithm.\n\nNote that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.\n\n*Sugar method, equivalent to* `hash(value, {algorithm: 'md5'})`\n\n## hash.keysMD5(value)\n\nHash object keys using the md5 algorithm, values ignored.\n\nNote that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.\n\n*Sugar method, equivalent to* `hash(value, {algorithm: 'md5', excludeValues: true})`\n\n## hash.writeToStream(value, [options,] stream)\n\nWrite the information that would otherwise have been hashed to a stream, e.g.:\n\n```js\nhash.writeToStream({foo: 'bar', a: 42}, {respectType: false}, process.stdout)\n// =\u003e e.g. 'object:a:number:42foo:string:bar'\n```\n\n## Installation\n\nnode:\n\n```js\nnpm install object-hash\n```\n\nbrowser: */dist/object_hash.js*\n\n```html\n\u003cscript src=\"object_hash.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  var hash = objectHash.sha1({foo:'bar'});\n\n  console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9\n\u003c/script\u003e\n```\n\n## Example usage\n\n```js\nvar hash = require('object-hash');\n\nvar peter = { name: 'Peter', stapler: false, friends: ['Joanna', 'Michael', 'Samir'] };\nvar michael = { name: 'Michael', stapler: false, friends: ['Peter', 'Samir'] };\nvar bob = { name: 'Bob', stapler: true, friends: [] };\n\n/***\n * sha1 hex encoding (default)\n */\nhash(peter);\n// 14fa461bf4b98155e82adc86532938553b4d33a9\nhash(michael);\n// 4b2b30e27699979ce46714253bc2213010db039c\nhash(bob);\n// 38d96106bc8ef3d8bd369b99bb6972702c9826d5\n\n/***\n * hash object keys, values ignored\n */\nhash(peter, { excludeValues: true });\n// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c\nhash(michael, { excludeValues: true });\n// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c\nhash.keys(bob);\n// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c\n\n/***\n * hash object, ignore specific key(s)\n */\nhash(peter, { excludeKeys: function(key) {\n    if ( key === 'friends') {\n      return true;\n    }\n    return false;\n  }\n});\n// 66b7d7e64871aa9fda1bdc8e88a28df797648d80\n\n/***\n * md5 base64 encoding\n */\nhash(peter, { algorithm: 'md5', encoding: 'base64' });\n// 6rkWaaDiG3NynWw4svGH7g==\nhash(michael, { algorithm: 'md5', encoding: 'base64' });\n// djXaWpuWVJeOF8Sb6SFFNg==\nhash(bob, { algorithm: 'md5', encoding: 'base64' });\n// lFzkw/IJ8/12jZI0rQeS3w==\n```\n\n## Legacy Browser Support\n\nIE \u003c= 8 and Opera \u003c= 11 support dropped in version 0.3.0.  If you require\nlegacy browser support you must either use an ES5 shim or use version 0.2.5\nof this module.\n\n## Development\n\n```sh-session\ngit clone https://github.com/puleos/object-hash\n```\n\n## Node Docker Wrapper\n\nIf you want to stand this up in a docker container, you should take at look\nat the [![node-object-hash](https://github.com/bean5/node-object-hash)](https://github.com/bean5/node-object-hash) project.\n\n### Package scripts\n\n* `gulp watch` (default) watch files, test and lint on change/add\n* `gulp test` unit tests\n* `gulp karma` browser unit tests\n* `npm run lint` linter\n* `gulp dist` create browser version in /dist\n\n## License\n\nMIT\n\n## Changelog\n\n### v3.0.0\n\nA change was introduced to the hash in order to differentiate signed and unsigned typed arrays.\nAs per our semantic versioning guarantee, this was considered a breaking change.\n\n### v2.0.0\n\nOnly Node.js versions `\u003e= 6.0.0` are being tested in CI now.\nNo other breaking changes were introduced.\n","funding_links":[],"categories":["JavaScript","Repository"],"sub_categories":["Crypto"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuleos%2Fobject-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuleos%2Fobject-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuleos%2Fobject-hash/lists"}