Git Product home page Git Product logo

pearxteam / kasechange Goto Github PK

View Code? Open in Web Editor NEW
88.0 3.0 6.0 850 KB

๐Ÿซ๐Ÿ๐Ÿข๐Ÿ…ฟ Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case

License: Mozilla Public License 2.0

Kotlin 100.00%
kotlin kotlin-multiplatform gradle-kotlin-dsl camelcase-to-snakecase snakecase-to-camelcase case-converter camelcase snakecase pascal-case snake-case

kasechange's People

Contributors

asos-savvasdalkitsis avatar devkanro avatar greghib avatar mrapplexz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kasechange's Issues

Add support for detecting case

Thanks for this library, works really well.

It would be cool if it could be used to return the casing of a string also.

"my_string".detectCase() // snake_case

Custom case formatter and preserving char casing

I have a use case where I want to format a string away from camel_case etc. but not remove the casing of each word.

E.g. If someone wrote this_is_Kotlin, I can change it to this is Kotlin.

Current solution is "this_is_Kotlin".splitToWords().joinToString(" "), however not able to do it with the custom case formatter, or at least haven't figured out how.

Make config in CaseFormat publicly accessible

This is related to the earlier enhancement I raised #3

In CaseFormat, I had intentionally made the config value publicly accessible but didn't explain my reasoning behind it (my apologies):

enum class CaseFormat(config: CaseFormatterConfig) : CaseFormatter by CaseFormatterConfigurable(config) {

Since the API is now extensible, clients might want to mix and match predefined formats with their own and the only way to do it in a concise manner would be something like this:

val formats = mapOf(
    "SCREAMING_SNAKE_CASE" to CaseFormat.UPPER_UNDERSCORE.config,
    "snake_case" to CaseFormat.LOWER_UNDERSCORE.config,
    "Pascal.Dot.Case" to CaseFormatterConfig(false, ".", wordCapitalize = true, firstWordCapitalize = true)
)

which can then be used like so:

val format : String = parseFormatFromConfigurationFile()
"Some words".toCase(formats["format"] ?: throw IllegalArgumentException("Unrecognised format"))

If the config is not exposed, the only way is to keep two constructs and depending on the value you might want to use, know which construct to pull the formatter from.

Any thoughts on this?

Treat digits as a continuous word

If [WordSplitterConfig.handleCase] is set to true: if a lowercase character is followed by an uppercase character, a word boundary is considered to be prior to the uppercase character.
If [WordSplitterConfig.handleCase] is set to true: if multiple uppercase characters are followed by a lowercase character, a word boundary is considered to be prior to the last uppercase character.

Prior to the last digit is an odd place to be considered a boundary. As such any digits which are followed by letters get chopped up.

Input Expected Actual
option14b option 14 b option 1 4b
123abc 123 abc 12 3abc

Numbers should be considered continuous

Adding option to not treat digits as word boundaries

The latest version of the library changed the behaviour when it comes to how digits are treated (commit e8e3222).

It used to be that something like "a_word1_with_number" == "a_word1_with_number".toSnakeCase() but it no longer holds true.

To allow clients to maintain that behaviour if they need to so that they can still update to later versions of the library (my project is one that needs this behaviour for various reasons but I also would like to use the latest version), I raised #5

This PR maintains API compatibility as it introduces one parameter to the public API that has a default value so existing code should not be affected

Allow clients to extend the library without needing to wait for an update

Hello,

I really like the library, found a good use for it recently on one of my projects.

I realised that I had need for what I'd call Pascal.Dot.Case though and realised the library was not extensible since it relies on the enums themselves performing the formatting.

I decided to raise a PR that, in my view, fixes the problem while maintaining API compatibility: #2

Please have a look and tell me if you think it's worth merging or, if not, any changes you'd propose if you think it's worth creating an extensible API for the library.

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.