Package

purescript-slug

Repository
thomashoneyman/purescript-slug
License
MIT
Uploaded by
pacchettibotti
Published on
2022-09-08T03:08:02Z

CI Latest release Latest package set Maintainer: thomashoneyman

Type-safe slugs for PureScript.

Installation

spago install slug

Use

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"

Contributing

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.

Modules
Slug
Dependencies