CaseON 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global CaseON --version 1.0.0                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local CaseON --version 1.0.0                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CaseON&version=1.0.0                
nuke :add-package CaseON --version 1.0.0                

CaseON: A C# String Casing Library

CaseON is a lightweight C# library providing a simple and efficient way to convert strings to various casing styles. It handles different separators and offers robust error handling.

Features

  • Multiple Casing Styles: Supports conversion to:
    • snake_case
    • kebab-case
    • PascalCase
    • camelCase
    • Sentence case
    • Title Case
  • Robust Input Handling: Throws informative ArgumentExceptions for null or empty/whitespace input strings. Handles strings containing spaces, underscores, and hyphens.
  • Easy to Use: Simple static methods provide a clean and intuitive API.
  • Lightweight: Minimal dependencies, easy to integrate into existing projects.

Usage

  1. Installation: You can easily add CaseON to your project via NuGet. Alternatively, you can directly include the source code in your project.

  2. Basic Example:

using CaseON;

string myString = "This Is A Test String";

string snakeCase = StringFormatter.ToSnakeCase(myString);      // Output: this_is_a_test_string
string kebabCase = StringFormatter.ToKebabCase(myString);     // Output: this-is-a-test-string
string pascalCase = StringFormatter.ToPascalCase(myString);    // Output: ThisIsATestString
string camelCase = StringFormatter.ToCamelCase(myString);     // Output: thisIsATestString
string sentenceCase = StringFormatter.ToSentenceCase(myString); // Output: This is a test string
string titleCase = StringFormatter.ToTitleCase(myString);     // Output: This Is A Test String

Console.WriteLine($"Snake Case: {snakeCase}");
Console.WriteLine($"Kebab Case: {kebabCase}");
Console.WriteLine($"Pascal Case: {pascalCase}");
Console.WriteLine($"Camel Case: {camelCase}");
Console.WriteLine($"Sentence Case: {sentenceCase}");
Console.WriteLine($"Title Case: {titleCase}");
  1. Error Handling:

CaseON throws an ArgumentException if you pass a null or empty/whitespace string to any of its methods. Make sure to handle this exception appropriately in your code:

try
{
    string result = StringFormatter.ToSnakeCase(null);
}
catch (ArgumentException ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}

API Reference

The StringFormatter class contains the following static methods:

  • ToSnakeCase(string input): Converts a string to snake_case.
  • ToKebabCase(string input): Converts a string to kebab-case.
  • ToPascalCase(string input): Converts a string to PascalCase.
  • ToCamelCase(string input): Converts a string to camelCase.
  • ToSentenceCase(string input): Converts a string to Sentence case.
  • ToTitleCase(string input): Converts a string to Title Case.
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.

This package has no dependencies.

Version Downloads Last updated
1.1.0 39 11/21/2024
1.0.0 53 11/21/2024 1.0.0 is deprecated because it has critical bugs.

This release introduces CaseON version 1.0.0, a lightweight and efficient C# library for simplifying string casing conversions. It offers a straightforward API to convert strings to various common casing formats, including snake_case, kebab-case, PascalCase, camelCase, Sentence case, and Title Case. The library includes comprehensive error handling for null, empty, and whitespace-only inputs, throwing informative ArgumentExceptions for ease of debugging. Its simple static methods allow for seamless integration into existing projects, and its minimal dependencies ensure optimized performance. This is the initial release, implementing all core casing conversion functionalities. Future plans include potential support for additional casing styles based on user feedback and ongoing performance optimizations. We encourage users to try CaseON and provide feedback to help improve the library.