Generate hashes from javascript objects in node and the browser.
Installations
npm install object-hash
Developer Guide
Typescript
No
Module System
CommonJS, UMD
Min. Node Version
>= 6
Node Version
14.18.0
NPM Version
6.14.15
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
puleos
Download Statistics
Total Downloads
3,461,298,294
Last Day
214,370
Last Week
214,370
Last Month
66,239,701
Last Year
966,426,699
GitHub Statistics
1,426 Stars
222 Commits
145 Forks
11 Watching
3 Branches
27 Contributors
Bundle Size
33.78 kB
Minified
10.30 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.0.0
Package Id
object-hash@3.0.0
Unpacked Size
57.48 kB
Size
17.81 kB
File Count
5
NPM Version
6.14.15
Node Version
14.18.0
Total Downloads
Cumulative downloads
Total Downloads
3,461,298,294
Last day
0%
214,370
Compared to previous day
Last week
-98.5%
214,370
Compared to previous week
Last month
-9.9%
66,239,701
Compared to previous month
Last year
15.4%
966,426,699
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
object-hash
Generate hashes from objects and values in node and the browser. Uses node.js crypto module for hashing. Supports SHA1 and many others (depending on the platform) as well as custom streams (e.g. CRC32).
- Hash values of any type.
- Supports a keys only option for grouping similar objects with different values.
1var hash = require('object-hash'); 2 3hash({foo: 'bar'}) // => '67b69634f9880a282c14a0f0cb7ba20cf5d677e9' 4hash([1, 2, 2.718, 3.14159]) // => '136b9b88375971dff9f1af09d7356e3e04281951'
Versioning Disclaimer
Starting with version 1.1.8
(released April 2017), new versions will consider
the exact returned hash part of the API contract, i.e. changes that will affect
hash values will be considered semver-major
. Previous versions may violate
that expectation.
For more information, see this discussion.
hash(value, options)
Generate a hash from any object or type. Defaults to sha1 with hex encoding.
algorithm
hash algo to be used: 'sha1', 'md5', 'passthrough'. default: sha1- 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. - This also supports the
passthrough
algorith, which will return the information that would otherwise have been hashed.
- This supports the algorithms returned by
excludeValues
{true|false} hash object keys, values ignored. default: falseencoding
hash encoding, supports 'buffer', 'hex', 'binary', 'base64'. default: hexignoreUnknown
{true|*false} ignore unknown object types. default: falsereplacer
optional function that replaces values before hashing. default: accept all valuesrespectFunctionProperties
{true|false} Whether properties on functions are considered when hashing. default: truerespectFunctionNames
{true|false} considername
property of functions for hashing. default: truerespectType
{true|false} Whether special type attributes (.prototype
,.__proto__
,.constructor
) are hashed. default: trueunorderedArrays
{true|false} Sort all arrays before hashing. Note that this affects all collections, i.e. including typed arrays, Sets, Maps, etc. default: falseunorderedSets
{true|false} SortSet
andMap
instances before hashing, i.e. makehash(new Set([1, 2])) == hash(new Set([2, 1]))
returntrue
. default: trueunorderedObjects
{true|false} Sort objects before hashing, i.e. makehash({ x: 1, y: 2 }) === hash({ y: 2, x: 1 })
. default: trueexcludeKeys
optional function for excluding specific key(s) from hashing, if true is returned then exclude from hash. default: include all keys
hash.sha1(value)
Hash using the sha1 algorithm.
Note that SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
Sugar method, equivalent to hash(value, {algorithm: 'sha1'})
hash.keys(value)
Hash object keys using the sha1 algorithm, values ignored.
Sugar method, equivalent to hash(value, {excludeValues: true})
hash.MD5(value)
Hash using the md5 algorithm.
Note that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
Sugar method, equivalent to hash(value, {algorithm: 'md5'})
hash.keysMD5(value)
Hash object keys using the md5 algorithm, values ignored.
Note that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
Sugar method, equivalent to hash(value, {algorithm: 'md5', excludeValues: true})
hash.writeToStream(value, [options,] stream)
Write the information that would otherwise have been hashed to a stream, e.g.:
1hash.writeToStream({foo: 'bar', a: 42}, {respectType: false}, process.stdout)
2// => e.g. 'object:a:number:42foo:string:bar'
Installation
node:
1npm install object-hash
browser: /dist/object_hash.js
1<script src="object_hash.js" type="text/javascript"></script> 2 3<script> 4 var hash = objectHash.sha1({foo:'bar'}); 5 6 console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9 7</script>
Example usage
1var hash = require('object-hash'); 2 3var peter = { name: 'Peter', stapler: false, friends: ['Joanna', 'Michael', 'Samir'] }; 4var michael = { name: 'Michael', stapler: false, friends: ['Peter', 'Samir'] }; 5var bob = { name: 'Bob', stapler: true, friends: [] }; 6 7/*** 8 * sha1 hex encoding (default) 9 */ 10hash(peter); 11// 14fa461bf4b98155e82adc86532938553b4d33a9 12hash(michael); 13// 4b2b30e27699979ce46714253bc2213010db039c 14hash(bob); 15// 38d96106bc8ef3d8bd369b99bb6972702c9826d5 16 17/*** 18 * hash object keys, values ignored 19 */ 20hash(peter, { excludeValues: true }); 21// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c 22hash(michael, { excludeValues: true }); 23// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c 24hash.keys(bob); 25// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c 26 27/*** 28 * hash object, ignore specific key(s) 29 */ 30hash(peter, { excludeKeys: function(key) { 31 if ( key === 'friends') { 32 return true; 33 } 34 return false; 35 } 36}); 37// 66b7d7e64871aa9fda1bdc8e88a28df797648d80 38 39/*** 40 * md5 base64 encoding 41 */ 42hash(peter, { algorithm: 'md5', encoding: 'base64' }); 43// 6rkWaaDiG3NynWw4svGH7g== 44hash(michael, { algorithm: 'md5', encoding: 'base64' }); 45// djXaWpuWVJeOF8Sb6SFFNg== 46hash(bob, { algorithm: 'md5', encoding: 'base64' }); 47// lFzkw/IJ8/12jZI0rQeS3w==
Legacy Browser Support
IE <= 8 and Opera <= 11 support dropped in version 0.3.0. If you require legacy browser support you must either use an ES5 shim or use version 0.2.5 of this module.
Development
1git clone https://github.com/puleos/object-hash
Node Docker Wrapper
If you want to stand this up in a docker container, you should take at look
at the project.
gulp tasks
gulp watch
(default) watch files, test and lint on change/addgulp test
unit testsgulp karma
browser unit testsgulp lint
jshintgulp dist
create browser version in /dist
License
MIT
Changelog
v2.0.0
Only Node.js versions >= 6.0.0
are being tested in CI now.
No other breaking changes were introduced.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 18/28 approved changesets -- score normalized to 6
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/puleos/object-hash/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/puleos/object-hash/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/puleos/object-hash/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/puleos/object-hash/main.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:53
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 2 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 21 are checked with a SAST tool
Reason
50 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-866w-wm4h-95c6
- Warn: Project is vulnerable to: GHSA-cfgr-75jx-h88g
- Warn: Project is vulnerable to: GHSA-r737-347m-wqc7
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m
- Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c
- Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-6fx8-h7jm-663j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-qg8p-v9q4-gh34
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472
- Warn: Project is vulnerable to: GHSA-34r7-q49f-h37c
- Warn: Project is vulnerable to: GHSA-c9f4-xj24-8jqx
- Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
Score
3.4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to object-hash
node-object-hash
Node.js object hash library with properties/arrays sorting to provide constant hashes
@types/object-hash
TypeScript definitions for object-hash
cache-base
Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.
hash-it
Hash any object based on its value