{"id":16270816,"url":"https://github.com/yarabey/node-hashit","last_synced_at":"2025-03-19T23:30:56.267Z","repository":{"id":74249092,"uuid":"82597893","full_name":"yarabey/node-hashit","owner":"yarabey","description":"Fast node.js hash/stringify object library with sorting and typing","archived":false,"fork":false,"pushed_at":"2017-04-19T13:28:14.000Z","size":23,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T21:41:15.217Z","etag":null,"topics":["crypto","hash","node","object","stringify"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yarabey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-02-20T20:08:45.000Z","updated_at":"2019-05-22T14:55:16.000Z","dependencies_parsed_at":"2023-06-11T18:45:17.581Z","dependency_job_id":null,"html_url":"https://github.com/yarabey/node-hashit","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"9590d687739bc53f1f3ffeff65a7eaf4b92d2235"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarabey%2Fnode-hashit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarabey%2Fnode-hashit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarabey%2Fnode-hashit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarabey%2Fnode-hashit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yarabey","download_url":"https://codeload.github.com/yarabey/node-hashit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244031033,"owners_count":20386534,"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":["crypto","hash","node","object","stringify"],"created_at":"2024-10-10T18:11:41.828Z","updated_at":"2025-03-19T23:30:56.255Z","avatar_url":"https://github.com/yarabey.png","language":"JavaScript","readme":"# node-hashit\nFast node.js hash library with sorting and typing. Provides [Hasher](#Hasher) class. [stringifyit](https://www.npmjs.com/package/stringifyit) provides [stringify Symbol](https://github.com/yarabey/stringifyit#stringifierstringify--symbol) to allow you [customize](https://github.com/yarabey/stringifyit#stringifierstringifycallback--function) stringifying your own classes.\n\nUsing node.js `crypto` module and [stringifyit](https://www.npmjs.com/package/stringifyit) library. For browsers you can use [crypto-browserify](https://github.com/crypto-browserify/crypto-browserify) or only [stringifyit](https://www.npmjs.com/package/stringifyit) library.\n\nSee [benchmarks](#benchmarks) for compare to other libs.\n\n# Install\n`npm i node-hashit --save`\n\n# Features\n\n- Supports node.js \u003e= 4.0.0\n- Supports Map/WeakMap, Set/WeakSet and typed arrays\n- Supports algorithms and encodings from node.js `crypto` module\n- Supports sort Set, Map, object keys and optional sort arrays\n- Supports custom stringify rules for user-defined classes (provided by [stringifyit](https://www.npmjs.com/package/stringifyit) library)\n- One of the fastest hash libraries\n\n# API\n\n## Classes\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#Hasher\"\u003eHasher\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eProvides interface to hash any value\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#hashit\"\u003ehashit(value, [options])\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eHelper for simple hash single value\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"Hasher\"\u003e\u003c/a\u003e\n\n## Hasher\nProvides interface to hash any value\n\n**Kind**: global class  \n\n* [Hasher](#Hasher)\n    * [new Hasher([options])](#new_Hasher_new)\n    * _instance_\n        * [.update(value, [inputEncoding])](#Hasher+update)\n        * [.digest([outputEncoding])](#Hasher+digest) ⇒ \u003ccode\u003estring\u003c/code\u003e \u0026#124; \u003ccode\u003eBuffer\u003c/code\u003e\n    * _inner_\n        * [~options](#Hasher..options) : \u003ccode\u003eStringifier~options\u003c/code\u003e\n\n\u003ca name=\"new_Hasher_new\"\u003e\u003c/a\u003e\n\n### new Hasher([options])\n\n| Param | Type |\n| --- | --- |\n| [options] | \u003ccode\u003e[options](#Hasher..options)\u003c/code\u003e | \n\n\u003ca name=\"Hasher+update\"\u003e\u003c/a\u003e\n\n### hasher.update(value, [inputEncoding])\nUpdates hash with stringified value\n\n**Kind**: instance method of \u003ccode\u003e[Hasher](#Hasher)\u003c/code\u003e  \n**Throws**:\n\n- \u003ccode\u003eHashitRangeError\u003c/code\u003e \n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| value | \u003ccode\u003e\\*\u003c/code\u003e |  |\n| [inputEncoding] | \u003ccode\u003estring\u003c/code\u003e | Input encoding |\n\n\u003ca name=\"Hasher+digest\"\u003e\u003c/a\u003e\n\n### hasher.digest([outputEncoding]) ⇒ \u003ccode\u003estring\u003c/code\u003e \u0026#124; \u003ccode\u003eBuffer\u003c/code\u003e\n**Kind**: instance method of \u003ccode\u003e[Hasher](#Hasher)\u003c/code\u003e  \n**See**: [https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding](https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| [outputEncoding] | \u003ccode\u003estring\u003c/code\u003e | Output encoding (if `null` Buffer will be returned) |\n\n\u003ca name=\"Hasher..options\"\u003e\u003c/a\u003e\n\n### Hasher~options : \u003ccode\u003eStringifier~options\u003c/code\u003e\n**Kind**: inner typedef of \u003ccode\u003e[Hasher](#Hasher)\u003c/code\u003e  \n**See**\n\n- [https://nodejs.org/api/crypto.html#crypto_class_hash](https://nodejs.org/api/crypto.html#crypto_class_hash)\n- [https://github.com/yarabey/stringifyit#stringifieroptions--object](https://github.com/yarabey/stringifyit#stringifieroptions--object)\n\n**Properties**\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| algorithm | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;md5\u0026quot;\u003c/code\u003e | Hash algorithm |\n| inputEncoding | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;utf8\u0026quot;\u003c/code\u003e | Input encoding |\n| outputEncoding | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;hex\u0026quot;\u003c/code\u003e | Output encoding (if `null` Buffer will be returned) |\n\n\u003ca name=\"hashit\"\u003e\u003c/a\u003e\n\n## hashit(value, [options]) ⇒ \u003ccode\u003estring\u003c/code\u003e\nHelper for simple hash single value\n\n**Kind**: global function  \n\n| Param | Type |\n| --- | --- |\n| value | \u003ccode\u003e\\*\u003c/code\u003e | \n| [options] | \u003ccode\u003e[options](#Hasher..options)\u003c/code\u003e | \n\n**Example**  \n```js\nconst {hashit} = require('node-hashit');\n\nhashit({key: 'value', value: 'key'}) === hashit({value: 'key', key: 'value'}); // true\nhashit(new Set(['value1', 'value2'])) === hashit(new Set(['value2', 'value1'])); // true\nhashit(new Map([['key', 'value'], ['value', 'key']])) === hashit(new Map([['value', 'key'], ['key', 'value']])); // true\nhashit([1, 2, 3]) === hashit([1, 2, 3]); // true\nhashit([1, 2, 3], {sortArrays: true}) === hashit([1, 3, 2], {sortArrays: true}); // true\n\nhashit([1, 2, 3]) === hashit([1, 3, 2]); // false\nhashit(5) === hashit('5'); // false\n```\n\n# Benchmarks\n\nBenchmarked with Node.js v6.9.5\n\n## Usage\n\n* `npm run benchOps` to run comparison operations/second with other libs for different cases\n* `npm run benchHeap` to run comparison heap using with other libs for complex cases\n* `npm run benchSpeed` to run benchmarking hashit operations/second for different cases\n\n## Results\n\n### Operations/second comparison (+includePrimitiveTypes +sortArrays) [source](bench/ops.js)\n\n```\nhashit/array x 255,710 ops/sec ±1.54% (86 runs sampled)\nnodeObjectHash/array x 174,084 ops/sec ±2.11% (84 runs sampled)\nhashObject/array x 140,706 ops/sec ±1.56% (82 runs sampled)\nobjectHash/array x 48,767 ops/sec ±1.55% (88 runs sampled)\n\nhashit/object x 426,051 ops/sec ±1.18% (82 runs sampled)\nnodeObjectHash/object x 354,923 ops/sec ±1.59% (83 runs sampled)\nhashObject/object x 350,324 ops/sec ±1.40% (84 runs sampled)\nobjectHash/object x 27,030 ops/sec ±1.39% (83 runs sampled)\n\nhashit/nestedObject x 23,762 ops/sec ±1.33% (87 runs sampled)\nnodeObjectHash/nestedObject x 16,252 ops/sec ±4.74% (81 runs sampled)\nhashObject/nestedObject x 17,689 ops/sec ±1.92% (85 runs sampled)\nobjectHash/nestedObject x 657 ops/sec ±1.27% (84 runs sampled)\n\nhashit/complexObject_5items x 19,677 ops/sec ±1.54% (86 runs sampled)\nnodeObjectHash/complexObject_5items x 9,922 ops/sec ±1.58% (87 runs sampled)\nhashObject/complexObject_5items x 2,561 ops/sec ±1.65% (84 runs sampled)\nobjectHash/complexObject_5items x 1,433 ops/sec ±1.37% (85 runs sampled)\n\nhashit/complexObject_10items x 10,385 ops/sec ±1.58% (86 runs sampled)\nnodeObjectHash/complexObject_10items x 4,906 ops/sec ±2.10% (86 runs sampled)\nhashObject/complexObject_10items x 1,331 ops/sec ±1.21% (85 runs sampled)\nobjectHash/complexObject_10items x 722 ops/sec ±1.65% (82 runs sampled)\n\nhashit/complexObject_100items x 944 ops/sec ±1.55% (84 runs sampled)\nnodeObjectHash/complexObject_100items x 483 ops/sec ±1.72% (84 runs sampled)\nhashObject/complexObject_100items x 129 ops/sec ±1.35% (70 runs sampled)\nobjectHash/complexObject_100items x 66.61 ops/sec ±1.44% (65 runs sampled)\n\nhashit faster in cases: array, object, nestedObject, complexObject_5items, complexObject_10items, complexObject_100items (6)\n\n```\n\n### Heap using comparison  (+includePrimitiveTypes +sortArrays) [source](bench/heap.js)\n\n| Library                               | Time (ms)  | Memory (Mb)        |\n|---------------------------------------|------------|--------------------|\n| hashit-0.3.2                          | 2120.435   | 42                 |\n| node-object-hash-1.2.0                | 2635.670   | 39                 |\n| object-hash-1.1.5                     | 17325.391  | 62                 |\n| hash-object-0.1.7                     | 9762.324   | 51                 |\n\n### Operations/second hashit benchmarking (+includePrimitiveTypes -sortArrays) [source](bench/speed.js)\n\n```\narray x 362,314 ops/sec ±0.97% (84 runs sampled)\nobject x 434,386 ops/sec ±1.78% (85 runs sampled)\nnestedObject x 23,896 ops/sec ±1.35% (85 runs sampled)\ncomplexObject_5items x 20,820 ops/sec ±1.56% (86 runs sampled)\ncomplexObject_10items x 10,930 ops/sec ±1.55% (84 runs sampled)\ncomplexObject_100items x 981 ops/sec ±1.68% (83 runs sampled)\nset x 119,927 ops/sec ±2.33% (83 runs sampled)\nmap x 111,666 ops/sec ±2.27% (83 runs sampled)\n```\n\n## Links\n\n* [node-object-hash](https://www.npmjs.com/package/node-object-hash) - Fast hasher with nice interface\n* [object-hash](https://www.npmjs.com/package/object-hash) - Slow but popular hash lib, supports browser using\n* [hash-object](https://www.npmjs.com/package/hash-object) - Old and not supporting lib, but useful for simple objects\n\n\n# License\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyarabey%2Fnode-hashit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyarabey%2Fnode-hashit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyarabey%2Fnode-hashit/lists"}