crockford
Version, currently master branch1 version
- master branchlatestFeb 27, 2022
github.com/davidkellis/crockford
Crystal implementation of Crockford's base-32 encoding.
Installation
# Add this to your shard.yml
dependencies:
crockford:
github: davidkellis/crockford
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
1.3.0- License
- MIT
- Author
- David Ellis
Dependencies
This version declares no dependencies.
README
crockford
This library implements Crockford's base 32 encoding as defined at https://www.crockford.com/base32.html.
Installation
-
Add the dependency to your
shard.yml:dependencies: crockford: github: davidkellis/crockford -
Run
shards install
Usage
There are three methods that make up the API:
-
Crockford.encode(number : Int, encoding : Encoding = Crockford::DEFAULT) : String
Takes a non-negative integer and encodes it with Crockford's base-32 encoding. Returns a String representing the encoded value.
-
Crockford.decode(str : String, encoding : Encoding = Crockford::DEFAULT) : UInt64
Decodes the given Crockford base-32 encoded string. Raises ArgumentError if the encoded string value does not represent a valid encoded value. Returns a UInt64 representation of the encoded value.
-
Crockford.decode?(str : String, encoding : Encoding = Crockford::DEFAULT) : UInt64?
Decodes the given Crockford base-32 encoded string. Returns a UInt64 representation of the encoded value if the encoded string represents a valid encoded value; otherwise, returns nil.
require "crockford"
encoded_value = Crockford.encode(123) # encoded_value = "3V"
decoded_value = Crockford.decode(encoded_value) # decoded_value = 123
Crockford.encode(-5) # raises ArgumentError, "Unable to encode negative values."
Crockford.decode("invalid_value") # raises ArgumentError, "Unable to decode ordinal 95."
optional_val = Crockford.decode?("invalid_value") # optional_val = nil
Contributors
- David Ellis - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Feb 27, 2022
- Crystal
1.3.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/davidkellis/crockford
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1