sindresorhus / camelcase

Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar
MIT License
682 stars 95 forks source link

Case conversion with specific locale #72

Closed rasgele closed 4 years ago

rasgele commented 4 years ago

Case conversion are done with String.prototype.toLocaleLowerCase() and String.prototype.toLocaleUpperCase() without explicit locale parameter and this causes host dependent output. Example:

camelCase('lorem-ipsum')
//=> 'loremIpsum' if host locale is en-US
//=> 'loremİpsum' if host locale is tr-TR

This causes unexpected results int hosts with non en-US environment.

I'd suggest to extend options parameter to have a locale property to be passed to aforementioned methods.

camelCase('lorem-ipsum', {locale: 'en-US'});
//=> 'loremIpsum' if host locale is en-US
//=> 'loremIpsum' if host locale is tr-TR
selimrecep commented 4 years ago

I am experiencing same issue too. Just because of this error, I couldn't get Jest work without workarounds.

i => İ
ı => I
(Lower => Upper s in Turkish)
selimrecep commented 4 years ago

I have created PR. I think that will fix it.

rasgele commented 4 years ago

@selimrecep Sorry, in parallel I've also submitted a PR. Any of them is fine :)