{"id":22549145,"url":"https://github.com/datl4g/kmp-nanoid","last_synced_at":"2025-04-10T01:53:00.503Z","repository":{"id":128635895,"uuid":"270336619","full_name":"DatL4g/KMP-NanoId","owner":"DatL4g","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-30T09:43:26.000Z","size":169,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T03:34:52.295Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/DatL4g.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}},"created_at":"2020-06-07T14:48:33.000Z","updated_at":"2024-09-05T04:38:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6ea1a07-9856-4e6a-bbe6-d7f25d4f5c0e","html_url":"https://github.com/DatL4g/KMP-NanoId","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DatL4g%2FKMP-NanoId","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DatL4g%2FKMP-NanoId/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DatL4g%2FKMP-NanoId/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DatL4g%2FKMP-NanoId/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DatL4g","download_url":"https://codeload.github.com/DatL4g/KMP-NanoId/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142939,"owners_count":21054671,"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-12-07T16:07:58.667Z","updated_at":"2025-04-10T01:53:00.476Z","avatar_url":"https://github.com/DatL4g.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kotlin Multiplatform NanoId\n\n![CI Test](https://github.com/DATL4G/KMP-NanoId/workflows/CI%20Test/badge.svg)\n\nA unique string ID generator for Javascript, JVM and Native written in Kotlin.\n\n### Secure\nKMP-NanoId uses Korlibs [Krypto SecureRandom](https://github.com/korlibs/krypto) to generate cryptographically strong random IDs with a proper distribution of characters.\n\nKrypto provides a `SecureRandom` class that extends the `kotlin.random.Random` class, but generating cryptographic secure values.\n\nIt uses `SecureRandom` on the JVM + `PRNGFixes` on Android. On Native POSIX (including Linux, macOs and iOS), it uses `/dev/urandom`, on Windows `BCryptGenRandom`\n\n### Compact\nKMP-NanoId generates compact IDs with just 21 characters.\n\nBy using a larger alphabet than UUID, KMP-NanoId can generate a greater number of unique IDs, when compared to UUID, with fewer characters (21 vs 36)\n\n### URL-Friendly\nKMP-NanoId uses URL-friendly character (`A-Za-z0-9_-`). Perfect for unique identifiers in web applications.\n\n### Customizable\nKMP-NanoId is fully customizable.\n\nAll default options may be overridden. \nSupply your own Random Number Generator, alphabet or size.\n\n### Tested\nKMP-NanoId is thoroughly tested with [Kotlin Test](https://kotlinlang.org/api/latest/kotlin.test/)\n\n## Usage\nKMP-NanoId provides one easy-to-use utility class (`NanoIdUtils`) with multiple methods to generate IDs.\n\n#### Standard IDs - `randomNanoId()`\nThe default method creates secure, url-friendly, unique ids.\nIt uses a url-friendly alphabet (`A-Za-z0-9_-`), a secure random number generator, and generates a unique ID wit 21 characters.\n\n##### Java:\n```java\nString id = NanoIdUtils.randomNanoId();\n```\n\n##### Kotlin:\n```kotlin\nval id = NanoIdUtils.randomNanoId()\n```\n\n#### Custom IDs - `NanoIdUtils.randomNanoId(random, alphabet, size)`\nAdditional methods allow you to generate custom IDs by specifying your own random number generator, alphabet or size.\n\n##### Java:\nMethods created by `@JvmOverloads`\n```java\nRandom random = new Random();\nchar[] alphabet = {'a', 'b', 'c'};\nint size = 10;\n\n// Only change random number generator\nString idRandom = NanoIdUtils.randomNanoId(random);\n\n// Change random number generator and alphabet\nString idRandomAlphabet = NanoIdUtils.randomNanoId(random, alphabet);\n\n// Change all parameter\nString idRandomAlphabetSize = NanoIdUtils.randomNanoId(random, alphabet, size);\n``` \n\n#### Kotlin:\n```kotlin\nval kRandom = Random()\nval kAlphabet = charArrayOf('a', 'b', 'c')\nval kSize = 10\n\n// Only change random number generator\nval idRandom = NanoIdUtils.randomNanoId(kRandom)\n\n// Change random number generator and alphabet\nval idRandomAlphabet = NanoIdUtils.randomNanoId(kRandom, kAlphabet)\n\n// Change all parameter\nval idRandomAlphabetSize = NanoIdUtils.randomNanoId(kRandom, kAlphabet, kSize)\n\n// Change alphabet only (keep default random number generator and size)\nval idAlphabet = NanoIdUtils.randomNanoId(alphabet = kAlphabet)\n\n// Change size only (keep default random number generator and alphabet)\nval idSize = NanoIdUtils.randomNanoId(size = kSize)\n\n// Change alphabet and size (keep default random number generator)\nval idAlphabetSize = NanoIdUtils.randomNanoId(alphabet = kAlphabet, size = kSize)\n```\n\nNeeded in Java (can be used in Kotlin)\n\n##### Default values:\n```java\n// Useful to keep some default values and change only specific\nNanoIdUtils.DEFAULT_NUMBER_GENERATOR\nNanoIdUtils.DEFAULT_ALPHABET\nNanoIdUtils.DEFAULT_SIZE\n\n// Usage example\nString idAlphabet = NanoIdUtils.randomNanoId(Random(), NanoIdUtils.DEFAULT_ALPHABET, 10);\n```\n\n## License\nCode released under the [MIT License](https://github.com/DATL4G/KMP-NanoId/blob/master/LICENSE)\n\n## Other Programming Languages\n\n* [C#](https://github.com/codeyu/nanoid-net)\n* [Clojure and ClojureScript](https://github.com/zelark/nano-id)\n* [Crystal](https://github.com/mamantoha/nanoid.cr)\n* [Dart](https://github.com/pd4d10/nanoid)\n* [Go](https://github.com/matoous/go-nanoid)\n* [Elixir](https://github.com/railsmechanic/nanoid)\n* [Haskell](https://github.com/4e6/nanoid-hs)\n* [Java](https://github.com/aventrix/jnanoid)\n* [JavaScript](https://github.com/ai/nanoid)\n* [Nim](https://github.com/icyphox/nanoid.nim)\n* [PHP](https://github.com/hidehalo/nanoid-php)\n* [Python](https://github.com/puyuan/py-nanoid)\n* [Ruby](https://github.com/radeno/nanoid.rb)\n* [Rust](https://github.com/nikolay-govorov/nanoid)\n* [Swift](https://github.com/antiflasher/NanoID)\n\nAlso, a [CLI tool](https://github.com/twhitbeck/nanoid-cli) is available to generate IDs from the command line.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatl4g%2Fkmp-nanoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatl4g%2Fkmp-nanoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatl4g%2Fkmp-nanoid/lists"}