Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clovyr/string-fromto
Conversions between common string types, as well as Base16/Base32/Base64
https://github.com/clovyr/string-fromto
base16 base32 base64 bytestring conversion haskell text
Last synced: about 2 months ago
JSON representation
Conversions between common string types, as well as Base16/Base32/Base64
- Host: GitHub
- URL: https://github.com/clovyr/string-fromto
- Owner: clovyr
- License: bsd-3-clause
- Created: 2019-09-30T17:23:28.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-08-18T00:08:08.000Z (over 4 years ago)
- Last Synced: 2024-11-28T13:45:21.034Z (2 months ago)
- Topics: base16, base32, base64, bytestring, conversion, haskell, text
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/string-fromto
- Size: 4.88 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# string-fromto
A collection of predictably-named functions (e.g. byteStringToString) that
convert between the common string types, as well as to and from Base16, Base32,
and Base64.## Usage
```haskell
import Data.String.FromTo -- or imported as part of your Preludestr :: String
str = "Hi, I'm a string"text :: Text
text = stringToText strencoded :: ByteString
encoded = textToBase64ByteString textdecoded :: Either String Text
decoded = base64ByteStringToText encoded
```## Documentation
[Hackage](https://hackage.haskell.org/package/string-fromto)
## License
[BSD3](LICENSE)
## Motivation
Have you ever found yourself frustrated that you're spending 15-30% of your
time in Haskell converting between string types, remembering which module has
the `toStrict` function, importing Data.Text.Encoding and
Data.Text.Lazy.Encoding qualified, spending time thinking about how to do
Base64 encoding, etc.? Or tried to use one of the (excellent) typeclass-based
string conversion libraries, only to find yourself adding awkward type
signatures to avoid type-inferencing ambiguities?This library exports a collection of functions that follow a simple pattern:
```haskell
stringTypeAToStringTypeB :: a -> b
```For example:
```haskell
stringToByteString :: String -> ByteString
stringToLazyByteString :: String -> Lazy.ByteString
base64ByteStringToText :: ByteString -> Either String Text
```This way, if you import this module unqualified, or as part of your Prelude,
all you have to think about is which type you want to convert into which other
type.(Note that not *every* possible permutation has a function, just each one we've
ever needed. If you need one that's not included, please submit a pull request
to add it.)