packages feed

NanoID 2.0.0 → 2.1.0

raw patch · 5 files changed

+12/−9 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

NanoID.cabal view
@@ -1,5 +1,5 @@ name:                NanoID-version:             2.0.0+version:             2.1.0 synopsis:            NanoID generator description:         Library and CLI tool for NanoID generation license:             BSD3
ReadMe.md view
@@ -2,7 +2,7 @@  ``` [user@box ~] $ nanoid -h-nanoid v2.0.0, (c) Michel Boucey 2021+nanoid v2.1.0, (c) Michel Boucey 2021  Usage: nanoid [-a|--alphabet ARG] [-l|--length ARG] [-q|--quantity ARG]                [-n|--newline]
app/Main.hs view
@@ -13,8 +13,8 @@ main :: IO () main = do   Options{..} <- execParser opts-  if length < 1 -    then putStrLn "Strange (nano)idea... less than one char" >> exitFailure+  if length < 1 || quantity < 1+    then putStrLn "Bad numeric input. See help (-h)." >> exitFailure     else do       let alphabet' = Alphabet { unAlphabet = C.pack alphabet }       replicateM_ quantity $
app/Options.hs view
@@ -16,7 +16,7 @@ opts = info (options <**> helper)   ( fullDesc     <> progDesc "NanoID generator"-    <> header "nanoid v1.0.0, (c) Michel Boucey 2021" )+    <> header "nanoid v2.1.0, (c) Michel Boucey 2021" )  options :: Parser Options options =
src/Data/NanoID.hs view
@@ -15,16 +15,19 @@ nanoID = createSystemRandom >>= customNanoID defaultAlphabet Nothing  customNanoID :: Alphabet -> Maybe Length -> GenIO-> IO (Either String NanoID)-customNanoID a l g =+customNanoID a l g = do+  let l' = fromMaybe 21 l+  when (l' < 1) (fail "Negative length for a NanoID")   let ua = unAlphabet a-      al = C.length ua in-  pure . NanoID . C.pack <$> replicateM (fromMaybe 21 l) ((\r -> C.index ua (r-1)) <$> uniformR (1,al) g)+      al = C.length ua+  pure . NanoID . C.pack <$> replicateM l' ((\r -> C.index ua (r-1)) <$> uniformR (1,al) g)  -- | The default 'Alphabet', made of URL-friendly symbols. defaultAlphabet :: Alphabet defaultAlphabet = Alphabet (C.pack "ABCDEFGHIJKLMNOPKRSTUVWXYZ_1234567890-abcdefghijklmnopqrstuvwxyz") --- | Predefined 'Alphabet's borrowed from <https://github.com/CyberAP/nanoid-dictionary>+-- * Predefined Alphabets borrowed from https://github.com/CyberAP/nanoid-dictionary+ numbers :: Alphabet numbers = Alphabet (C.pack "1234567890")