Slugify.Core 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Slugify.Core --version 3.0.0
NuGet\Install-Package Slugify.Core -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Slugify.Core" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Slugify.Core --version 3.0.0
#r "nuget: Slugify.Core, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Slugify.Core as a Cake Addin
#addin nuget:?package=Slugify.Core&version=3.0.0

// Install Slugify.Core as a Cake Tool
#tool nuget:?package=Slugify.Core&version=3.0.0

Slugify Core

This is a fork of the original project here: https://github.com/fcingolani/Slugify. This has been updated for .NET Standard 2.0 support (older versions support .NET Standard down to 1.3).

.NET Version license

Simple Slug / Clean URL generator helper for Microsoft .NET framework.

With default settings, you will get an hyphenized, lowercase, alphanumeric version of any string you please, with any diacritics removed and collapsed whitespace, collapsed dashes and trimmed whitespace.

In example, having:

a ambição cerra o coração

You'll get:

a-ambicao-cerra-o-coracao

Installation

You can get the Slugify NuGet package by running the following command in the Package Manager Console:

PM> Install-Package Slugify.Core

Upgrading from 2.x to 3.x

  • 3.0 is a significantly faster and less memory intensive version of the Slugifier. Whilst effort has been made to maintain backwards compatability, there may be some breaking changes.
  • The SlugHelper.Config nested class has been renamed to just SlugHelperConfiguration.

Basic Usage

It's really simple! Just instantiate SlugHelper and call its GenerateSlug with the string you want to convert; it'll return the URL Safe version:

using Slugify;

public class MyApp
{
   public static void Main()
   {
      SlugHelper helper = new SlugHelper();

      String title = "OLA ke ase!";

      String slug = helper.GenerateSlug(title); // "ola-ke-ase"

      Console.WriteLine(slug);
   }
}

Configuration

You can provide a SlugHelperConfiguration instance to SlugHelper's constructor to customize the helper's behavior:

// Creating a configuration object
var config = new SlugHelperConfiguration();

// Replace spaces with a dash
config.StringReplacements.Add(" ", "-");

// We want a lowercase Slug
config.ForceLowerCase = true;

// Will collapse multiple seqential dashes down to a single one
config.CollapseDashes = true;

// Will trim leading and trailing whitespace
config.TrimWhitespace = true;

// Colapse consecutive whitespace chars into one
config.CollapseWhiteSpace = true;

// Remove everything that's not a letter, number, hyphen, dot, or underscore
config.DeniedCharactersRegex = @"[^a-zA-Z0-9\-\._]";

// Create a helper instance with our new configuration
SlugHelper helper = new SlugHelper(config);

In fact, the above values are so common they're the default ones! So last code could be rewritten as:

var config = new SlugHelperConfiguration();
SlugHelper helper = new SlugHelper(config);

One more thing: SlugHelperConfiguration is used when you call the parameterless SlugHelper constructor. Then ...

SlugHelper helper = new SlugHelper();

... is the same as running the code we had in first place.

Options

CharacterReplacements

Type: Dictionary<String, String>. Default: [" ": "-"].

Will replace the specified keys with their associated value.

By default, will replace spaces with hyphens.

ForceLowerCase

Type: Boolean. Default: true.

Setting it to true will convert output string to be LowerCase. If false, original casing will be preserved.

CollapseWhiteSpace

Type: Boolean. Default: true.

Setting it to true will replace consecutive whitespace characters by just one space (" ").

DeniedCharactersRegex

Type: String. Default: [^a-zA-Z0-9-._].

Any character matching this Regular Expression will be deleted from the resulting string.

CollapseDashes

Type: Boolean. Default: true

This will condense multiple dashes (e.g. foo---bar) down to a single dash (foo-bar). This is useful to avoid scenarios like foo & bar becoming foo--bar.

License

The MIT License (MIT)

Copyright (c) 2013 Federico Cingolani

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on Slugify.Core:

Package Downloads
Volo.CmsKit.Domain The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Package Description

ZhileTime.CmsKit.Domain

Package Description

SpiderSharp

Web Crawling and Scraping Framework

Squidex.CLI.Core

Command Line Interface for Squidex Headless CMS

HelpersToolbox

A set of C# extensions/helpers library

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Slugify.Core:

Repository Stars
abpframework/abp
Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
madskristensen/MarkdownEditor2022
A Visual Studio extension
Version Downloads Last updated
5.0.0-prerelease.4 14,473 7/24/2023
4.0.1 429,831 2/22/2023
4.0.0 2,440 2/22/2023
3.0.0 1,106,292 11/26/2020
2.3.0 840,400 8/7/2018
2.2.2 10,423 6/27/2018
2.2.1 12,860 3/15/2018
2.2.0 54,335 3/8/2017
2.1.0 42,102 9/14/2016

3.0.0 - Much improved performance and memory usage. Config file renamed. Potentially some breaking changes but none we're aware of
       2.4.0 - NetStandard 2.0 support only
       2.3.0 - ISlugHelper interface added. Thanks @jcharlesworthuk
       2.2.2 - NetStandard 2.0
       2.2.1 - NuGet package updates
       2.2.0 - Minor tweaks