GithubHelp home page GithubHelp logo

stakx / camelcaser Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 17 KB

A .NET micro-library for converting "PascalCase" names to "camelCase".

License: MIT License

C# 100.00%
dotnet dotnet-standard formatter strings camelcase camel-case pascalcase pascal-case string-transformations

camelcaser's Introduction

CamelCaser

A small .NET library for converting identifiers to "camelCase".

AppVeyor AppVeyor tests

partial interface ICamelCaser { }

nameof(ICamelCaser).ToLowerCamelCase();
// => "camelCaser"

What could this be useful for?

The main purpose behind this library is to be able to automatically derive suitable variable names from type names e.g. in Reflection-based tools. The usual .NET conventions state that variable names should be in "camelCase", while type names should be in "PascalCase".

While this conversion is a no-brainer for humans, it's actually made more complicated than one might realise at first by several .NET naming conventions:

  • For interface types whose name starts with an I, that I should be dropped: IFruitPickerfruitPicker (not iFruitPicker!)

  • When there are several initial upper-case characters, all but the last of them should be lower-cased: IDESettingsideSettings (not idesettings, nor idesEttings!)

  • … but not if all characters are in upper-case: IDEide (not idE!)

This library takes care of that transformation, so that you don't have to.

How do I use it?

By importing the CamelCaser namespace, the following extension method becomes available:

  • string.ToLowerCamelCase():
    Converts the original string to "camelCase" according to the rules shown above.

But it doesn't lower-case <some string> correctly!

If you think you've found a bug, please raise an issue so it can be looked into. (Make sure to mention the string that doesn't get formatted as expected, along with your expectation of how it should have been formatted.)

camelcaser's People

Contributors

stakx avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

camelcaser's Issues

Transform for interface names not implemented yet

Since the library has no way of knowing whether a type name belongs to an interface or not, it's likely that the string.ToLowerCamelCase() method will have to be augmented with an options parameter.

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.