/Minerals.StringCases

Optimized NuGet package with minimum memory allocation designed to help you convert strings to name cases such as Pascal, Camel, Kebab, Snake, Macro, Train and Title

Primary LanguageC#MIT LicenseMIT

Minerals.StringCases

GitHub License NuGet Version NuGet Downloads

Package on nuget.org

Optimized NuGet package with minimum memory allocation designed to help you convert strings to names cases such as Pascal, Camel, Kebab, Snake, Macro, Train and Title.

Features

  • Wide choice of cases: PascalCase, camelCase, _underscoreCamelCase, kebab-case, snake_case, MACRO_CASE, Train-Case, Title Case.
  • Performance: The package is optimized for speed and memory allocation.
  • Universal: Convert from any freely formatted string.
  • Compatible with .NET Standard 2.0: Works on a wide range of platforms and development environments.

Installation

Add the Minerals.StringCases nuget package to your C# project using the following methods:

1. Project file definition

<PackageReference Include="Minerals.StringCases" Version="0.2.1" />

2. dotnet command

dotnet add package Minerals.StringCases

Usage

using Minerals.StringCases;

string sampleText = "  _ example Variable - - Name   321";

string pascalCase = sampleText.ToPascalCase();
// ExampleVariableName321

string camelCase = sampleText.ToCamelCase();
// exampleVariableName321

string underscoreCamelCase = sampleText.ToUnderscoreCamelCase();
// _exampleVariableName321

string kebabCase = sampleText.ToKebabCase();
// example-variable-name-321

string snakeCase = sampleText.ToSnakeCase();
// example_variable_name_321

string macroCase = sampleText.ToMacroCase();
// EXAMPLE_VARIABLE_NAME_321

string trainCase = sampleText.ToTrainCase();
// Example-Variable-Name-321

string titleCase = sampleText.ToTitleCase();
// Example Variable Name 321

Performance and comparison

Here is a comparison of the speed and amount of memory allocation with the most popular NuGet package similar to Minerals.StringCases version 0.2.0 - CaseExtesions version 1.1.0.

String used to perform the comparison:

string sampleText = "  _ example Variable - - Name   321";

Results

BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
AMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores
.NET SDK 8.0.301
  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2
  Job-KUHBVV : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2

Runtime=.NET 8.0  
Method Mean Error StdDev Gen0 Allocated
PascalCase_Minerals_StringCases 158.4 ns 0.95 ns 0.79 ns 0.0343 144 B
CamelCase_Minerals_StringCases 167.4 ns 1.94 ns 1.72 ns 0.0343 144 B
SnakeCase_Minerals_StringCases 182.4 ns 0.71 ns 0.63 ns 0.0362 152 B
KebabCase_Minerals_StringCases 196.0 ns 1.75 ns 1.55 ns 0.0362 152 B
TrainCase_Minerals_StringCases 206.1 ns 2.62 ns 2.46 ns 0.0362 152 B
- - - - - -
PascalCase_CaseExtensions 505.9 ns 1.83 ns 1.71 ns 0.0973 408 B
KebabCase_CaseExtensions 506.1 ns 1.68 ns 1.49 ns 0.0992 416 B
CamelCase_CaseExtensions 520.6 ns 4.91 ns 4.59 ns 0.0973 408 B
SnakeCase_CaseExtensions 525.1 ns 3.05 ns 2.55 ns 0.0992 416 B
TrainCase_CaseExtensions 527.3 ns 2.47 ns 2.06 ns 0.0992 416 B

Versioning

We use SemVer for versioning. For the versions available, see the branches on this repository.

Authors

  • Szymon Hałucha - Maintainer

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.