sqids: Sqids is a small library that lets you generate YouTube-looking IDs from numbers.

[ library, mit, web ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/sqids/sqids-haskell#readme


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.2.1, 0.1.3.0, 0.1.4.0, 0.2.0.0, 0.2.1.0, 0.2.2.0
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), containers (>=0.6.7 && <0.7.0), mtl (>=2.2.2 && <2.3.0), text (>=2.0.2 && <2.1.0), transformers (>=0.5.6.2 && <0.6.0.0) [details]
License MIT
Copyright 2023-present Sqids maintainers
Author Heikki Johannes Hildén
Maintainer hildenjohannes@gmail.com
Category Web
Home page https://sqids.org/
Bug tracker https://github.com/github.com/sqids/issues
Source repo head: git clone https://github.com/github.com/sqids(sqids-haskell)
Uploaded by arbelos at 2023-07-09T20:54:47Z
Distributions LTSHaskell:0.2.2.0, Stackage:0.2.2.0
Downloads 261 total (29 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
All reported builds failed as of 2023-07-09 [all 1 reports]

Readme for sqids-0.1.0.0

[back to package description]

Sqids Haskell

Haskell CI

Sqids (pronounced "squids") is a small library that lets you generate YouTube-looking IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

Getting started

Installation

@todo

Usage

module Main where

import Web.Sqids

main :: IO ()
main =
  case sqids (encode [1, 2, 3]) of
    Left  {}   -> print "Something went wrong."
    Right sqid -> print sqid
"8QRLaD"
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Web.Sqids

main :: IO ()
main =
  case sqids (decode "8QRLaD") of
    Left  {}   -> print "Something went wrong."
    Right nums -> print nums
[1,2,3]
main =
  case runSqids defaultSqidsOptions{ minLength = 24 } (encode [1, 2, 3]) of
    Left  {}   -> print "Something went wrong."
    Right sqid -> print sqid
"75JILToVsGerOADWmT1cd0dL"
main = do
  let options = SqidsOptions
        { alphabet  = "1234567890"
        , minLength = 8
        , blocklist = []
        }
  case runSqids options (encode [1, 2, 3]) of
    Left  {}   -> print "Something went wrong."
    Right sqid -> print sqid
"31764540"

Monad transformer

module Main where

import Control.Monad (forM_)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Writer (WriterT, execWriterT, tell)
import Data.Text (Text)
import Web.Sqids

main :: IO ()
main = do
  w <- execWriterT (sqidsT makeIds)
  print w

makeIds :: SqidsT (WriterT [Text] IO) ()
makeIds = do
  liftIO $ print "Generating IDs"
  forM_ [1 .. 50] $ \n -> do
    sqid <- encode [n, n, n, n]
    lift (tell [sqid])
["QkA3AmAC","fh9rtRtv","a7totm7V","KF5Z5l4X","ngqSq2b3","pjkCJlJf","yTrOSYSQ","HKVia9J2","0gTF2Zr3","jiw7wbw1","PtNNFWFA","I0vlvGvD","08TV2Sr5","UPLILMlD","ut2A2D20","Inv5vZvK","pDkBJTJJ","P1N8FRFr","R2eqeYeY","Ki5o5Q4U","1k70bzbD","dK4cE6Es","1L7XbJbZ","FyGjG1G0","ZEMReNre","aKtMte79","UtLNL9li","o6lElt2f","1w7ebtbl","nuqNqqbk","HlVSaOJ9","IKvdvave","3cWkDSD9","oQlzlc2C","RrezeDeC","OhJcJoVR","OEJFJzVJ","oplJlm2F","u8292F2H","FZGiGzGI","dN40E9EO","Q0AdAhAR","HJVzaaJC","s08YCUdX","sW8UCadW","ZaMNekrp","X4bsWS4Z","OoJIJEVj","Rqe1eTey","3aWYDXDs"]

@todo

Types

SqidsOptions

@todo

SqidsError

@todo

SqidsT

@todo

Sqids

@todo

Type classes

MonadSqids

@todo

Functions

encode

@todo

decode

@todo

sqidsVersion

@todo

defaultSqidsOptions

@todo

sqidsOptions

@todo

runSqidsT

@todo

sqidsT

This is a short form for runSqidsT defaultSqidsOptions.

runSqids

@todo

sqids

This is a short form for runSqids defaultSqidsOptions.

Examples

@todo

License

MIT