{"id":20768151,"url":"https://github.com/softwaremill/scala-id-generator","last_synced_at":"2025-07-12T12:34:37.469Z","repository":{"id":33860574,"uuid":"149287217","full_name":"softwaremill/scala-id-generator","owner":"softwaremill","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-08T13:57:54.000Z","size":61,"stargazers_count":48,"open_issues_count":1,"forks_count":5,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-04-30T11:57:40.872Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softwaremill.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-09-18T12:48:04.000Z","updated_at":"2023-11-13T14:08:58.000Z","dependencies_parsed_at":"2022-09-15T01:41:39.562Z","dependency_job_id":null,"html_url":"https://github.com/softwaremill/scala-id-generator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/softwaremill/scala-id-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwaremill%2Fscala-id-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwaremill%2Fscala-id-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwaremill%2Fscala-id-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwaremill%2Fscala-id-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softwaremill","download_url":"https://codeload.github.com/softwaremill/scala-id-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwaremill%2Fscala-id-generator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264991028,"owners_count":23694550,"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-11-17T11:35:56.339Z","updated_at":"2025-07-12T12:34:37.418Z","avatar_url":"https://github.com/softwaremill.png","language":"Scala","funding_links":[],"categories":["分布式开发"],"sub_categories":["微服务框架"],"readme":"# Id generator\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.softwaremill.common/id-generator_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.softwaremill.common/id-generator_2.12)\n\nGenerate unique ids. A default generator is provided, based on [Twitter Snowflake](https://github.com/twitter/snowflake),\nwhich generates time-based ids. Besides that library provide `IdPrettifier` which may convert `Long` into user friendly id such `HPJD-72036-HAPK-58077`. `IdPrettifier` preserve Long's monotonicity, provides checksum and produce id with constant length (if it's not configured otherwise). It also maybe configured to user custom part sizes, separator or don't use leasing zeros to provide fixed length. More information you will find in the [blogpost](https://blog.softwaremill.com/new-pretty-id-generator-in-scala-commons-39b0fc6b6210) about it.\n\nSBT depedency:\n\n````scala\nlibraryDependencies += \"com.softwaremill.common\" %% \"id-generator\" % \"1.4.0\"\n````\n\nExamples\n```scala\n//create instance of it\nval generator:StringIdGenerator = PrettyIdGenerator.singleNode\n\n//generate ids\nval stringId = generator.nextId()\nstringId shouldNot be(empty)\nstringId should fullyMatch regex \"\"\"[A-Z]{4}-[0-9]{5}-[A-Z]{4}-[0-9]{5}\"\"\"\n\n//or it might be used just for encoding existing ids\nval prettifier = IdPrettifier.default\nval id = prettifier.prettify(100L) //id = AAAA-00000-AAAA-01007\nid should be(\"AAAA-00000-AAAA-01007\")\n\n//get seed\nval origin = prettifier.toIdSeed(id) // 100L\norigin should be(Right(100L))\n\n//use custom prettifier\nval customPrettifier = IdPrettifier.custom(encoder = new AlphabetCodec(new Alphabet(\"ABC\")), partsSize = 4, delimiter = '_', leadingZeros = false)\nval customId = customPrettifier.prettify(1234567L) //BCAACAB_5671\n\n//construct custom PrettyIdGenerator\nval idGenerator:IdGenerator = new IdGenerator {\n  override def nextId(): Long = ???\n  override def idBaseAt(timestamp: Long): Long = ???\n}\nval customGenerator = new PrettyIdGenerator(idGenerator, customPrettifier)\n```   \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftwaremill%2Fscala-id-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftwaremill%2Fscala-id-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftwaremill%2Fscala-id-generator/lists"}