hecrj / elm-slug / Slug

Type-safe slugs for Elm

Definition


type Slug

Represents a slug

Constructors

generate : String -> Maybe Slug

Generate a valid slug from a given text.

If a valid slug can be generated it returns just the slug, otherwise nothing is returned.

generate "Some text here" == Just (Slug "some-text-here")
generate "--!@ยท==)/()" == Nothing

parse : String -> Maybe Slug

Parse a slug from its string representation.

It returns the slug if the input is a valid slug, otherwise it returns nothing.

parse "some-valid-slug" == Just (Slug "some-valid-slug")
parse "Not a valid slug" == Nothing
parse "another-invalid-slug-" == Nothing

Helpers

toString : Slug -> String

Returns the string representation of a slug.

Maybe.map toString (generate "Some text") == Just "some-text"