packages feed

base64-lens 0.1.0.1 → 0.1.0.3

raw patch · 4 files changed

+162/−30 lines, 4 filesdep ~base64dep ~textPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: base64, text

API changes (from Hackage documentation)

+ Data.ByteString.Base64.Lens: _Base64Lenient :: Iso' ByteString ByteString
+ Data.ByteString.Base64.Lens: _Base64UrlLenient :: Iso' ByteString ByteString
+ Data.ByteString.Base64.Lens: pattern Base64Lenient :: ByteString -> ByteString
+ Data.ByteString.Base64.Lens: pattern Base64UrlLenient :: ByteString -> ByteString
+ Data.Text.Encoding.Base64.Lens: _Base64Lenient :: Iso' Text Text
+ Data.Text.Encoding.Base64.Lens: _Base64UrlLenient :: Iso' Text Text
+ Data.Text.Encoding.Base64.Lens: pattern Base64Lenient :: Text -> Text
+ Data.Text.Encoding.Base64.Lens: pattern Base64UrlLenient :: Text -> Text

Files

README.md view
@@ -21,6 +21,16 @@ pattern Base64Url :: Text -> Text pattern Base64Unpadded :: Text -> Text pattern Base64UrlUnpadded :: Text -> Text++-- additionally if using >=base64-0.3++Base64Lenient :: ByteString -> ByteString+Base64UrlLenient :: ByteString -> ByteString++-- and++Base64Lenient :: Text -> Text+Base64UrlLenient :: Text -> Text ```  These provide a convenient high level interface for passing Base64 encoded values.@@ -44,6 +54,15 @@ _Base64Unpadded :: Prism' Text Text _Base64UrlUnpadded :: Prism' Text Text +-- additionally if using >=base64-0.3++_Base64Lenient :: Iso' ByteString ByteString+_Base64UrlLenient :: Iso' ByteString ByteString++-- and++_Base64Lenient :: Iso' Text Text+_Base64UrlLenient :: Iso' Text Text ```  If a particular structure has a `Lens` into some `Text` or `ByteString` value they might want to encode (or decode), then composing such a `Lens` with these `Prisms` yields an affine `Traversal`, resulting in a structure which has the focus of its `Lens` encoded as or decoded from Base64(-url). All one needs to do is compose their optics:
base64-lens.cabal view
@@ -1,7 +1,7 @@ cabal-version:       1.24  name:                base64-lens-version:             0.1.0.1+version:             0.1.0.3 synopsis:            Optics for the Base64 library description:   Prisms and pattern synonyms for the Base64 library@@ -37,10 +37,10 @@                      , Data.Text.Encoding.Base64.Lens    build-depends:       base       >=4.10 && <5-                     , base64     >=0.2  && <0.3+                     , base64     >=0.2  && <0.4                      , bytestring >=0.10 && <0.11                      , lens       >=4.0  && <4.19-                     , text+                     , text       >=1.2  && <1.3    hs-source-dirs:      src   default-language:    Haskell2010
src/Data/ByteString/Base64/Lens.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} -- |@@ -9,7 +10,7 @@ -- Stability	: Experimental -- Portability	: non-portable ----- This module contains 'Control.Lens.Type.Prism's for Base64-encoding and+-- This module contains 'Prism''s for Base64-encoding and -- decoding 'ByteString' values. -- module Data.ByteString.Base64.Lens@@ -18,11 +19,19 @@ , _Base64Url , _Base64Unpadded , _Base64UrlUnpadded+#if MIN_VERSION_base64(0,3,0)+, _Base64Lenient+, _Base64UrlLenient+#endif   -- * Patterns , pattern Base64 , pattern Base64Url , pattern Base64Unpadded , pattern Base64UrlUnpadded+#if MIN_VERSION_base64(0,3,0)+, pattern Base64Lenient+, pattern Base64UrlLenient+#endif ) where  @@ -45,7 +54,7 @@ -- -------------------------------------------------------------------------- -- -- Optics --- | A 'Control.Lens.Type.Prism' into the Base64 encoding of a 'ByteString' value+-- | A 'Prism'' into the Base64 encoding of a 'ByteString' value -- -- >>> _Base64 # "Sun" -- "U3Vu"@@ -54,12 +63,12 @@ -- Just "Sun" -- _Base64 :: Prism' ByteString ByteString-_Base64 = prism' B64.encodeBase64 $ \s -> case B64.decodeBase64 s of+_Base64 = prism' B64.encodeBase64' $ \s -> case B64.decodeBase64 s of     Left _ -> Nothing     Right a -> Just a {-# INLINE _Base64 #-} --- | A 'Control.Lens.Type.Prism' into the Base64-url encoding of a 'ByteString' value+-- | A 'Prism'' into the Base64url encoding of a 'ByteString' value -- -- >>> _Base64Url # "Sun" -- "U3Vu"@@ -68,12 +77,12 @@ -- Just "<<???>>" -- _Base64Url :: Prism' ByteString ByteString-_Base64Url = prism' B64U.encodeBase64 $ \s -> case B64U.decodeBase64 s of+_Base64Url = prism' B64U.encodeBase64' $ \s -> case B64U.decodeBase64 s of     Left _ -> Nothing     Right a -> Just a {-# INLINE _Base64Url #-} --- | A 'Control.Lens.Type.Prism' into the unpadded Base64 encoding of a+-- | A 'Prism'' into the unpadded Base64 encoding of a -- 'ByteString' value -- -- Please note that unpadded variants should only be used@@ -87,12 +96,12 @@ -- Just "Sun" -- _Base64Unpadded :: Prism' ByteString ByteString-_Base64Unpadded = prism' B64.encodeBase64Unpadded $ \s -> case B64.decodeBase64Unpadded s of+_Base64Unpadded = prism' B64.encodeBase64Unpadded' $ \s -> case B64.decodeBase64Unpadded s of     Left _ -> Nothing     Right a -> Just a {-# INLINE _Base64Unpadded #-} --- | A 'Control.Lens.Type.Prism' into the Base64-url encoding of a 'ByteString' value+-- | A 'Prism'' into the Base64url encoding of a 'ByteString' value -- -- Please note that unpadded variants should only be used -- when assumptions about the data can be made. In particular, if the length of@@ -105,11 +114,43 @@ -- Just "<<??>>" -- _Base64UrlUnpadded :: Prism' ByteString ByteString-_Base64UrlUnpadded = prism' B64U.encodeBase64Unpadded $ \s -> case B64U.decodeBase64Unpadded s of+_Base64UrlUnpadded = prism' B64U.encodeBase64Unpadded' $ \s -> case B64U.decodeBase64Unpadded s of     Left _ -> Nothing     Right a -> Just a {-# INLINE _Base64UrlUnpadded #-} +#if MIN_VERSION_base64(0,3,0)+-- | An 'Iso'' into the Base64 encoding of a 'ByteString' value+-- using lenient decoding.+--+--+-- _Note:_ This is not a lawful 'Iso'.+--+-- >>> "Sun" ^. _Base64Lenient+-- "U3Vu"+--+-- >>> "U3Vu" ^. from _Base64Lenient+-- "Sun"+--+_Base64Lenient :: Iso' ByteString ByteString+_Base64Lenient = iso B64.encodeBase64' B64.decodeBase64Lenient++-- | An 'Iso'' into the Base64url encoding of a 'ByteString' value+-- using lenient decoding.+--+--+-- _Note:_ This is not a lawful 'Iso'.+--+-- >>> "<<??>>" ^. _Base64UrlLenient+-- "PDw_Pz4-"+--+-- >>> "PDw_Pz4-" ^. from _Base64UrlLenient+-- "<<??>>"+--+_Base64UrlLenient :: Iso' ByteString ByteString+_Base64UrlLenient = iso B64U.encodeBase64' B64U.decodeBase64Lenient+#endif+ -- -------------------------------------------------------------------------- -- -- Patterns @@ -136,3 +177,19 @@ pattern Base64UrlUnpadded :: ByteString -> ByteString pattern Base64UrlUnpadded a <- (preview _Base64UrlUnpadded -> Just a) where     Base64UrlUnpadded a = _Base64UrlUnpadded # a++#if MIN_VERSION_base64(0,3,0)+-- | Bidirectional pattern synonym for leniently Base64-encoded 'ByteString' values+--+pattern Base64Lenient :: ByteString -> ByteString+pattern Base64Lenient a <- (view (from _Base64Lenient) -> a) where+    Base64Lenient a = view _Base64Lenient a+{-# COMPLETE Base64Lenient #-}++-- | Bidirectional pattern synonym for leniently Base64-encoded 'ByteString' values+--+pattern Base64UrlLenient :: ByteString -> ByteString+pattern Base64UrlLenient a <- (view (from _Base64UrlLenient) -> a) where+    Base64UrlLenient a = view _Base64UrlLenient a+{-# COMPLETE Base64UrlLenient #-}+#endif
src/Data/Text/Encoding/Base64/Lens.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} -- |@@ -9,7 +10,7 @@ -- Stability	: Experimental -- Portability	: non-portable ----- This module contains 'Control.Lens.Type.Prism's Base64-encoding and+-- This module contains 'Prism's Base64-encoding and -- decoding 'Text' values. -- module Data.Text.Encoding.Base64.Lens@@ -18,14 +19,21 @@ , _Base64Url , _Base64Unpadded , _Base64UrlUnpadded+#if MIN_VERSION_base64(0,3,0)+, _Base64Lenient+, _Base64UrlLenient+#endif   -- * Patterns , pattern Base64 , pattern Base64Url , pattern Base64Unpadded , pattern Base64UrlUnpadded+#if MIN_VERSION_base64(0,3,0)+, pattern Base64Lenient+, pattern Base64UrlLenient+#endif ) where - import Control.Lens  import Data.Text (Text)@@ -44,7 +52,7 @@ -- -------------------------------------------------------------------------- -- -- Optics --- | A 'Control.Lens.Type.Prism' into the Base64 encoding of a 'Text' value.+-- | A 'Prism' into the Base64 encoding of a 'Text' value. -- -- >>> _Base64 # "Sun" -- "U3Vu"@@ -58,7 +66,7 @@     Right a -> Just a {-# INLINE _Base64 #-} --- | A 'Control.Lens.Type.Prism' into the Base64-url encoding of a 'Text' value.+-- | A 'Prism' into the Base64-url encoding of a 'Text' value. -- -- >>> _Base64Url # "Sun" -- "U3Vu"@@ -72,7 +80,7 @@     Right a -> Just a {-# INLINE _Base64Url #-} --- | A 'Control.Lens.Type.Prism' into the unpadded Base64 encoding of a+-- | A 'Prism' into the unpadded Base64 encoding of a -- 'Text' value. -- -- Please note that unpadded variants should only be used@@ -91,7 +99,7 @@     Right a -> Just a {-# INLINE _Base64Unpadded #-} --- | A 'Control.Lens.Type.Prism' into the Base64-url encoding of a 'Text' value.+-- | A 'Prism' into the Base64-url encoding of a 'Text' value. -- -- Please note that unpadded variants should only be used -- when assumptions about the data can be made. In particular, if the length of@@ -109,29 +117,77 @@     Right a -> Just a {-# INLINE _Base64UrlUnpadded #-} +#if MIN_VERSION_base64(0,3,0)+-- | An 'Iso'' into the Base64 encoding of a 'Text' value+-- using lenient decoding.+--+--+-- _Note:_ This is not a lawful 'Iso'.+--+-- >>> "Sun" ^. _Base64Lenient+-- "U3Vu"+--+-- >>> "U3Vu" ^. from _Base64Lenient+-- "Sun"+--+_Base64Lenient :: Iso' Text Text+_Base64Lenient = iso B64T.encodeBase64 B64T.decodeBase64Lenient++-- | An 'Iso'' into the Base64url encoding of a 'Text' value+-- using lenient decoding.+--+--+-- _Note:_ This is not a lawful 'Iso'.+--+-- >>> "<<??>>" ^. _Base64UrlLenient+-- "PDw_Pz4-"+--+-- >>> "PDw_Pz4-" ^. from _Base64UrlLenient+-- "<<??>>"+--+_Base64UrlLenient :: Iso' Text Text+_Base64UrlLenient = iso B64TU.encodeBase64 B64TU.decodeBase64Lenient+#endif+ -- -------------------------------------------------------------------------- -- -- Patterns --- | Bidirectional pattern synonym for base64-encoded 'Text' values.+-- | Unidirectional pattern synonym for base64-encoded 'Text' values. -- pattern Base64 :: Text -> Text-pattern Base64 a <- (preview _Base64 -> Just a)-  where Base64 a = _Base64 # a+pattern Base64 a <- (preview _Base64 -> Just a) where+    Base64 a = _Base64 # a --- | Bidirectional pattern synonym for base64url-encoded 'Text' values.+-- | Unidirectional pattern synonym for base64url-encoded 'Text' values. -- pattern Base64Url :: Text -> Text-pattern Base64Url a <- (preview _Base64Url -> Just a)-  where Base64Url a = _Base64Url # a+pattern Base64Url a <- (preview _Base64Url -> Just a) where+    Base64Url a = _Base64Url # a --- | Bidirectional pattern synonym for unpadded base64-encoded 'Text' values.+-- | Unidirectional pattern synonym for unpadded base64-encoded 'Text' values. -- pattern Base64Unpadded :: Text -> Text-pattern Base64Unpadded a <- (preview _Base64Unpadded -> Just a)-  where Base64Unpadded a = _Base64Unpadded # a+pattern Base64Unpadded a <- (preview _Base64Unpadded -> Just a) where+    Base64Unpadded a = _Base64Unpadded # a --- | Bidirectional pattern synonym for unpadded base64url-encoded 'Text' values.+-- | Unidirectional pattern synonym for unpadded base64url-encoded 'Text' values. -- pattern Base64UrlUnpadded :: Text -> Text-pattern Base64UrlUnpadded a <- (preview _Base64UrlUnpadded -> Just a)-  where Base64UrlUnpadded a = _Base64UrlUnpadded # a+pattern Base64UrlUnpadded a <- (preview _Base64UrlUnpadded -> Just a) where+    Base64UrlUnpadded a = _Base64UrlUnpadded # a++#if MIN_VERSION_base64(0,3,0)+-- | Bidirectional pattern synonym for leniently Base64-encoded 'Text' values+--+pattern Base64Lenient :: Text -> Text+pattern Base64Lenient a <- (view (from _Base64Lenient) -> a) where+    Base64Lenient a = view _Base64Lenient a+{-# COMPLETE Base64Lenient #-}++-- | Bidirectional pattern synonym for leniently Base64-encoded 'Text' values+--+pattern Base64UrlLenient :: Text -> Text+pattern Base64UrlLenient a <- (view (from _Base64UrlLenient) -> a) where+    Base64UrlLenient a = view _Base64UrlLenient a+{-# COMPLETE Base64UrlLenient #-}+#endif