Coder Social home page Coder Social logo

szymonhalucha / minerals.stringcases Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 35 KB

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

License: MIT License

C# 100.00%
camelcase caseconverter csharp dotnet kebabcase netstandard20 pascalcase snakecase string-formatter string-manipulation

minerals.stringcases's Introduction

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.

minerals.stringcases's People

Contributors

szymonhalucha avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

minerals.stringcases's Issues

Snake Case Bug 🐛 : Run-time exception (line x): Index was outside the bounds of the array.

How to reproduce it:

In the following example, everything works as expected:

var str = "TestAbc";
Console.WriteLine(str.ToSnakeCase());

// Output: test_abc

But if you try with "TestA", "TestAb" or "TestABCDE" you get an exception:

var str = "TestAb";
Console.WriteLine(str.ToSnakeCase());

// Output: Run-time exception (line X): Index was outside the bounds of the array.

Run-time exception (line X): Index was outside the bounds of the array.

Stack Trace:
[System.IndexOutOfRangeException: Index was outside the bounds of the array.]
at Minerals.StringCases.StringExtensions.ToSnakeCase(String value)
at Program.Main() :line X

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.