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

Keys ending with numbers fail to snake_case #119

Open
andymerskin opened this issue Aug 10, 2023 · 4 comments
Open

Keys ending with numbers fail to snake_case #119

andymerskin opened this issue Aug 10, 2023 · 4 comments

Comments

@andymerskin
Copy link

Due to the way the snake-case package handles numbers, keys ending with numbers aren't being properly snake_cased.

Example keys:

fooBar01 -> foo_bar01
foo01 -> foo01
fooBar1 -> foo_bar1
foo1 -> foo1

Whereas lodash's snakeCase utility does properly separate numbers from alphabetical characters:

fooBar01 -> foo_bar_01
foo01 -> foo_01
fooBar1 -> foo_bar_1
foo1 -> foo_1

This may mean this library's underlying case conversion library would need to be swapped, or updated, but unfortunately it hasn't been maintained in several years.

@bendrucker
Copy link
Owner

This seems like an opinion rather than a correctness issue:

https://stackoverflow.com/questions/58009622/whats-the-correct-way-to-treat-numbers-in-snake-case

In which case I'm not especially inclined to pursue a breaking change.

@andymerskin
Copy link
Author

andymerskin commented Aug 10, 2023

Could this offered as a configurable option, especially since the consensus in that opinion favors what I'm suggesting here? It would also be beneficial for this library to at least offer comparable functionality to popular libraries like lodash, etc. so that case conversion can remain consistent and predictable.

Example with option:

const object = {
  foo01: "value",
};

snakecaseKeys(object, { separateNumbers: true });
// { foo_01: "value" }

@bendrucker
Copy link
Owner

Probably not, as maintaining variations on what snake case means becomes very complex. And bringing in multiple libraries to handle those is both complex and bloats the package.

I'll certainly accept a PR that makes the snake case function an option so you can pass your own.

@andymerskin
Copy link
Author

andymerskin commented Aug 10, 2023

Fair points — I love that idea better!

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