NanoID 3.0.0 → 3.1.0
raw patch · 3 files changed
+34/−9 lines, 3 filesdep +aesondep +cerealdep +textPVP ok
version bump matches the API change (PVP)
Dependencies added: aeson, cereal, text
API changes (from Hackage documentation)
+ Data.NanoID: instance Data.Aeson.Types.FromJSON.FromJSON Data.NanoID.NanoID
+ Data.NanoID: instance Data.Aeson.Types.ToJSON.ToJSON Data.NanoID.NanoID
+ Data.NanoID: instance Data.Serialize.Serialize Data.NanoID.NanoID
+ Data.NanoID: instance GHC.Generics.Generic Data.NanoID.NanoID
Files
- NanoID.cabal +8/−5
- app/Options.hs +2/−2
- src/Data/NanoID.hs +24/−2
NanoID.cabal view
@@ -1,5 +1,5 @@ name: NanoID-version: 3.0.0+version: 3.1.0 synopsis: NanoID generator description: Library and CLI tool for NanoID generation license: BSD3@@ -20,10 +20,13 @@ library exposed-modules: Data.NanoID- build-depends: base >= 4.7 && < 4.16- , bytestring >= 0.10 && < 0.12- , extra >= 1.6 && < 1.8- , mwc-random >= 0.13 && < 0.16+ build-depends: aeson >= 1.5.6 && < 1.6+ , base >= 4.7 && < 4.16+ , bytestring >= 0.10 && < 0.12+ , cereal >= 0.5.8 && < 0.5.9+ , extra >= 1.6 && < 1.8+ , mwc-random >= 0.13 && < 0.16+ , text >= 1.2.4 && < 1.3 hs-source-dirs: src default-language: Haskell2010
app/Options.hs view
@@ -16,7 +16,7 @@ opts = info (options <**> helper) ( fullDesc <> progDesc "NanoID generator"- <> header "nanoid v3.0.0, (c) Michel Boucey 2021" )+ <> header "nanoid v3.1.0, (c) Michel Boucey 2021" ) options :: Parser Options options =@@ -31,7 +31,7 @@ option auto ( short 'l' <> long "length"- <> help "Get shorter NanoID"+ <> help "Default NanoID length is 21 chars" <> value 21 ) <*> option auto
src/Data/NanoID.hs view
@@ -1,18 +1,40 @@+{-# LANGUAGE DeriveGeneric #-}+ module Data.NanoID where import Control.Monad+import Data.Aeson import qualified Data.ByteString.Char8 as C import Data.Maybe+import Data.Serialize (Serialize)+import Data.Text.Encoding+import GHC.Generics import Numeric.Natural import System.Random.MWC -newtype NanoID = NanoID { unNanoID :: C.ByteString } deriving (Eq, Show)+newtype NanoID = NanoID { unNanoID :: C.ByteString } deriving (Eq,Generic) -newtype Alphabet = Alphabet { unAlphabet :: C.ByteString } deriving (Eq, Show)+newtype Alphabet = Alphabet { unAlphabet :: C.ByteString } deriving (Eq) type Length = Natural +instance Show NanoID where+ show n = C.unpack (unNanoID n)++instance Show Alphabet where+ show a = C.unpack (unAlphabet a)++instance ToJSON NanoID where+ toJSON n = String (decodeUtf8 $ unNanoID n)++instance FromJSON NanoID where+ parseJSON (String s) = pure (NanoID $ encodeUtf8 s)+ parseJSON _ = fail "A JSON String is expected to convert to NanoID"++instance Serialize NanoID+ -- | Standard 'NanoID' generator function+-- -- >λ: g <- createSystemRandom -- >λ: NanoID g -- >NanoID {unNanoID = "x2f8yFadImeVp14ByJ8R3"}