packages feed

basesystems-1.1.0.0: README.md

basesystems [![hackage.haskell.org](
https://img.shields.io/badge/hackage%2Ehaskell%2Eorg-5C5181?logo=haskell)](
https://hackage.haskell.org/package/basesystems)[![builds.sr.ht status](
https://builds.sr.ht/~z0/basesystems/commits/main/basesystem-testing.yml.svg)](
https://builds.sr.ht/~z0/basesystems/commits/main/basesystem-testing.yml?)
------------------------------------------------

This project contains code for encoding/decoding numeric basesystems in Haskell.
It's implemented in a strategy pattern style where `BaseSystem` is a type-class
which provides the `encoder` and `decoder` methods on, for instance,
`ShortByteString`, in `Data.BaseSystem`:

```haskell
class BaseSystem a where
  encoder :: a -> ShortByteString -> String
  decoder :: a -> String -> Maybe ShortByteString
```

The library creates more `BaseSystem` classes with methods on normal
`ByteString` in `Data.BaseSystem.Strict` and `LazyByteString`
in `Data.BaseSystem.Lazy`. The basesystems passed as `a` to `encoder` and
`decoder` are defined in `Data.BaseSystem.DigitSystem`. See the [*example*](
#example).

`basesystems` is a part of the [ipfshs](https://git.sr.ht/~z0/ipfshs) project
which contains [testing via sourcehut builds](
https://builds.sr.ht/~z0/basesystems/commits/main/basesystem-testing.yml) and a
[bug ticket tracker](https://todo.sr.ht/~z0/ipfshs).

Coverage
--------

Eventually, This project aims to implement most if not all of the [mulitbase
specification's basesytems list](
https://github.com/multiformats/multibase?tab=readme-ov-file#multibase-table).

Currently, the following basesystems are supported:
- base2
- base10
- base16(upper/lower)
- base32(upper/lower) w/pad + nopad
- base32hex(lower/upper) w/pad + nopad
- base58btc
- base64 w/pad + nopad
- base64url w/pad + nopad

Example
-------

For an example of using `basesystems`, we can do the following in GHCI:

Set `OverloadedStrings` so strings can act as Text data and import the needed
functions. Then import the basesystem functions and `packValue` from
`Data.BaseSystem.BinaryTranscoder` to convert a number value directly into
bytes.

```haskell
λ> {-# LANGUAGE OverloadedStrings #-}
λ> import Data.BaseSystem (encoder, decoder)
λ> import Data.BaseSystem.DigitSystem (base2, base10, base16lower, base32lower)
λ> import Data.BaseSystem.BinaryTranscoder (packValue)
```

This shows how we can take the binary value of `123` and display it in various
number systems.

```haskell
λ> :t encoder
encoder :: BaseSystem a => a -> ShortByteString -> Text
λ> :t decoder
decoder :: BaseSystem a => a -> Text -> Maybe ShortByteString
λ> encoder base2 $ packValue (123 :: Int)
"1111011"
λ> encoder base16lower $ packValue (123 :: Int)
"7b"
λ> encoder base32lower $ packValue (123 :: Int)
"pm======"
```

We can also use encoders and decoders to translate one numeric representation to
another.

```haskell
λ> encoder base10 <$> decoder base2 "1111011"
Just "123"
λ> encoder base10 <$> decoder base16lower "7b"
Just "123"
λ> encoder base10 <$> decoder base32lower "pm======"
Just "123"
```

Licensing
---------

The `basesystems` project and its modules are free software and licensed under
the BSD 3-clause license. See [LICENSE.txt](LICENSE.txt).

Copyright © 2026 Zoey McBride | [zoeymcbride@mailbox.org](
mailto:zoeymcbride@mailbox.org)