{"id":13411119,"url":"https://github.com/lukeed/uid","last_synced_at":"2025-10-09T18:23:38.685Z","repository":{"id":41325477,"uuid":"244573944","full_name":"lukeed/uid","owner":"lukeed","description":"A tiny (130B to 205B) and fast utility to generate random IDs of fixed length","archived":false,"fork":false,"pushed_at":"2024-09-27T06:12:32.000Z","size":43,"stargazers_count":665,"open_issues_count":1,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-02T01:15:43.566Z","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/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"lukeed"}},"created_at":"2020-03-03T07:51:36.000Z","updated_at":"2025-09-30T19:29:55.000Z","dependencies_parsed_at":"2022-09-02T11:01:11.275Z","dependency_job_id":"3be687e3-2d11-428b-8d36-d71b5eb0b844","html_url":"https://github.com/lukeed/uid","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":0.06060606060606055,"last_synced_commit":"421297570d40d6705c3a50a582466018251630c9"},"previous_names":["lukeed/foid"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/lukeed/uid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/uid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fuid/sbom","scorecard":{"id":604464,"data":{"date":"2025-08-11","repo":{"name":"github.com/lukeed/uid","commit":"b93753336bb89e227737f79cb2df59fcd5897662"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Code-Review","score":1,"reason":"Found 2/19 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/uid/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/uid/ci.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:20","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:28","Warn: downloadThenRun not pinned by hash: .github/workflows/ci.yml:35","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 npmCommand dependencies pinned","Info:   0 out of   1 downloadThenRun dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"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"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 14 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T01:15:39.400Z","repository_id":41325477,"created_at":"2025-08-21T01:15:39.400Z","updated_at":"2025-08-21T01:15:39.400Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277952596,"owners_count":25904758,"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","status":"online","status_checked_at":"2025-10-02T02:00:08.890Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-30T20:01:11.526Z","updated_at":"2025-10-09T18:23:38.669Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript","ID \u0026 Unique IDs","Generation","Unique ID Generation"],"sub_categories":["JavaScript","Reactive Programming"],"readme":"# uid [![CI](https://github.com/lukeed/uid/workflows/CI/badge.svg)](https://github.com/lukeed/uid/actions) [![licenses](https://licenses.dev/b/npm/uid)](https://licenses.dev/npm/uid) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/uid)](https://codecov.io/gh/lukeed/uid)\n\n\u003e A tiny (130B to 205B) and [fast](#benchmarks) utility to randomize unique IDs of fixed length\n\n_**Fast object IDs.** Available for Node.js and the browser._\u003cbr\u003eGenerate **randomized** output strings of fixed length using lowercase alphanumeric characters (`a-z0-9`). To produce IDs in UUID.V4 format, please see [`@lukeed/uuid`](https://github.com/lukeed/uuid).\n\nThis module offers multiple [modes](#modes) for your needs:\n\n* [`uid`](#uid)\u003cbr\u003e_The default is \"non-secure\", which uses `Math.random` to produce UUIDs._\n* [`uid/secure`](#uidsecure)\u003cbr\u003e_The \"secure\" mode produces cryptographically secure (CSPRNG) UUIDs using the current environment's `crypto` module._\n* [`uid/single`](#uidsingle)\u003cbr\u003e_The \"single\" mode does not maintain an internal cache, which makes it ideal for short-lived environments._\n\nAdditionally, this module is preconfigured for native ESM support in Node.js with fallback to CommonJS. It will also work with any Rollup and webpack configuration, regardless of the \"mode\" selected.\n\n## Install\n\n```\n$ npm install --save uid\n```\n\n## Modes\n\nThere are three \"versions\" of `uid` available:\n\n#### `uid`\n\u003e **Size (gzip):** 174 bytes\u003cbr\u003e\n\u003e **Availability:** [CommonJS](https://unpkg.com/uid/dist/index.js), [ES Module](https://unpkg.com/uid/dist/index.mjs), [UMD](https://unpkg.com/uid/dist/index.min.js)\n\nRelies on `Math.random`, which means that, while faster, this mode **is not** cryptographically secure. \u003cbr\u003eWorks in Node.js and all browsers. \u003cbr\u003eAlphabet: ***Hexadecimal***\n\n#### `uid/secure`\n\u003e **Size (gzip):** 205 bytes\u003cbr\u003e\n\u003e **Availability:** [CommonJS](https://unpkg.com/uid/secure/index.js), [ES Module](https://unpkg.com/uid/secure/index.mjs), [UMD](https://unpkg.com/uid/secure/index.min.js)\n\nRelies on the environment's `crypto` module in order to produce cryptographically secure (CSPRNG) values. \u003cbr\u003eWorks in all versions of Node.js. Works in all browsers with [`crypto.getRandomValues()` support](https://caniuse.com/#feat=getrandomvalues). \u003cbr\u003eAlphabet: ***Hexadecimal***\n\n#### `uid/single`\n\u003e **Size (gzip):** 131 bytes\u003cbr\u003e\n\u003e **Availability:** [CommonJS](https://unpkg.com/uid/single/index.js), [ES Module](https://unpkg.com/uid/single/index.mjs), [UMD](https://unpkg.com/uid/single/index.min.js)\n\nRelies on `Math.random`, which means that this mode **is not** cryptographically secure. \u003cbr\u003eDoes **not** maintain an internal buffer, which makes this mode ideal for single-use and/or short-lived environments. \u003cbr\u003eWorks in Node.js and all browsers. \u003cbr\u003eAlphabet: ***Alphanumeric***\n\n\n## Usage\n\n```js\nimport { uid } from 'uid';\n// or: import { uid } from 'uid/secure';\n// or: import { uid } from 'uid/single';\n\n// length = 11 (default)\nuid(); //=\u003e 'c92054d1dd6'\nuid(); //=\u003e 'ac84bbb3728'\n\n// customize length\nuid(16); //=\u003e '8234dbf9a7dcec3b'\nuid(25); //=\u003e '4bbb3728b7a00a12209ec5ff5'\nuid(32); //=\u003e 'dcbc3e65506a7e6f15d30a357e884432'\n```\n\n\n## API\n\n### uid(length?)\nReturns: `String`\n\nCreates a new random identifer of fixed length.\n\n#### length\nType: `Number`\u003cbr\u003e\nDefault: `11`\n\nThen length of the output string.\n\n\u003e **Important:** Your risk of collisions decreases with longer strings!\n\n\n## Benchmarks\n\nYou can run the benchmark(s) yourself via the [`/bench`](/bench) directory.\n\nAll items listed pass a validation step for length and uniqueness. \u003cbr\u003e\nItems marked with a `†` are cryptographically secure (via CSPRNG).\n\n\n\u003e Running on Node.js v12.18.4\n\n```\nBenchmark (length = 11):\n  hashids/fixed        x   387,306 ops/sec ±1.03% (92 runs sampled)\n  nanoid/non-secure    x  5,338,433 ops/sec ±0.20% (95 runs sampled)\n† nanoid               x  2,705,158 ops/sec ±0.31% (95 runs sampled)\n† uid/secure           x  9,648,755 ops/sec ±0.18% (96 runs sampled)\n  uid/single           x  4,843,529 ops/sec ±0.19% (96 runs sampled)\n  uid                  x 21,276,788 ops/sec ±0.37% (94 runs sampled)\n\nBenchmark (length = 16):\n  hashids/fixed        x    409,228 ops/sec ±0.36% (98 runs sampled)\n  nanoid/non-secure    x  3,643,896 ops/sec ±1.27% (96 runs sampled)\n† nanoid               x  2,273,555 ops/sec ±0.15% (95 runs sampled)\n† uid/secure           x  9,167,545 ops/sec ±0.32% (95 runs sampled)\n  uid/single           x  3,624,579 ops/sec ±0.29% (95 runs sampled)\n  uid                  x 24,770,463 ops/sec ±0.41% (97 runs sampled)\n\nBenchmark (length = 25):\n  cuid                 x    177,241 ops/sec ±1.38% (91 runs sampled)\n  hashids/fixed        x    396,013 ops/sec ±0.21% (98 runs sampled)\n  nanoid/non-secure    x  2,477,463 ops/sec ±0.37% (96 runs sampled)\n† nanoid               x  1,794,062 ops/sec ±0.18% (97 runs sampled)\n† uid/secure           x  3,778,663 ops/sec ±0.16% (95 runs sampled)\n  uid/single           x  2,428,167 ops/sec ±0.27% (96 runs sampled)\n  uid                  x 24,580,091 ops/sec ±0.31% (96 runs sampled)\n\nBenchmark (length = 36):\n  uuid/v1              x  1,738,574 ops/sec ±0.36% (97 runs sampled)\n  uuid/v4              x  1,276,888 ops/sec ±0.26% (94 runs sampled)\n  hashids/fixed        x    374,294 ops/sec ±0.14% (98 runs sampled)\n  nanoid/non-secure    x  1,816,630 ops/sec ±0.31% (97 runs sampled)\n† nanoid               x  1,364,928 ops/sec ±0.18% (95 runs sampled)\n† @lukeed/uuid/secure  x  5,144,752 ops/sec ±0.28% (93 runs sampled)\n  @lukeed/uuid         x  5,950,932 ops/sec ±0.53% (95 runs sampled)\n† uid/secure           x  5,163,209 ops/sec ±0.32% (96 runs sampled)\n  uid/single           x  1,755,748 ops/sec ±0.24% (99 runs sampled)\n  uid                  x 20,166,119 ops/sec ±0.66% (94 runs sampled)\n```\n\n\u003e Running on Chrome 85.0.4183.121\n\n```\nBenchmark (length = 11):\n  hashids/fixed        x    369,393 ops/sec ±1.04% (67 runs sampled)\n  nanoid/non-secure    x  4,741,795 ops/sec ±0.67% (68 runs sampled)\n† nanoid               x    176,138 ops/sec ±7.17% (57 runs sampled)\n† uid/secure           x  2,061,703 ops/sec ±3.95% (65 runs sampled)\n  uid/single           x  4,547,527 ops/sec ±0.29% (67 runs sampled)\n  uid                  x 21,073,518 ops/sec ±0.60% (67 runs sampled)\n\nBenchmark (length = 16):\n  hashids/fixed        x    362,882 ops/sec ±0.25% (67 runs sampled)\n  nanoid/non-secure    x  3,245,036 ops/sec ±1.05% (67 runs sampled)\n† nanoid               x    165,535 ops/sec ±5.21% (59 runs sampled)\n† uid/secure           x  1,676,705 ops/sec ±0.25% (68 runs sampled)\n  uid/single           x  3,322,695 ops/sec ±0.49% (67 runs sampled)\n  uid                  x 24,074,441 ops/sec ±0.35% (67 runs sampled)\n\nBenchmark (length = 25):\n  cuid                 x     99,011 ops/sec ±6.09% (57 runs sampled)\n  hashids/fixed        x    349,187 ops/sec ±0.21% (68 runs sampled)\n  nanoid/non-secure    x  2,245,251 ops/sec ±1.21% (61 runs sampled)\n† nanoid               x    143,529 ops/sec ±4.53% (62 runs sampled)\n† uid/secure           x    936,133 ops/sec ±2.14% (67 runs sampled)\n  uid/single           x  2,276,265 ops/sec ±1.17% (66 runs sampled)\n  uid                  x 23,409,912 ops/sec ±1.81% (67 runs sampled)\n\nBenchmark (length = 36):\n  uuid/v1              x  1,695,352 ops/sec ±0.26% (67 runs sampled)\n  uuid/v4              x    294,032 ops/sec ±1.75% (63 runs sampled)\n  hashids/fixed        x    340,402 ops/sec ±0.37% (50 runs sampled)\n  nanoid/non-secure    x  1,611,905 ops/sec ±0.45% (66 runs sampled)\n† nanoid               x    118,006 ops/sec ±6.31% (52 runs sampled)\n† @lukeed/uuid/secure  x    859,592 ops/sec ±0.54% (67 runs sampled)\n  @lukeed/uuid         x  6,041,873 ops/sec ±0.33% (66 runs sampled)\n† uid/secure           x    776,658 ops/sec ±0.31% (56 runs sampled)\n  uid/single           x  1,646,199 ops/sec ±1.17% (66 runs sampled)\n  uid                  x 22,779,817 ops/sec ±0.66% (67 runs sampled)\n```\n\n## Performance\n\nThe reason `uid` and `uid/secure` are so much faster than its alternatives is two-fold:\n\n1) It composes an output with hexadecimal pairs (from a cached dictionary) instead of single characters.\n2) It allocates a larger Buffer/ArrayBuffer up front (expensive) and slices off chunks as needed (cheap).\n\nThe `uid/secure` module maintains an internal ArrayBuffer of 4096 bytes, which supplies **256** `uid()` invocations. However, the default module (`uid`) preallocates **512** invocations using less memory upfront. Both implementations will regenerate its internal allocation as needed.\n\nLarger buffers would result in higher performance over time, but I found these to be a good balance of performance and memory space.\n\n\u003e **Note:** If you want to don't want to preallocate memory, and do not need a CSPRNG, check out the `uid/single` mode.\n\n\n## Related\n\n- [hexoid](https://github.com/lukeed/hexoid) - A slightly larger (190B) but extremely fast variant of this module with a different API\n- [@lukeed/uuid](https://github.com/lukeed/uuid) - A tiny (230B), fast, and cryptographically secure UUID (V4) generator for Node and the browser\n\n## Credits\n\nThank you [Matthew Mueller](https://github.com/matthewmueller) for gifting the `uid` name on npm.\u003cbr\u003e\nThis module was previously known as `foid` (fast object IDs).\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fuid/lists"}