Skip to content

Commit 996afda

Browse files
committed
fix underscored method for single letter words
1 parent e622437 commit 996afda

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

test/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ $(document).ready(function() {
436436

437437
test('String: underscored', function(){
438438
equal(_('oneAtATime').underscored(), 'one_at_a_time');
439+
equal(_('oneAtATime AnotherWordAtATime').underscored(), 'one_at_a_time_another_word_at_a_time');
439440
equal(_('the-underscored-string-method').underscored(), 'the_underscored_string_method');
440441
equal(_('theUnderscoredStringMethod').underscored(), 'the_underscored_string_method');
441442
equal(_('TheUnderscoredStringMethod').underscored(), 'the_underscored_string_method');

underscored.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var trim = require('./trim');
22

33
module.exports = function underscored(str) {
4-
return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
4+
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();
55
};

0 commit comments

Comments
 (0)