Skip to content

A simple NuGet package that converts a string to an URL-friendly string, also called a slug.

License

Notifications You must be signed in to change notification settings

marthijn/Sidio.Text.Slugify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sidio.Text.Slugify

Sidio.Text.Slugify is a simple NuGet package that converts a string to an URL-friendly string, also called a slug.

For example, the string Hello, World! will be converted to hello-world.

build NuGet Version Coverage Status

Installation

Add the NuGet package to your project.

Usage

Dependency injection

services.AddSlugifier();
// - or -
services.AddSlugifier(options => {
    options.AddDefaultProcessors = false;
    options.Processors.Add(new LowerCaseProcessor());
}); 
public class MyClass()
{
    public MyClass(ISlugifier slugifier)
    {
        var slug = slugifier.Slugify("Hello, World!");
    }
}

Direct usage

var slugifier = Slugifier.Create();
var slug = slugifier.Slugify("Hello, World!");

Extensions

Using the extension method is not recommended because it creates a new instance of the Slugifier class every time it is called.

using Sidio.Text.Slugify.Extensions;

var slug = "Hello, World!".Slugify();

Extensibility

You can implement your own processors by implementing the SlugifyProcessor class. For example:

public sealed class RemoveExclamationMarkProcessor : SlugifyProcessor
{
    protected override string ProcessInput(string input)
    {
        return input.Replace("!", string.Empty);
    }

    // run this processor first
    public override int Order => 0; // or int.MaxValue for last
}

About

A simple NuGet package that converts a string to an URL-friendly string, also called a slug.

Topics

Resources

License

Stars

Watchers

Forks

Languages