![]() |
VOOZH | about |
dotnet add package Slugify.Core --version 5.1.1
NuGet\Install-Package Slugify.Core -Version 5.1.1
<PackageReference Include="Slugify.Core" Version="5.1.1" />
<PackageVersion Include="Slugify.Core" Version="5.1.1" />Directory.Packages.props
<PackageReference Include="Slugify.Core" />Project file
paket add Slugify.Core --version 5.1.1
#r "nuget: Slugify.Core, 5.1.1"
#:package Slugify.Core@5.1.1
#addin nuget:?package=Slugify.Core&version=5.1.1Install as a Cake Addin
#tool nuget:?package=Slugify.Core&version=5.1.1Install as a Cake Tool
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).
👁 Build status
👁 Current NuGet release
👁 MIT license
Simple Slug / Clean URL generator helper for Microsoft .NET.
With default settings, you will get an hyphenized, lowercase, alphanumeric version of any string you please, with any diacritics removed, whitespace and dashes collapsed, and whitespace trimmed.
For example, having:
a ambição cerra o coração
You'll get:
a-ambicao-cerra-o-coracao
You can get the Slugify NuGet package by running the following command in the Package Manager Console:
PM> Install-Package Slugify.Core
Or running dotnet add package Slugify.Core from the command line.
DeniedCharactersRegex is no longer a string, and it now takes in a Regex object. This will allow you to use Source Generated regexes on platforms that support them. Using something like:[GeneratedRegex(@"[^a-z0-9\-\._]")]
private static partial Regex GeneratedRegex();
- by default and will instead be stripped. This will only be a noticeable change if you have disabled CollapseDashes (which is not the default).AllowedChars is renamed to AllowedCharacters.SlugHelper.Config nested class has been renamed to just SlugHelperConfiguration.It's really simple! Just instantiate SlugHelper and call its GenerateSlug method with the string you want to convert; it'll return the slugified version:
using Slugify;
public class MyApp
{
public static void Main()
{
SlugHelper helper = new SlugHelper();
String title = "OLA ke ase!";
String slug = helper.GenerateSlug(title);
Console.WriteLine(slug); // "ola-ke-ase"
}
}
If you want to support non-ASCII characters, you can use the SlugHelperForNonAsciiLanguages class instead of SlugHelper. This is a derived class which will translate the characters provided into something "equivalent" in ASCII.
The default configuration of SlugHelper will make the following changes to the passed input in order to generate a slug:
You can customize most of this behavior by passing a SlugHelperConfiguration object to the SlugHelper constructor. For example, the following example will keep upper-case characters in the input and provides a custom handling for ampersands in the input:
// Creating a configuration object
var config = new SlugHelperConfiguration();
// Add individual replacement rules
config.StringReplacements.Add("&", "-");
config.StringReplacements.Add(",", "-");
// Keep the casing of the input string
config.ForceLowerCase = false;
// Create a helper instance with our new configuration
var helper = new SlugHelper(config);
var result = helper.GenerateSlug("Simple,short&quick Example");
Console.WriteLine(result); // Simple-short-quick-Example
The following options can be configured with the SlugHelperConfiguration:
ForceLowerCaseThis specifies whether the output string should be converted to lower-case. If set to false, the original casing will be preserved. The lower-case conversion happens before any other character replacements are being made.
trueTrimWhitespaceThis specifies whether leading and trailing whitespace should be removed from the input string. The whitespace will be trimmed before any other character replacements are being made.
trueCollapseDashesThis specifies wehther consecutive dashes ("-") should be collapsed into a single dash. This is useful to avoid scenarios like "foo & bar" becoming "foo--bar". Dashes will be collapsed after all other string replacements have been made before the final result string is returned.
trueStringReplacementsThis is a dictionary containing a mapping of characters that should be replaced individually before the translation happens. By default, this will replace space characters with a hyphen.
String replacements are being made after whitespace has been trimmed and collapsed, after the input string has been converted to lower-case characters, but before any characters are removed, to allow replacing characters that would otherwise be just removed.
Default value:
new Dictionary<string, string> {
[" "] = "-", // replace space with a hyphen
}
Examples:
var config = new SlugHelperConfiguration();
// replace the dictionary completely
config.StringReplacements = new() {
["ä"] = "ae",
["ö"] = "oe",
["ü"] = "ue",
};
// or add individual replacements to it
config.StringReplacements.Add("ß", "ss");
AllowedCharactersSet of characters that are allowed in the slug, which will be kept when the input string is being processed. By default, this contains all ASCII characters, the full stop, the dash and the underscore. This is the preferred way of controlling which characters should be replaced when generating the slug.
Characters that are not allowed will be replaced after string replacements are completed.
Default value: Alphanumerical ASCII characters, the full stop (.), the dash (-), and the underscore (-).
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._)
Examples:
var config = new SlugHelperConfiguration();
// add individual characters to the list of allowed characters
config.AllowedCharacters.Add('!');
// remove previously added or default characters
config.AllowedCharacters.Remove('.');
DeniedCharactersRegexAlternative method of specifying which characters will be allowed in the slug, which will replace the functionality of the AllowedChars set. The value must be a valid regular expression that specifies which characters are to be removed. Every match of this regular expression in the input string will be removed. The removal happens after string replacements are completed.
Specifying the DeniedCharactersRegex option will disable the character removal behavior from the AllowedChars option.
Default value: null
Examples:
var helper = new SlugHelper(new SlugHelperConfiguration
{
// this is equivalent to the default behavior from `AllowChars`
DeniedCharactersRegex = new(@"[^a-zA-Z0-9._-]")
});
Console.WriteLine(helper.GenerateSlug("OLA ke ase!")); // "ola-ke-ase"
helper = new SlugHelper(new SlugHelperConfiguration
{
// remove certain characters explicitly
DeniedCharactersRegex = new(@"[abcdef]")
});
Console.WriteLine(helper.GenerateSlug("abcdefghijk")); // "ghijk"
helper = new SlugHelper(new SlugHelperConfiguration
{
// remove more complex matches
DeniedCharactersRegex = new(@"foo|bar")
});
Console.WriteLine(helper.GenerateSlug("this is an foo example")); // "this-is-an-example"
MaximumLengthThis will limit the length of the generated slug to be a maximum of the number of chars given by the parameter. If the truncation happens in a way that a trailing - is left, it will be removed.
null| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Slugify.Core:
| Package | Downloads |
|---|---|
|
N3O.Umbraco.Extensions
TODO |
|
|
Volo.CmsKit.Domain
Package Description |
|
|
ZhileTime.CmsKit.Domain
Package Description |
|
|
VeeFriends.WikiImporter
VeeFriends Wiki Importer - A .NET library for automating the import of character data from ClickUp, enhanced with AI and media integrations. |
|
|
Yseer.Catalog.Domain
Package Description |
Showing the top 1 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. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 5.1.1 | 1,322,492 | 3/18/2025 |
| 5.1.1-prerelease.179 | 220 | 3/18/2025 |
| 5.1.1-prerelease.177 | 206 | 3/18/2025 |
| 5.0.0-prerelease.167 | 242 | 3/18/2025 |
| 5.0.0-prerelease.166 | 231 | 3/18/2025 |
| 5.0.0-prerelease.4 | 119,951 | 7/24/2023 |
| 4.0.1 | 1,941,468 | 2/22/2023 |
| 4.0.0 | 7,338 | 2/22/2023 |
| 3.0.0 | 1,540,953 | 11/26/2020 |
| 2.3.0 | 1,234,883 | 8/7/2018 |
| 2.2.2 | 11,310 | 6/27/2018 |
| 2.2.1 | 13,935 | 3/15/2018 |
| 2.2.0 | 98,122 | 3/8/2017 |
| 2.1.0 | 63,234 | 9/14/2016 |
5.1.1 - Fixes issue with Turkish `i` character.
5.1.0 - Adds support for MaximumLength to limit the length of the slug. Thanks @ntbm
5.0.0 - Rewrite using newer language features. Added support for Non-Ascii languages for SlugHelperForNonAsciiLanguages
4.0.0 - Bug fix relase from 3.0.0
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