All Projects → thomashoneyman → purescript-slug

thomashoneyman / purescript-slug

Licence: MIT license
Type-safe slugs for PureScript

Programming Languages

purescript
368 projects
Dhall
116 projects
Nix
1067 projects

Slug

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].