{"id":29022050,"url":"https://github.com/jsweb/randkey","last_synced_at":"2025-06-26T02:37:41.142Z","repository":{"id":33095744,"uuid":"145777250","full_name":"jsweb/randkey","owner":"jsweb","description":"Simple JS module to generate random id/key/hash in various formats, including UUID like","archived":false,"fork":false,"pushed_at":"2022-12-05T16:03:08.000Z","size":501,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-12T02:56:15.847Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/jsweb.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}},"created_at":"2018-08-23T00:17:49.000Z","updated_at":"2022-08-20T21:38:28.000Z","dependencies_parsed_at":"2023-01-14T23:20:14.372Z","dependency_job_id":null,"html_url":"https://github.com/jsweb/randkey","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"purl":"pkg:github/jsweb/randkey","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Frandkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Frandkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Frandkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Frandkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsweb","download_url":"https://codeload.github.com/jsweb/randkey/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Frandkey/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261396892,"owners_count":23152460,"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":"2025-06-26T02:37:38.501Z","updated_at":"2025-06-26T02:37:41.091Z","avatar_url":"https://github.com/jsweb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jsweb/randkey\n\nSimple JS module to generate random id/key/hash in various formats, including UUID.\n\nSee tests at [https://randkey.jsweb.app](https://randkey.jsweb.app)\n\n![package-npm](https://img.shields.io/badge/package-npm-blue.svg?style=for-the-badge)\n![module-es](https://img.shields.io/badge/module-es-blue.svg?style=for-the-badge)\n![tests-ava](https://img.shields.io/badge/tests-ava-blue.svg?style=for-the-badge)\n\n---\n\n## Installation\n\nYou can install it with NPM, Yarn or get from Unpkg CDN:\n\n`npm i -S @jsweb/randkey`\n\n`yarn add @jsweb/randkey`\n\n`pnpm add @jsweb/randkey`\n\nUnpkg CDN: https://unpkg.com/@jsweb/randkey\n\n## Usage\n\n`@jsweb/randkey` is a full ES module, there is no UMD or CommonJS versions.\n\nES modules are the pattern in modern JS development, already natively supported by newer versions of Node.js and modern browsers.\n\nBackward compatibility is not a concern here. If you use a module bundler (like Webpack or Rollup) to transpile your code, the result will be compatible according to your setup.\n\n### ES6\n\nTree shaking:\n\n```javascript\nimport { id16, uuid, ... } from '@jsweb/randkey'\n```\n\n### From Unpkg CDN (installation not required)\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { uuid } from 'https://unpkg.com/@jsweb/randkey'\n\n  const key = uuid()\n\u003c/script\u003e\n```\n\n## Methods\n\n### rand(radix = 10, limit = 40)\n\nGenerates a random number as string with optional radix and size limit.\n\nThe `radix` parameter can be a number from 2 to 36. Default is 10, which generates base 10 random numbers.\n\nThe `limit` size parameter can be a number from 1 to 40. Default is 40, which is the bigger possible.\n\nKeep in mind that `radix` can automatic limit the result max size.\n\n```javascript\nimport { rand } from '@jsweb/randkey'\n\nrand()\n// \u003e '555847878175'\n\nrand(2)\n// \u003e '1001010000010000000001111111010100000110'\n\nrand(8)\n// \u003e '2036103777231'\n\nrand(16)\n// \u003e '12a82628ee7'\n\nrand(32)\n// \u003e '18vq5b2hq'\n\nrand(36)\n// \u003e 'fdqlsnvb'\n```\n\n### hex(limit = 11)\n\nGenerates a random hexadecimal number as string with optional custom size limit.\n\nSize limit must be from 1 to 11. Default is 11, which is the bigger possible.\n\nIt is just an alias for `rand(16, limit)`.\n\n```javascript\nimport { hex } from '@jsweb/randkey'\n\nhex(6) // \u003e 'f9c1d0'\n```\n\n### id4()\n\nGenerates a random ID with 4 hexadecimal digits. It is just an alias for `hex(4)`.\n\n```javascript\nimport { id4 } from '@jsweb/randkey'\n\nid4() // \u003e 'f9c1'\n```\n\n### id8()\n\nGenerates a random ID with 8 hexadecimal digits. It is just an alias for `hex(8)`.\n\n```javascript\nimport { id8 } from '@jsweb/randkey'\n\nid8() // \u003e 'bf9c61ed'\n```\n\n### id16()\n\nGenerates a random ID with 16 hexadecimal digits.\n\n```javascript\nimport { id16 } from '@jsweb/randkey'\n\nid16() // \u003e '6c1f3ac8e0ba611d'\n```\n\n### id32()\n\nGenerates a random ID with 32 hexadecimal digits.\n\n```javascript\nimport { id32 } from '@jsweb/randkey'\n\nid32() // \u003e 'f17e3ac8e0ba925a61ed19016c1f2eb0'\n```\n\n### id64()\n\nGenerates a random ID with 64 hexadecimal digits.\n\n```javascript\nimport { id64 } from '@jsweb/randkey'\n\nid64() // \u003e 'f17e3ac8e0ba925a61ed19016c1f2eb0f17e3ac8e0ba925a61ed19016c1f2eb0'\n```\n\n### uuid()\n\nGenerates a valid UUID v4 (RFC 4122 compilant).\n\n```javascript\nimport { uuid } from '@jsweb/randkey'\n\nuuid() // \u003e 'c30663ff-a2d3-4e5d-b377-9e561e8e599b'\n```\n\n### puid()\n\nGenerates a random 5x5 ID with base2 progressive radix per block.\n\n```javascript\nimport { puid } from '@jsweb/randkey'\n\npuid() // \u003e 10100-13110-42720-98222-13prn\n```\n\n### ruid(radix = 10)\n\nGenerates a random 5x5 ID using a common radix for all blocks using `rand(radix, 5)`.\n\nThe `radix` parameter can be a number from 2 to 36. Default is 10, which generates base 10 random blocks.\n\n```javascript\nimport { ruid } from '@jsweb/randkey'\n\nruid(8) // \u003e 15124-22432-17325-45517-15522\n```\n\n### huid()\n\nGenerates a random 5x5 ID with hexadecimal blocks.\n\nIt is just an alias for `ruid(16)`.\n\n```javascript\nimport { huid } from '@jsweb/randkey'\n\nhuid() // \u003e d74b8-124e7-15854-15c73-82909\n```\n\n### wuid()\n\nGenerates a random 5x5 ID with alphanumerical blocks, like Windows Product Key.\n\nIt is just an alias for `ruid(36)`.\n\n```javascript\nimport { wuid } from '@jsweb/randkey'\n\nwuid() // \u003e 7wuiu-e4fw7-ari12-3z50r-iv04x\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsweb%2Frandkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsweb%2Frandkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsweb%2Frandkey/lists"}