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

Pitfall using Turkish locale #81

Closed
jhnns opened this issue Dec 10, 2021 · 1 comment · Fixed by #84
Closed

Pitfall using Turkish locale #81

jhnns opened this issue Dec 10, 2021 · 1 comment · Fixed by #84

Comments

@jhnns
Copy link
Contributor

jhnns commented Dec 10, 2021

Hi 👋

thanks for this module – and all the other modules 🙏

I recently ran into a problem where my JSON objects were transformed into this:

            "customersİd": 619336, // <-- notice the different capital i character
            "projectsİd": 631365,
            "usersİd": 62488,

Unfortunately, this didn't happen locally and during testing, it only happened in production in case the user was using the Turkish locale. There's already an issue in the camelcase repo describing the problem.

I kind of understand that toLocaleUpperCase() is the default for the camelcase package since the context of the "to camelcase" transformation is not clear.

However, I think that camelcase-keys should use the locale-independent toUpperCase(). This is because I'm assuming that most people are using this module in a context where they want to transform API responses to camelCase in a predictable way. Using toLocaleUpperCase() poses the risk that API responses are transformed into a different shape on runtime. Also toLocaleUpperCase("en") doesn't really help since the locale might be unavailable and the host might fall back to the default locale.

I think this issue could be solved like this:

  • Add an option to camelcase to use the locale-independent toUpperCase()
  • Use that option as default in camelcase-keys

What do you think? 😀 I'd be willing to help out if that's ok.

@sindresorhus
Copy link
Owner

I agree your proposed solution. PR welcome.

Could possibly just make the locale option in camelcase support false.

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

Successfully merging a pull request may close this issue.

2 participants