ULID

[![Linux Build][travis-image]][travis-url] [![Shards version][shards-image]][shards-url]

A Crystal port of [alizain/ulid][origin-lib-url].

![Logo][logo-image]

Universally Unique Lexicographically Sortable Identifier

UUID can be suboptimal for many uses-cases because:

Instead, herein is proposed ULID:


Installation

Add this to your application's shard.yml:

dependencies:
  ulid:
    github: SuperPaintman/ulid

Usage

require "ulid"

ULID.generate
# => "01B3EAF48P97R8MP9WS6MHDTZ3"

Specification

Below is the current specification of ULID as implemented in this repository.

Components

Timestamp

Randomness

Sorting

The left-most character must be sorted first, and the right-most character sorted last (lexical order). The default ASCII character set must be used. Within the same millisecond, sort order is not guaranteed

Encoding

Crockford's Base32 is used as shown. This alphabet excludes the letters I, L, O, and U to avoid confusion and abuse.

Binary Layout and Byte Order

The components are encoded as 16 octets. Each component is encoded with the Most Significant Byte first (network byte order).

0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      32_bit_uint_time_low                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     16_bit_uint_time_high     |       16_bit_uint_random      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       32_bit_uint_random                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       32_bit_uint_random                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

String Representation

 

Test

crystal spec

Contributing

  1. Fork it (<https://github.com/SuperPaintman/ulid/fork>)
  2. Create your feature branch (git checkout -b feature/)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin feature/)
  5. Create a new Pull Request

Contributors


API

[Docs][docs-url]


Changelog

[Changelog][changelog-url]


License

[MIT][license-url]

[license-url]: LICENSE [changelog-url]: CHANGELOG.md [docs-url]: https://superpaintman.github.io/ulid/ [logo-image]: README/logo.png [origin-lib-url]: https://github.com/alizain/ulid [travis-image]: https://img.shields.io/travis/SuperPaintman/ulid/master.svg?label=linux [travis-url]: https://travis-ci.org/SuperPaintman/ulid [shards-image]: https://img.shields.io/github/tag/superpaintman/ulid.svg?label=shards [shards-url]: https://github.com/superpaintman/ulid