jishi / node-sonos-discovery

Simplified framework for Sonos built on node.js
MIT License
146 stars 75 forks source link

string compare better with uppercase #65

Closed ColdFireIce closed 8 years ago

ColdFireIce commented 8 years ago

Hi,

while scanning over the code I noticed something I read about recently. Its better to use "toUpperCase()" than "toLowerCase()": https://msdn.microsoft.com/en-us/library/bb386042.aspx http://stackoverflow.com/questions/234591/upper-vs-lower-case

It might even be better to use "toLocaleUpperCase()".

Its just a proposition. I didn't check every file for a similar comparison. I like your code. Its clean and easy to read :)

Greetings

jishi commented 8 years ago

I think in this case it doesn't really matter. I choose lower case since most of the string would consist of lower case, and the entered value (from user or api) would probably be lower case.

toLocaleXXXX is a good point, however, node.js doesn't seem to include localization data for Linux distribution, so the effect of it might be moot there. Either way, I only use this "hack" for matching user input with correlated values of favorites and players etc. If one enters the exact same content (casing wise) it would still match even if locale isn't applied correctly. In a few rare edge cases, it might match the incorrect entry, but I think we can disregard that.

Thanks for the pointer though, it's always good to contemplate about things like this.