Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dasch/crockford
An implementation of Crockford's base32 in Elm
https://github.com/dasch/crockford
Last synced: 24 days ago
JSON representation
An implementation of Crockford's base32 in Elm
- Host: GitHub
- URL: https://github.com/dasch/crockford
- Owner: dasch
- License: apache-2.0
- Created: 2019-10-29T09:58:57.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-12T14:37:41.000Z (almost 5 years ago)
- Last Synced: 2023-08-08T20:39:03.741Z (about 1 year ago)
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/dasch/crockford/latest/
- Size: 46.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crockford's base32 encoding in Elm
Encode integers as [Crockford-style base32 strings](https://www.crockford.com/base32.html).
From the specification:
> Base 32 is a textual 32-symbol notation for expressing numbers in a form that can be conveniently and accurately transmitted between humans and computer systems. It can be used for out of band communication of public keys.
>
> The encoding scheme is required to
>
> - Be human readable and machine readable.
> - Be compact. Humans have difficulty in manipulating long strings of arbitrary symbols.
> - Be error resistant. Entering the symbols must not require keyboarding gymnastics.
> - Be pronounceable. Humans should be able to accurately transmit the symbols to other humans using a telephone.This package provides functions for encoding and decoding base32 data.
## Examples
```elm
-- Encodes a non-negative integer as a base32 string according to Crockford's encoding scheme.
Crockford.encode 1337 --> Ok "19S" : Result Crockford.Error String-- Decodes a base32 string into a non-negative integer.
Crockford.decode "19S" --> Ok 1337 : Result Crockford.Error Int-- Negative integers cannot be encoded.
Crockford.encode -1 --> Err NegativeNumberError : Result Crockford.Error String
```It's also possible to have a checksum number appended to the string when encoded. This checksum number will be used to validate the correctness of the encoded number when decoding.
```elm
Crockford.encodeWithChecksum 32 --> Ok "10*" : Result Crockford.Error StringCrockford.decodeWithChecksum "10*" --> Ok 32 : Result Crockford.Error Int
Crockford.decodeWithChecksum "10~" --> Err Crockford.InvalidChecksum : Result Crockford.Error Int
```