Giter Site home page Giter Site logo

Comments (7)

stephenh avatar stephenh commented on July 4, 2024 1

I believe #1052 is a good approach, and at least fixes all current test cases 😅 , I went ahead and merged the fix, let us know if there are other exceptions. 🤞

from ts-proto.

daeteck avatar daeteck commented on July 4, 2024

Same problema here. This is a breaking change that is given us a lot of problems.

from ts-proto.

stephenh avatar stephenh commented on July 4, 2024

Hey guys, thanks for the report! Hopefully it won't be too bad to craft a regex that achieves both goals--I'll take a look at this in a few days/next weekend, unless @BrandonArmand you can take a look/beat me to it. Thanks!

from ts-proto.

BrandonArmand avatar BrandonArmand commented on July 4, 2024

Hey yeah i actually noticed this today as well. I will be happy to whip up some regex.

from ts-proto.

mishio-n avatar mishio-n commented on July 4, 2024

Thanks.

I think, the original cause was two-fold:

  1. the consecutive capital letters were not being treated as independent words.
  2. metacharacter \w contains capital letters.

For 1.
Consider a series of uppercase letters as a word, and consider that they can be separated by one before they change to lowercase letters.

For 2.
Use [a-z0-9] insted of \w.

So, I came up with the following regular expression.

export function camelToSnake(s: string): string {
  return s.replace(/(?<!^)([a-z0-9][A-Z]|([A-Z][A-Z])[a-z0-9])/g, (m) => m.length === 2 ? m[0] + "_" + m[1] :  m[0] + "_" + m[1] + m[2]).toUpperCase();
}

// getAPIValueV1Beta1 => GET_API_VALUE_V1_BETA1

I have passed the test case, but I feel it is not very elegant.

If you have any good ideas, please let me know.

from ts-proto.

stephenh avatar stephenh commented on July 4, 2024

🎉 This issue has been resolved in version 1.176.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

from ts-proto.

mishio-n avatar mishio-n commented on July 4, 2024

@stephenh Thank you so much for the fix !

from ts-proto.

Related Issues (20)

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.