Skip to content
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

Fix underscore for single word #412

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

az7arul
Copy link
Contributor

@az7arul az7arul commented Mar 16, 2015

No description provided.

@az7arul
Copy link
Contributor Author

az7arul commented Mar 16, 2015

@az7arul
Copy link
Contributor Author

az7arul commented May 30, 2015

any feedback on this ?

@stoeffel
Copy link
Collaborator

I will check it tomorrow

@stoeffel
Copy link
Collaborator

I think if we change the behaviour of underscored we should change dasherize too.
WIth your change they would behave differently.
i.e.

dasherize('oneAtATime'); // => 'one-at-a-time'
dasherize('ATime'); // => '-a-time'
dasherize('ONETime'); // => '-o-n-e-time'

underscored('oneAtATime'); // => 'one_at_a_time'
underscored('ATime'); // => 'a_time'
underscored('ONETime'); // => 'one_time'

The only different should be that dasherize prefixes the sting with a dash if it starts with an uppercase.

@epeli do you agree that we should change both functions to the behaviour proposed by @az7arul ?

btw. related #89 #156

@@ -1,5 +1,5 @@
var trim = require('./trim');

module.exports = function underscored(str) {
return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/([A-Z\d]+)([A-Z][a-z])/,'$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not have to be global (test case please)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup it needs to be global

@az7arul az7arul force-pushed the fix-underscore-for-single-word branch from 63450a0 to 996afda Compare June 2, 2015 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants