Skip to content

Commit

Permalink
fix underscored method for single letter words
Browse files Browse the repository at this point in the history
  • Loading branch information
az7arul committed Jun 2, 2015
1 parent e622437 commit 996afda
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ $(document).ready(function() {

test('String: underscored', function(){
equal(_('oneAtATime').underscored(), 'one_at_a_time');
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();
};

0 comments on commit 996afda

Please sign in to comment.