gleam base32 clockwork
Find a file
2025-12-16 16:30:28 -08:00
.github/workflows initial commit 2024-03-18 13:58:21 -07:00
src/gbase32_clockwork these aliases do not need to be public 2024-10-26 12:45:03 -07:00
test simplify interfaces 2024-10-26 12:34:03 -07:00
.gitignore initial commit 2024-03-18 13:58:21 -07:00
gleam.toml fix readme 2024-10-26 12:50:40 -07:00
LICENSE initial commit 2024-03-18 13:58:21 -07:00
manifest.toml update deps 2025-12-16 16:30:28 -08:00
README.md fix readme 2024-10-26 12:50:40 -07:00

gbase32_clockwork

About

I wanted to try implementing base32_clockwork in Gleam.
Inspired by shiguredo/base32_clockwork and this gist.

Usage

Package Version Hex Docs

gleam add gbase32_clockwork
import gbase32_clockwork/gbase32
import gleam/result
import gleam/string
import gleeunit/should

pub fn main() {
  // create a reusable encoder
  let encode = gbase32.new_encoder()
  
  // by default, lowercase is emitted
  encode("foobar")
  |> should.equal(Ok("csqpyrk1e8"))

  // to emit as uppercase, simply uppercase the output string
  encode("foobar")
  |> result.map(string.uppercase)
  |> should.equal(Ok("CSQPYRK1E8"))

  // create a reusable decoder
  let decode = gbase32.new_encoder()

  // a decoder will decode both upper and lowercase
  decode("CSQPYRG")
  |> should.equal(Ok("foob"))
}

Further documentation can be found at https://hexdocs.pm/gbase32_clockwork.

Development

gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell