Add optional argument for toDash and camelCase#214
Add optional argument for toDash and camelCase#214dpolac wants to merge 1 commit intodocumentcloud:masterfrom
Conversation
If specified, it's used instead of dash. Does not break BC.
mafiosso
left a comment
There was a problem hiding this comment.
Dist files and docs should be generated from scratch. I mean it should not be part of this commit as well as package.json diff. Currently I am not sure about planned functionality - see comments below. I tested this PR, tests are OK. I vote to merge this but I recommend to consider the notes below.
| toDash : function( string, separator ){ | ||
| separator = separator || '-'; | ||
| if (typeof separator != 'string') throw new TypeError('Separator must be a string.'); | ||
| if (separator.length != 1) throw new Error('Separator must be one character.'); |
There was a problem hiding this comment.
I find this restriction as artificial.
There was a problem hiding this comment.
I agree. I only had a quick glance over the code, but this stood out to me, too.
| camelCase : function( string, separator ){ | ||
| separator = separator || '-'; | ||
| if (typeof separator != 'string') throw new TypeError('Separator must be a string.'); | ||
| if (separator.length != 1) throw new Error('Separator must be one character.'); |
There was a problem hiding this comment.
I find this restriction as artificial.
| // Converts a string to camel case | ||
| camelCase : function( string ){ | ||
| return string.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); | ||
| camelCase : function( string, separator ){ |
There was a problem hiding this comment.
What do we expect for inputs like "some----func" as result? Is it really some---Func, maybe input check for string would be fine. I suppose idempotence would be a good property here meaning that _.camelCase(_.camelCase(...(_.camelCase(x))...)) === _.camelCase(x) the same property should apply to the toDash function.
|
@dpolac Would you like to dust off your PR and revise as indicated in the comments above? Otherwise, we can also do it for you. In either case, you'll get the credits for the commits you already made. |
If specified, it's used instead of dash. Does not break BC.