packages feed

NanoID 1.0.1 → 1.2.0

raw patch · 4 files changed

+36/−12 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.NanoID: customNanoID :: Alphabet -> Length -> GenIO -> IO NanoID
+ Data.NanoID: customNanoID :: Alphabet -> Length -> GenIO -> IO (Either String NanoID)
- Data.NanoID: nanoID :: IO NanoID
+ Data.NanoID: nanoID :: IO (Either String NanoID)

Files

NanoID.cabal view
@@ -1,5 +1,5 @@ name:                NanoID-version:             1.0.1+version:             1.2.0 synopsis:            NanoID generator description:         Library and CLI tool for NanoID generation license:             BSD3@@ -10,6 +10,7 @@ category:            Data build-type:          Simple cabal-version:       >=1.10+extra-source-files:  ReadMe.md  Tested-With: GHC ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.1 || ==8.10.4 || ==9.0.1 @@ -19,7 +20,7 @@  library   exposed-modules:     Data.NanoID-  build-depends:       base       >=4.7 && < 4.16+  build-depends:       base       >= 4.7 && < 4.16                      , bytestring >= 0.10 && < 0.12                      , extra      >= 1.6 && < 1.8                      , mwc-random >= 0.13 && < 0.16@@ -29,7 +30,7 @@ executable nanoid   main-is:             Main.hs   other-modules:       Options-  build-depends:       base                 >=4.7 && < 4.16+  build-depends:       base                 >= 4.7 && < 4.16                      , bytestring           >= 0.10 && < 0.12                      , mwc-random           >= 0.13 && < 0.16                      , NanoID
+ ReadMe.md view
@@ -0,0 +1,18 @@+# NanoID generator, library and CLI tool [![Build Status](https://travis-ci.org/MichelBoucey/NanoID.svg?branch=main)](https://travis-ci.org/github/MichelBoucey/NanoID)++```+[user@box ~] $ nanoid -h+nanoid v1.0.1, (c) Michel Boucey 2021++Usage: nanoid [-a|--alphabet ARG] [-l|--length ARG] [-q|--quantity ARG] +              [-n|--newline]+  NanoID generator++Available options:+  -a,--alphabet ARG        Use an alternative alphabet (ascii chars only)+  -l,--length ARG          Get shorter NanoID+  -q,--quantity ARG        Quantity of NanoID to generate+  -n,--newline             Do not output the trailing newline+  -h,--help                Show this help text+```+
app/Main.hs view
@@ -2,6 +2,7 @@  import           Control.Monad import qualified Data.ByteString.Char8 as C+import           Data.Either import           Options.Applicative import           System.Exit import           System.Random.MWC@@ -17,8 +18,9 @@     else do       let alphabet' = Alphabet { unAlphabet = C.pack alphabet }       replicateM_ quantity $-        unNanoID <$> (createSystemRandom >>= customNanoID alphabet' length) >>= putNanoID newline+        createSystemRandom >>= customNanoID alphabet' length >>= putNanoID newline       exitSuccess-      where-        putNanoID n = if n then C.putStrLn else C.putStr+        where+          putNanoID nl = either (put nl . C.pack) (put nl . unNanoID)+            where put nl = if nl then C.putStrLn else C.putStr 
src/Data/NanoID.hs view
@@ -13,12 +13,15 @@ defaultAlphabet :: Alphabet defaultAlphabet = Alphabet (C.pack "ABCDEFGHIJKLMNOPKRSTUVWXYZ_-abcdefghijklmnopqrstuvwxyz") -nanoID :: IO NanoID+nanoID :: IO (Either String NanoID) nanoID = createSystemRandom >>= customNanoID defaultAlphabet 21 -customNanoID :: Alphabet -> Length -> GenIO-> IO NanoID-customNanoID a l g = do-  let acs = unAlphabet a-      al = C.length acs-  NanoID . C.pack <$> replicateM l ((\r -> C.index acs (r-1)) <$> uniformR (1,al) g)+customNanoID :: Alphabet -> Length -> GenIO-> IO (Either String NanoID)+customNanoID a l g =+  if l > 21+    then return (Left "The length of NanoID is less or equal to 21")+    else do+      let acs = unAlphabet a+          al = C.length acs+      pure . NanoID . C.pack <$> replicateM l ((\r -> C.index acs (r-1)) <$> uniformR (1,al) g)