{"id":18779401,"url":"https://github.com/zostay/raku-ulid","last_synced_at":"2025-12-18T00:30:19.957Z","repository":{"id":66558074,"uuid":"170360559","full_name":"zostay/raku-ULID","owner":"zostay","description":"ULID for Raku","archived":false,"fork":false,"pushed_at":"2020-02-08T16:41:40.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T10:29:19.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zostay.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-12T17:26:55.000Z","updated_at":"2021-05-14T15:57:35.000Z","dependencies_parsed_at":"2023-04-25T21:26:53.320Z","dependency_job_id":null,"html_url":"https://github.com/zostay/raku-ULID","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/zostay%2Fraku-ULID","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-ULID/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-ULID/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-ULID/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zostay","download_url":"https://codeload.github.com/zostay/raku-ULID/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239690614,"owners_count":19681134,"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-07T20:19:56.487Z","updated_at":"2025-12-18T00:30:19.907Z","avatar_url":"https://github.com/zostay.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"NAME\n====\n\nULID - Universally Unique Lexicographically Sortable Identifier\n\nSYNOPSIS\n========\n\n    use ULID;\n\n    say ulid; #\u003e 01D3HRFBR2WBZHW2HZ6CYSJ9JB\n\nDESCRIPTION\n===========\n\nThis implements the [ULID specification](https://github.com/ulid/spec) in Perl. Using the `ulid` function will generate a random unique ID according to that specification. These unique IDs can be generated in sortable order and are encoded in a Base 32 encoding.\n\nEXPORTED SUBROUTINES\n====================\n\nsub ulid\n--------\n\n    our sub ulid(\n        Int:D() $now       = ulid-now,\n        Bool:D :$monotonic = False,\n        :\u0026random-function  = \u0026random-number,\n        --\u003e Str:D\n    ) is export(:DEFAULT, :ulid)\n\nWith no arguments, this returns a string containing the ULID for the current moment.\n\nThe `$now` argument may be set to ULID's notion of time, which is number of milliseconds since the POSIX epoch start. Because this is annoying to calculate in Perl, this module provides the [ulid-now](#sub ulid-now) to do the conversion from [Instant](Instant) for you.\n\nThe `$monotonic` argument turns on monotonic ULID generation, which ensures that ULIDs generated sequentially during the same millisecond will also be issued in sorted order. The first time this is done for a given millisecond, the ULID is generated randomly as usual. The second time, however, the next ULID will be identical to the previous ULID, but increased in value by 1. This process may be repreated until the final carry bit occurs, at which point an [X::ULID](#X::ULID) exception will be thrown.\n\n**CAVEAT:** As of this writing, this is implemented in Perl and has not been much optimized, so it is unlikely in the extreme that you will be able to generate 2 ULIDs during the same millisecond unless you are passing the `$now` argument to deliberately generate multiple per second.\n\nThe `\u0026random-function` argument allows you to provide an alternative to the built-in random function used, which just depends on Perl's `rand`. The function should be defined similar to the default implementation which looks something like this:\n\n    sub (Int:D $max --\u003e Int:D) { $max.rand.floor }\n\nThat is, given an integer, it should return an integer `$n` such that `0 \u003c= $n \u003c $max `.\n\nsub ulid-now\n------------\n\n    our sub ulid-now(Instant:D $now = now --\u003e Int:D) is export(:time)\n\nThis method can be used to retrieve the number of milliseconds since the POSIX epoch. Or you may choose to pass an [Instant](Instant) to convert to such a value.\n\nsub ulid-time\n-------------\n\n    our sub ulid-time(Int:D $now --\u003e Seq:D) is export(:parts)\n\nThis method will allow you to return just the time part of a ULID. The value will convert a number of milliseconds since the POSIX epoch, `$now`, into the first 10 characters of the ULID. These are returned a sequence, so you'll have to join them yourself if you want a string.\n\nsub ulid-random\n---------------\n\n    our sub ulid-random(\n        Int:D $now,\n        :\u0026random-function = \u0026random-number,\n        Bool:D :$monotonic = False,\n        --\u003e Seq:D\n    ) is export(:parts)\n\nThis method will allow you to return just the random part of a ULID. The value returned will be 16 characters long in a sequence.\n\nThis must be passed the `$now` to use to generate the sequence, which will be stord in case `$monotonic` is passed during a subsequent call.\n\nSee `\u0026random-function` and `$monotonic` as described for [ulid](#sub ulid) for details on how they work.\n\nDIAGNOSTICS\n===========\n\nX::ULID\n-------\n\nThis exception will be thrown if a ULID cannot be generated for some reason by [ulid](#sub ulid). Currently, the only case where this will be true is when monotonic ULIDs are generated for a given millisecond and the module runs out of ULIDs that can be generated monotonically.\n\nIn that case, the message will be \"monotonic ULID overflow\". Enjoy.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-ulid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzostay%2Fraku-ulid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-ulid/lists"}