Type-safe slugs for PureScript.
spago install slug
This package provides a Slug
type and related type classes & helper functions to help you construct and use type-safe slugs. When you have a Slug
, you can be sure:
- it isn't empty
- it only contains alpha-numeric groups of characters separated by dashes (
-
) - it does not start or end with a dash
- there are never two dashes in a row
- every character is lower cased
This library currently only supports characters within the Latin-1 character set.
Create a slug with Slug.generate
:
generate :: String -> Maybe Slug
> show $ Slug.generate "This is an article!"
> Just (Slug "this-is-an-article")
> show $ Slug.generate "¬¬¬{}¬¬¬"
> Nothing
Parse a string that is (supposedly) already a slug with Slug.parse
:
parse :: String -> Either SlugError Slug
> Slug.parse "this-is-an-article"
> Just (Slug "this-is-an-article")
> Slug.parse "-this-is--not-"
> Nothing
Recover a string from a valid Slug
with Slug.toString
:
toString :: Slug -> String
> Slug.toString (mySlug :: Slug)
> "this-is-an-article"
Read the contribution guidelines to get started and see helpful related resources.
Inspired by the Haskell slug library by @mrkkrp. Some naming conventions mirror elm-slug.