Skip to content

Repository files navigation

ktsu.CaseConverter

A library with extension methods to convert strings between common casings used in code.

LicenseNuGet VersionNuGet VersionNuGet DownloadsGitHub commit activityGitHub contributorsGitHub Actions Workflow Status

Introduction

CaseConverter is a lightweight .NET library that provides a set of extension methods for converting strings between various case styles commonly used in programming. Whether you need to transform identifiers between different naming conventions or format text for display, CaseConverter makes these operations simple and efficient.

Features

  • ToTitleCase: Converts text to Title Case (Each Word Capitalized)
  • ToPascalCase: Converts text to PascalCase (CapitalizedWords)
  • ToCamelCase: Converts text to camelCase (firstWordLowerCaseRestCapitalized)
  • ToSnakeCase: Converts text to snake_case (lowercase_with_underscores)
  • ToKebabCase: Converts text to kebab-case (lowercase-with-hyphens)
  • ToMacroCase: Converts text to MACRO_CASE (UPPERCASE_WITH_UNDERSCORES)
  • ToUppercaseFirstChar: Converts only the first character to uppercase (Uppercasefirstchar)
  • ToLowercaseFirstChar: Converts only the first character to lowercase (lowercaseFirstChar)

Installation

Package Manager Console

Install-Package ktsu.CaseConverter

.NET CLI

dotnet add package ktsu.CaseConverter

Package Reference

<PackageReferenceInclude="ktsu.CaseConverter"Version="x.y.z" />

Usage Examples

Basic Example

usingktsu.CaseConverter;stringoriginal="This is a test string";// Convert to different casesstringpascalCase=original.ToPascalCase();// "ThisIsATestString"stringcamelCase=original.ToCamelCase();// "thisIsATestString"stringsnakeCase=original.ToSnakeCase();// "this_is_a_test_string"stringkebabCase=original.ToKebabCase();// "this-is-a-test-string"stringmacroCase=original.ToMacroCase();// "THIS_IS_A_TEST_STRING"Console.WriteLine(pascalCase);Console.WriteLine(camelCase);Console.WriteLine(snakeCase);Console.WriteLine(kebabCase);Console.WriteLine(macroCase);

Advanced Usage

// Working with code identifiersstringvariableName="customer_order_details";stringclassName=variableName.ToPascalCase();// "CustomerOrderDetails"stringpropertyName=variableName.ToCamelCase();// "customerOrderDetails"stringconstantName=variableName.ToMacroCase();// "CUSTOMER_ORDER_DETAILS"// Handling acronyms and special casesstringwithAcronym="API_response_URL";stringpascalWithAcronym=withAcronym.ToPascalCase();// "ApiResponseUrl"// First character transformationsstringsentence="lorem ipsum dolor sit amet";stringcapitalized=sentence.ToUppercaseFirstChar();// "Lorem ipsum dolor sit amet"

API Reference

Extension Methods

MethodParametersReturn TypeDescription
ToTitleCase()NonestringConverts string to Title Case
ToPascalCase()NonestringConverts string to PascalCase
ToCamelCase()NonestringConverts string to camelCase
ToSnakeCase()NonestringConverts string to snake_case
ToKebabCase()NonestringConverts string to kebab-case
ToMacroCase()NonestringConverts string to MACRO_CASE
ToUppercaseFirstChar()NonestringCapitalizes only the first character
ToLowercaseFirstChar()NonestringMakes only the first character lowercase

Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

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

Releases

Packages

Used by

Contributors

Languages