string-fromto: Conversions between common string types, as well as Base16/Base32/Base64.

[ bsd3, conversion, library, text ] [ Propose Tags ] [ Report a vulnerability ]

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 package exports a collection of functions that follow a simple pattern:

stringTypeAToStringTypeB :: a -> b

This way, if you import Data.String.FromTo unqualified, or as part of your Prelude, all you have to think about is which type you want to convert into which other type.

For convenience, this package also exposes conversions between Base16, Base32, and Base64-encoded strings.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0.0
Change log CHANGELOG.md
Dependencies base (>=4.8.2.0 && <5), bytestring (>=0.10.4.0 && <0.11), memory (>=0.8 && <0.18), text (>=0.1 && <2.1) [details]
License BSD-3-Clause
Copyright 2018-2019 Clovyr LLC
Author Patrick Nielsen
Maintainer patrick@clovyr.io
Revised Revision 2 made by patrick at 2023-08-28T03:26:17Z
Category Text, Conversion
Home page https://github.com/clovyr/string-fromto
Bug tracker https://github.com/clovyr/string-fromto/issues
Source repo head: git clone https://github.com/clovyr/string-fromto
Uploaded by patrick at 2019-09-30T17:29:07Z
Distributions
Downloads 619 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for string-fromto-1.0.0.0

[back to package description]

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

import Data.String.FromTo -- or imported as part of your Prelude

str :: String
str = "Hi, I'm a string"

text :: Text
text = stringToText str

encoded :: ByteString
encoded = textToBase64ByteString text

decoded :: Either String Text
decoded = base64ByteStringToText encoded

Documentation

Hackage

License

BSD3

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:

stringTypeAToStringTypeB :: a -> b

For example:


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.)