Permalink
Browse files

#89 - Dasherize - last regular expression now replaces multiple dashe…

…s globally instead of just the first instance. Added test case coverage for this. Also added a couple other test cases.
  • Loading branch information...
1 parent f0b895c commit 31d507aefbd2263069c5552220d53d712d856652 @rallison rallison committed Feb 29, 2012
Showing with 4 additions and 1 deletion.
  1. +1 −1 lib/underscore.string.js
  2. +3 −0 test/strings.js
View
@@ -287,7 +287,7 @@
},
dasherize: function(str){
- return _s.trim(str).replace(/[\W_]+/g, '-').replace(/([A-Z])/g, '-$1').replace(/-+/, '-').toLowerCase();
+ return _s.trim(str).replace(/[\W_]+/g, '-').replace(/([A-Z])/g, '-$1').replace(/-+/g, '-').toLowerCase();
},
humanize: function(str){
View
@@ -196,6 +196,9 @@ $(document).ready(function() {
equals(_('the_dasherize_string_method').dasherize(), 'the-dasherize-string-method');
equals(_('TheDasherizeStringMethod').dasherize(), '-the-dasherize-string-method');
equals(_('thisIsATest').dasherize(), 'this-is-a-test');
+ equals(_('this Is A Test').dasherize(), 'this-is-a-test');
+ equals(_('thisIsATest123').dasherize(), 'this-is-a-test123');
+ equals(_('123thisIsATest').dasherize(), '123this-is-a-test');
equals(_('the dasherize string method').dasherize(), 'the-dasherize-string-method');
equals(_('the dasherize string method ').dasherize(), 'the-dasherize-string-method');
equals(_(123).dasherize(), '123');

0 comments on commit 31d507a

Please sign in to comment.