Skip to content
A Java library for creating nice URL Slugs
Java Gherkin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper chore(deps): update dependency gradle to v6.1.0 (#43) Jan 17, 2020
src test(bdd): move features out of silly top-level directory in resources ( Sep 10, 2019
.gitignore build(git): update gitignore - remove unnecessary project types (e.g.… Sep 19, 2019
.travis.yml ci(travis): add initial travis config Sep 9, 2019
LICENSE docs(license): set copyright in license (#31) Sep 19, 2019
README.md Link license shield to license file Feb 19, 2016
build.gradle chore(deps): update cucumber to v4.8.1 (#42) Jan 12, 2020
gradlew build(gradle): update gradle wrapper to use newer version. add gradle… Sep 10, 2019
gradlew.bat
renovate.json ci(renovate): Group Cucumber dependencies in Renovate (#38) Nov 16, 2019

README.md

Slugger - A Java library for creating nice URL Slugs

Build Status Coverage Status License

Overview

Instances of a Slugger object provide a way to generate "slugs", that can be used in URLs on the web. Inputs can be split into words in a variety of ways and the length of the output can be restricted if required. Any CharSequence can be used as the joining character between consecutive words. Characters that would require escaping in a URL are removed or replaced, as appropriate.

Getting Started

The simplest usage of Slugger would be something like the following:

Slugger slugger = Slugger.create();
String firstTitle = slugger.sluggify("My first blog post"); // my-first-blog-post
String secondTitle = slugger.sluggify("Another post!"); // another-post

This creates an instance of a Slugger with the default configuration, which splits the input on whitespace, removes special characters, and converts the output to lowercase.

Word Splitters

By default, a Slugger will split the supplied input into words based on whitespace, although a number of alternative word splitters are provided (and the interface is publicly exposed for extensibility).

To replace the default splitter, use the withWordSplitter(WordSplitter ws) method as follows:

Slugger slugger = Slugger.create().withWordSplitter(WordSplitters.camelCaseWordSplitter());
slugger.sluggify("MyFirstBlogPost"); // my-first-blog-post

Splitters can also be chained, so you can split on both whitespace and camel-case, as follows:

Slugger slugger = Slugger.create().withAdditionalWordSplitter(WordSplitters.camelCaseWordSplitter());
slugger.sluggify("The importance of toString()"); //the-importance-of-to-string
You can’t perform that action at this time.