{"id":30668249,"url":"https://github.com/devnax/xanv","last_synced_at":"2025-08-31T23:47:14.741Z","repository":{"id":308327906,"uuid":"1032376881","full_name":"devnax/xanv","owner":"devnax","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-19T20:46:18.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-19T22:18:15.745Z","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":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,"zenodo":null}},"created_at":"2025-08-05T08:10:58.000Z","updated_at":"2025-08-19T20:46:21.000Z","dependencies_parsed_at":"2025-08-05T12:18:41.049Z","dependency_job_id":null,"html_url":"https://github.com/devnax/xanv","commit_stats":null,"previous_names":["devnax/xanv"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devnax/xanv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fxanv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fxanv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fxanv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fxanv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devnax","download_url":"https://codeload.github.com/devnax/xanv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fxanv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273056063,"owners_count":25037873,"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-08-31T02:00:09.071Z","response_time":79,"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":"2025-08-31T23:47:09.306Z","updated_at":"2025-08-31T23:47:14.731Z","avatar_url":"https://github.com/devnax.png","language":"TypeScript","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%2Fxanv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevnax%2Fxanv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnax%2Fxanv/lists"}