Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snake_case to camelCase fails to match _[number] #1856

Closed
horacimacias opened this issue Jan 30, 2023 · 2 comments
Closed

snake_case to camelCase fails to match _[number] #1856

horacimacias opened this issue Jan 30, 2023 · 2 comments

Comments

@horacimacias
Copy link

protobuf.js version: 7.2.0

A similar issue was raised #714 but the difference here is having just a number after the underscore.

camelCase('testing_1') -> 'testing1' (expected)
camelCase('testing_1') -> 'testing_1' (actual)

copy this snippet into Chrome dev tools:

var camelCaseRe = /_([a-z])/g;

function camelCase(str) {
    return str.substring(0,1)
         + str.substring(1)
               .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
}

Then evaluate:

camelCase('testing_1')

I believe the regular expression should be instead:

var camelCaseRe = /_([a-z0-9])/g;
@jcready
Copy link

jcready commented Feb 2, 2023

@horacimacias
Copy link
Author

thanks, I wasn't aware of this.
So far every page I check for "convert to camelCase" is not behaving like that.
But you're absolutely right; searching a bit more (sorry I should have seen this earlier) I see this:

https://developers.google.com/protocol-buffers/docs/style#message_and_field_names

If your field name contains a number, the number should appear after the letter instead of after the underscore. For example, use song_name1 instead of song_name_1

alright, thanks again. nothing to fix here. sorry for the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants