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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ $(document).ready(function() {
});

test('String: underscored', function(){
equal(_('oneAtATime').underscored(), 'one_at_a_time');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test case for IAmA TWAT TryingATrick or something :D

equal(_('oneAtATime AnotherWordAtATime').underscored(), 'one_at_a_time_another_word_at_a_time');
equal(_('the-underscored-string-method').underscored(), 'the_underscored_string_method');
equal(_('theUnderscoredStringMethod').underscored(), 'the_underscored_string_method');
equal(_('TheUnderscoredStringMethod').underscored(), 'the_underscored_string_method');
Expand Down
2 changes: 1 addition & 1 deletion underscored.js
Original file line number Diff line number Diff line change
@@ -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])/g,'$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
};