Version: v0.7.1 - Beta.  We welcome contributors & feedback.

String.slug

slug($delimiter = '-') -> string

Description

Convert the string to lower-case, and join words with $delimiter.

A word is any substring that starts with an upper-case character (e.g. in “camelCase”), or is separated by non-alphanumeric characters (spaces, punctuation, etc).

Origin

A “slug” is a token that is commonly added to a URL to make it more human readable and optimized for search engines. (The term comes from the publishing industry.)

https://myblog.com/post/4252/my-top-10-recipes
                             ^^^^^^^^^^^^^^^^^

Examples

'list of posts'.slug()
//= 'list-of-posts'

'listOfPosts'.slug()
//= 'list-of-posts'

'list of posts'.slug('_')
//= 'list_of_posts'

See Also