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
Search Document