-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add optional argument for toDash and camelCase #214
base: master
Are you sure you want to change the base?
Conversation
If specified, it's used instead of dash. Does not break BC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this restriction as artificial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this restriction as artificial.
@@ -105,15 +105,21 @@ | |||
}, | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.