{"id":13484116,"url":"https://github.com/mcollina/hyperid","last_synced_at":"2025-04-10T03:48:56.114Z","repository":{"id":37276147,"uuid":"66265596","full_name":"mcollina/hyperid","owner":"mcollina","description":"Uber-fast unique id generation, for Node.js and the browser","archived":false,"fork":false,"pushed_at":"2024-08-31T14:57:28.000Z","size":120,"stargazers_count":735,"open_issues_count":3,"forks_count":39,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T02:08:25.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mcollina.png","metadata":{"files":{"readme":"README.md","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":"2016-08-22T11:06:10.000Z","updated_at":"2025-04-02T18:17:45.000Z","dependencies_parsed_at":"2024-10-20T11:08:35.204Z","dependency_job_id":null,"html_url":"https://github.com/mcollina/hyperid","commit_stats":{"total_commits":91,"total_committers":24,"mean_commits":"3.7916666666666665","dds":0.4285714285714286,"last_synced_commit":"88e4f0f7058bfa8e8e856bbeb883c438982fa584"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Fhyperid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Fhyperid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Fhyperid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Fhyperid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcollina","download_url":"https://codeload.github.com/mcollina/hyperid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154995,"owners_count":21056542,"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:19.596Z","updated_at":"2025-04-10T03:48:56.096Z","avatar_url":"https://github.com/mcollina.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Generation"],"sub_categories":["JavaScript"],"readme":"# hyperid\n\n[![Build Status](https://img.shields.io/github/workflow/status/mcollina/hyperid/CI)](https://github.com/mcollina/hyperid/actions)\n\nUber-fast unique id generation, for Node.js and the browser.\nHere are the benchmarks:\n\n```\ncrypto.randomUUID x 12,969,725 ops/sec ±0.88% (91 runs sampled)\nhashids process.hrtime x 419,350 ops/sec ±0.66% (94 runs sampled)\nhashids counter x 819,049 ops/sec ±0.58% (93 runs sampled)\nshortid x 40,820 ops/sec ±2.49% (87 runs sampled)\ncrypto.random x 372,773 ops/sec ±2.39% (84 runs sampled)\nnid x 1,614,450 ops/sec ±0.38% (93 runs sampled)\nuuid.v4 x 1,446,051 ops/sec ±0.60% (98 runs sampled)\nnapiRsUuid.v4 x 8,676,151 ops/sec ±0.49% (97 runs sampled)\nuuid.v1 x 2,051,072 ops/sec ±0.15% (99 runs sampled)\nnanoid x 4,293,733 ops/sec ±0.31% (97 runs sampled)\nhyperid - variable length x 25,937,129 ops/sec ±1.48% (91 runs sampled)\nhyperid - fixed length x 24,970,478 ops/sec ±1.48% (92 runs sampled)\nhyperid - fixed length, url safe x 25,856,735 ops/sec ±1.93% (92 runs sampled)\n\nFastest is hyperid - variable length,hyperid - fixed length, url safe\nSlowest is shortid\n```\n\n_Note:_ Benchmark run with Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz and Node.js v22.0.0\n\nAs you can see the native `crypto.randomUUID` is almost as fast as hyperid\non Node.js v16, but not on v14.\n\n## Install\n\n```\nnpm i hyperid --save\n```\n\n## Example\n\n```js\n'use strict'\n\nconst hyperid = require('hyperid')\nconst instance = hyperid()\n\nconst id = instance()\n\nconsole.log(id)\nconsole.log(instance())\nconsole.log(hyperid.decode(id))\nconsole.log(hyperid.decode(instance()))\n```\n\n## API\n\n### hyperid([fixedLength || options])\n\nReturns a function to generate unique ids.\nThe function can accept one of the following parameters:\n- `fixedLength: Boolean`\nIf *fixedLength* is `true` the function will always generate an id\nthat is 33 characters in length, by default `fixedLength` is `false`.\n- `options: Object`\nIf `{ fixedLength: true }` is passed in, the function will always generate an id\nthat is 33 characters in length, by default `fixedLength` is `false`.\nIf `{ urlSafe: true }` is passed in, the function will generate url safe ids according to RFC4648.\nIf `{ startFrom: \u003cint\u003e }` is passed in, the first counter will start from that\nnumber, which must be between 0 and 2147483647. Fractions are discarded, only the\ninteger part matters.\nIf `{ maxInt: \u003cint\u003e }` is passed in, the uuid will be re-generated once the *maxInt* is reached. The lesser the *maxInt*, higher the performance because of SMI (a V8 optimization).\n\n### instance()\n\nReturns an unique id.\n\n### instance.uuid\n\nThe uuid used to generate the ids, it will change over time.\nIf `maxInt` is provided in options, then it will regenerated every `maxInt`, else it will be regenerated every `Math.pow(2, 31) - 1` to keep the integer a SMI (a V8 optimization). \n\n### hyperid.decode(id, [options])\n\nDecode the unique id into its two components, a `uuid` and a counter.\nIf you are generating *url safe* ids, you must pass `{ urlSafe: true }` as option.\nIt returns:\n\n```js\n{\n  uuid: '049b7020-c787-41bf-a1d2-a97612c11418',\n  count: 1\n}\n```\n\nThis is aliased as `instance.decode`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcollina%2Fhyperid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcollina%2Fhyperid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcollina%2Fhyperid/lists"}