Skip to content

Commit c228b6b

Browse files
committed
fix underscore method for single letter words
1 parent af0ace6 commit c228b6b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ string.js - Copyright (C) 2012-2014, JP Richardson <[email protected]>
558558

559559
//#modified from https://github.com/epeli/underscore.string
560560
underscore: function() {
561-
var s = this.trim().s.replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
561+
var s = this.trim().s.replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/([A-Z\d]+)([A-Z][a-z])/,'$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
562562
return new this.constructor(s);
563563
},
564564

test/string.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@
680680
F (S('CarSpeed').underscore().s === '_car_speed');
681681
T (S('_CarSpeed').underscore().s === '_car_speed');
682682
T (S('yesWeCan').underscore().s === 'yes_we_can');
683+
T (S('oneAtATime').underscore().s === 'one_at_a_time');
683684
})
684685
})
685686

0 commit comments

Comments
 (0)