{"id":15379580,"url":"https://github.com/blond/hash-set","last_synced_at":"2025-06-11T03:37:19.951Z","repository":{"id":57152669,"uuid":"52831056","full_name":"blond/hash-set","owner":"blond","description":":hash: Set with custom equality comparisons","archived":false,"fork":false,"pushed_at":"2020-06-01T01:13:25.000Z","size":110,"stargazers_count":6,"open_issues_count":4,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-17T02:19:01.380Z","etag":null,"topics":["built-in-objects","equality","hash","same-value-zero","set"],"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/blond.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-29T22:56:43.000Z","updated_at":"2018-05-04T22:42:17.000Z","dependencies_parsed_at":"2022-09-06T18:10:55.614Z","dependency_job_id":null,"html_url":"https://github.com/blond/hash-set","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blond%2Fhash-set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blond%2Fhash-set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blond%2Fhash-set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blond%2Fhash-set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blond","download_url":"https://codeload.github.com/blond/hash-set/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blond%2Fhash-set/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259192663,"owners_count":22819453,"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":["built-in-objects","equality","hash","same-value-zero","set"],"created_at":"2024-10-01T14:19:24.501Z","updated_at":"2025-06-11T03:37:19.927Z","avatar_url":"https://github.com/blond.png","language":"JavaScript","readme":"hash-set\n========\n\n[![NPM Status][npm-img]][npm]\n[![Travis Status][test-img]][travis]\n[![Coverage Status][coveralls-img]][coveralls]\n\n[npm]:           https://www.npmjs.org/package/hash-set\n[npm-img]:       https://img.shields.io/npm/v/hash-set.svg\n\n[travis]:        https://travis-ci.org/blond/hash-set\n[test-img]:      https://img.shields.io/travis/blond/hash-set/master.svg?label=tests\n\n[coveralls]:     https://coveralls.io/r/blond/hash-set\n[coveralls-img]: https://img.shields.io/coveralls/blond/hash-set/master.svg\n\nThe original [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) uses [Same-value-zero](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness) equality.\n\nUse this package if you need custom comparison behavior.\n\nInstall\n-------\n\n```\n$ npm install --save hash-set\n```\n\nUsage\n-----\n\n```js\nimport hashSet from 'hash-set';\n\n// Create Set class which compares objects with JSON.stringify\nconst JSONSet = hashSet(JSON.stringify);\n// Create instance of JSONSet\nconst mySet = new JSONSet();\n\nmySet.add({ a: 1 });\nmySet.add({ b: 2 });\n\nmySet.has({ a: 1 }); // true\nmySet.has({ b: 2 }); // true\nmySet.has({ c: 3 }); // false, `{ c: 3 }` has not been added to the set\n\nmySet.size; // 2\n\nmySet.delete({ a: 1 }); // removes `{ a: 1 }` from the set\nmySet.has({ a: 1 });    // false, `{ a: 1 }` has been removed\n\nmySet.size; // 1\n```\n\nAPI\n---\n\n### hashSet(hashFn)\n\nReturns `Set` class with custom equality comparisons.\n\n#### hashFn\n\nType: `function`\n\nThe function to determine the unique of value.\n\n`HashSet` executes a provided function every time you call `add(value)`, `has(value)`, `delete(value)`.\n\nThe result of `hashFn(value)` will be used for comparison with the values of `HashSet`. For comparison will be used [Same-value-zero](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness).\n\n**Example**\n\n```js\nconst mySet = new Set();\n\nmySet.add(1);   // value has been added to the set\nmySet.add('1'); // value has been added to the set\n                // because `Object.is(1, '1')` is `false`\n\nconsole.log(mySet); // Set { 1, '1' }\n```\n\n```js\nimport hashSet from 'hash-set';\n\nfunction hashFn(value) {\n    return value.toString();\n}\n\nconst StringSet = hashSet(hashFn);\nconst mySet = new StringSet();\n\nmySet.add(1);   // value has been added to the set\nmySet.add('1'); // value has not been added to the set\n                // because `Object.is(hashFn(1), hashFn('1'))` is `true`\n\nconsole.log(mySet); // Set { 1 }\n```\n\n\nLicense\n-------\n\nMIT © [Andrew Abramov](https://github.com/blond)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblond%2Fhash-set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblond%2Fhash-set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblond%2Fhash-set/lists"}