-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BUGFIX] Namespaced strings conversions #10980
Conversation
It's not immediately obvious when I read the code what |
Thank you, @fivetanley. I will clean up code, but I'd like to understand you correctly. There were at least 3 options of coding in that file before this PR: var STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g);
var STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g);
var UNDERSCORE_CACHE = new Cache(1000, function(str) {
return str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').
replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase();
}); Option 2 (1 regexp var, 1 inline regexp): var CAMELIZE_CACHE = new Cache(1000, function(key) {
return key.replace(STRING_CAMELIZE_REGEXP, function(match, separator, chr) {
return chr ? chr.toUpperCase() : '';
}).replace(/^([A-Z])/, function(match, separator, chr) {
return match.toLowerCase();
});
}); Option 3 (without regexp): var CLASSIFY_CACHE = new Cache(1000, function(str) {
var parts = str.split(".");
var out = [];
for (var i=0, l=parts.length; i<l; i++) {
var camelized = camelize(parts[i]);
out.push(camelized.charAt(0).toUpperCase() + camelized.substr(1));
}
return out.join(".");
}); Quite a diverse mix, isn't it? Which option do you suggest me to follow to make this PR code immediately obvious? |
Since no response, I've clean the code in favor of option 1, moved regexp vars just before function they used in, added comments. IMHO it looks better now. |
LGTM. Can you amend the commit message to be |
Now Camelize, capitalize, classify consider "/". For example, 'private-docs/owner-invoice'.classify(); // 'PrivateDocs/OwnerInvoice'
@fivetanley |
Looks like forgotten during major changes? |
Yeah, sorry about that. |
[BUGFIX] Namespaced strings conversions
Fixes #11000