Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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();
};