{"id":24511712,"url":"https://github.com/devnax/youid","last_synced_at":"2025-04-14T08:22:17.505Z","repository":{"id":272714061,"uuid":"917519616","full_name":"devnax/youid","owner":"devnax","description":"A lightweight utility to generate unique identifiers (UIDs) from strings or randomly.","archived":false,"fork":false,"pushed_at":"2025-03-03T08:22:22.000Z","size":70,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T22:01:37.163Z","etag":null,"topics":["generate-id","javascript","random-id","react","string-based","uid"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/youid","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/devnax.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":"2025-01-16T06:23:36.000Z","updated_at":"2025-03-03T08:22:26.000Z","dependencies_parsed_at":"2025-01-16T07:36:59.617Z","dependency_job_id":"dacd433f-4d8a-4476-be09-745d4cf40702","html_url":"https://github.com/devnax/youid","commit_stats":null,"previous_names":["devnax/youid"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fyouid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fyouid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fyouid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fyouid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devnax","download_url":"https://codeload.github.com/devnax/youid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710434,"owners_count":21149191,"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":["generate-id","javascript","random-id","react","string-based","uid"],"created_at":"2025-01-22T00:40:47.689Z","updated_at":"2025-04-14T08:22:17.494Z","avatar_url":"https://github.com/devnax.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `youid`\n\n`youid` is a lightweight JavaScript function that generates unique identifiers (UIDs) from strings. It can also generate random UIDs if no string input is provided. `youid` is flexible, allowing you to specify the length of the UID.\n\n## Installation\n\nTo install `youid` as an npm package:\n\n```bash\nnpm install youid\n```\n\n## Usage\n\n`youid` provides a simple API to generate UIDs from strings or create random UIDs. The function takes two optional parameters:\n\n- `str` (optional): The input string from which the UID will be generated.\n- `length` (optional): The desired length of the UID.\n\n### Importing the Function\n\nIf using a module bundler:\n\n```javascript\nimport youid from 'youid';\n```\n\n### Generating a UID\n\n#### 1. UID from a String\nTo generate a UID based on a string:\n\n```javascript\nconst uid = youid('HelloWorld');\nconsole.log(uid); // Example output: \"j1m3q4v9\"\n```\n\n#### 2. Specifying the Length\nYou can control the length of the generated UID:\n\n```javascript\nconst uid = youid('HelloWorld', 10);\nconsole.log(uid); // Example output: \"j1m3q4v900\"\n```\n\n#### 3. Generating a Random UID\nIf no string is provided, `youid` generates a random UID:\n\n```javascript\nconst randomUID = youid();\nconsole.log(randomUID); // Example output: \"x5y7z1w8a2\"\n```\n\n### Function Signature\n```javascript\nconst youid = (str?: string, length?: number) =\u003e string;\n```\n\n### Parameters\n1. **`str`** *(optional)*: A string input to generate a hash-based UID.\n   - If omitted, a random UID generator function is returned.\n\n2. **`length`** *(optional)*: The desired length of the UID.\n   - Defaults to the full length of the generated hash or random string.\n\n### Return Value\n- **If `str` is provided**: A string UID based on the input string.\n- **If `str` is omitted**: A function that generates random UIDs, optionally constrained by `length`.\n\n## Examples\n\n### Basic Examples\n#### Hash-Based UID:\n```javascript\nconst uid = youid('MyString');\nconsole.log(uid); // Example output: \"k9l2m5\"\n```\n\n#### Length-Controlled UID:\n```javascript\nconst uid = youid('AnotherString', 12);\nconsole.log(uid); // Example output: \"k9l2m5n0pqr8\"\n```\n\n#### Random UID:\n```javascript\nconst randomUID = youid(null, 8);\nconsole.log(randomUID); // Example output: \"abc123xy\"\n```\n\n### Real-World Usage\n#### Generating IDs for HTML Elements:\n```javascript\nconst elementID = youid('button-submit', 10);\ndocument.getElementById('my-element').id = elementID;\nconsole.log(elementID); // Example output: \"b8t9w7z6x1\"\n```\n\n#### Random UIDs for Testing:\n```javascript\nconst randomIDGenerate = youid();\nconsole.log(randomIDGenerate); // Example output: \"a9b3c5d7\"\n```\n\n## How It Works\n\n1. If a string is provided, the function computes a hash using bitwise operations and converts it to a base-36 representation.\n2. If `length` is specified, the UID is padded or truncated to match the desired length.\n3. If no string is provided, the function returns another function that generates random UIDs using `Math.random()`.\n\n## License\n\n`youid` is open-source software licensed under the [MIT License](LICENSE).\n\n## Contributions\n\nContributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/devnax/`youid`).\n\n---\n\nFor any issues or inquiries, please contact the [maintainer](mailto:edvnaxrul@gmail.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnax%2Fyouid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevnax%2Fyouid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnax%2Fyouid/lists"}