Skip to content

Commit

Permalink
Merge pull request #2 from vtomilin/refactor-package-name
Browse files Browse the repository at this point in the history
Refactored to avoid package name clash on Hex
  • Loading branch information
vtomilin authored Oct 9, 2024
2 parents 1d89f15 + 189839e commit e147f75
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ULID
# Gleam ULID
[Universally Unique Lexicographically Sortable Identifier](https://github.com/ulid/spec) implementation in
Gleam.

Expand All @@ -9,14 +9,14 @@ Gleam.
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/ulid/)

```sh
gleam add ulid
gleam add gleam_ulid
```

# Basic Use

```gleam
import ulid.{ new_as_string, new, new_monotonic, from_string_function,
to_string_function }
import gleam_ulid.{ new_as_string, new, new_monotonic, from_string_function,
to_string_function }
pub fn main() {
// Quick and dirty ULID string - has performance implications
Expand Down Expand Up @@ -76,8 +76,8 @@ import gleam/io
import gleam/list
import gleam/result
import gleam/string
import gleeunit/should
import ulid.{from_parts, from_tuple, to_parts}
import gleam/bool
import gleam_ulid.{from_parts, from_tuple, to_parts}
pub fn main() {
let ulid =
Expand All @@ -99,7 +99,7 @@ pub fn main() {
let same_ulid = from_tuple(#(timestamp, random))
should.equal(ulid, same_ulid)
io.println("Same ulids? " <> { bool.to_string(same_ulid == ulid) })
}
@external(erlang, "calendar", "system_time_to_rfc3339")
Expand All @@ -121,7 +121,7 @@ Further documentation can be found at <https://hexdocs.pm/ulid>.
## Development

```sh
gleam run -m example1 # Run the example one
gleam run -m example2 # Run the example two
gleam run -m examples/example1 # Run the example one
gleam run -m examples/example2 # Run the example two
gleam test # Run the tests
```
7 changes: 5 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name = "ulid"
name = "gleam_ulid"
version = "0.0.1"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
#
description = "ULID implementation in Gleam (Erlang target only)"
licences = ["Apache-2.0"]
repository = { type = "github", user = "vtomilin", repo = "ulid" }
repository = { type = "github", user = "vtomilin", repo = "gleam_ulid" }
# links = [{ title = "Website", href = "" }]
internal_modules = [
"gleam_ulid/examples/*",
]

[dependencies]
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/example1.gleam → src/examples/example1.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gleam/io
import gleam/list
import ulid.{
import gleam_ulid.{
DecodeError, InvalidLength, from_string_function, new, new_as_string,
to_string_function,
}
Expand Down
2 changes: 1 addition & 1 deletion src/example2.gleam → src/examples/example2.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import gleam/io
import gleam/list
import gleam/result
import gleam/string
import ulid.{from_parts, from_tuple, to_parts}
import gleam_ulid.{from_parts, from_tuple, to_parts}

pub fn main() {
let ulid =
Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions test/ulid_test.gleam → test/gleam_ulid_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import gleam/int
import gleam/list
import gleam/order
import gleam/string
import gleam_ulid.{
type Ulid, from_parts, from_string_function, new, new_monotonic, to_parts,
to_string_function,
}
import gleeunit
import gleeunit/should
import ulid.{type Ulid, from_string_function, new, to_string_function}

pub fn main() {
gleeunit.main()
Expand All @@ -24,7 +27,7 @@ pub fn to_string_success_test() -> #(Ulid, String) {

pub fn monotonic_test() {
list.range(0, 9)
|> list.scan(new(), fn(ulid, _) { ulid.new_monotonic(ulid) })
|> list.scan(new(), fn(ulid, _) { new_monotonic(ulid) })
|> list.map(to_string_function())
|> list.window_by_2
|> list.all(fn(ulid_pair) {
Expand Down Expand Up @@ -68,8 +71,8 @@ pub fn from_string_too_short_test() {
pub fn from_parts_test() {
let date_time = erlang.system_time(erlang.Millisecond)
let random = int.random(162_554_647_477_263)
let ulid = ulid.from_parts(date_time, random)
let #(ts, rnd) = ulid.to_parts(ulid)
let ulid = from_parts(date_time, random)
let #(ts, rnd) = to_parts(ulid)

ts |> should.equal(date_time)
rnd |> should.equal(random)
Expand Down

0 comments on commit e147f75

Please sign in to comment.