FastSlugger 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package FastSlugger --version 0.0.1
NuGet\Install-Package FastSlugger -Version 0.0.1
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="FastSlugger" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FastSlugger --version 0.0.1
#r "nuget: FastSlugger, 0.0.1"
#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 FastSlugger as a Cake Addin
#addin nuget:?package=FastSlugger&version=0.0.1

// Install FastSlugger as a Cake Tool
#tool nuget:?package=FastSlugger&version=0.0.1

What is it

A slug creator.

Example slugs

Input Output
text.contains.!marks#: textcontainsmarks
Hello Kønnìchiwa hello-konnichiwa
some--LONG_space-- some-long_space-
👑 🌴 crown-palm_tree
Привет privet

Behind the scenes, this uses the package AnyAscii slugger, which also transliterates.

This library then uses dashes to separate-words and makes all characters lowercase.
Any punctuation, such as # or . are removed.
Any consecutive dashes are squashed to a single dash.
Any connector punctuation such as are converted to _.

Installation

dotnet add package FastSlugger

Usage

using FastSlugger;

var text = "Create a new slug! Frøm ènglish#---txt";

// Output: "create-a-new-slug-from-english-txt"
var slug = Slug.Create(text);

You can configure the slugger by overriding the default parameter values for the connector character, the separator character and how long the slug should maximally be.

Remarks

This library uses stack allocation if the slug length is less than 1000 characters, which can be seen by the benchmark result.

The AnyAscii library seems to be a huge custom lookup table.

Furthermore the string creation uses the high performance community toolkit library to minimize string allocation.

Benchmark results

System
BenchmarkDotNet v0.13.12, Ubuntu 23.04 (Lunar Lobster) WSL AMD Ryzen 7 3700X, 1 CPU, 4 logical and 2 physical cores .NET SDK 8.0.203 [Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2 DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2

Result
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | |-------------- |----------:|---------:|---------:|------:|--------:|-------:|----------:|------------:| | SlugifyCore | 926.45 us | 4.951 us | 4.631 us | 28.97 | 0.13 | - | 39.67 KB | 8.97 | | FastSlugger | 31.96 us | 0.093 us | 0.082 us | 1.00 | 0.00 | - | 4.42 KB | 1.00 | | SlugGenerator | 45.97 us | 0.111 us | 0.104 us | 1.44 | 0.00 | 0.1221 | 13.16 KB | 2.98 |

Outliers
SpeedComparisonBenchmarks.FastSlugger: Default → 1 outlier was removed (32.78 us)

Package versions used:
Slugify.Core v.2.0.2
SlugGenerator v.4.0.1

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 89 4/11/2024
0.0.1 87 4/9/2024