Skip to content

Commit

Permalink
prune works with numbers... who cares?
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Pravosud committed Feb 27, 2012
1 parent 7df0e74 commit 58cf4d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/underscore.string.js
Expand Up @@ -325,11 +325,13 @@
* @author github.com/sergiokas
*/
prune: function(str, length, pruneStr){
var pruned, borderChar, template = (''+str).replace(/\W/g, function(ch){
str = ''+str; length = ~~length;
pruneStr = pruneStr != null ? ''+pruneStr : '...';

var pruned, borderChar, template = str.replace(/\W/g, function(ch){
return (ch.toUpperCase() != ch.toLowerCase()) ? 'A' : ' '
});

pruneStr = pruneStr || '...'; length = ~~length;

borderChar = template[length];

Expand Down
2 changes: 2 additions & 0 deletions test/strings.js
Expand Up @@ -230,6 +230,8 @@ $(document).ready(function() {
equals(_('Привет, мир').prune(8), 'Привет...');
equals(_('Привет, жестокий мир').prune(16), 'Привет, жестокий...');
equals(_('Привет, мир').prune(22), 'Привет, мир');
equals(_(123).prune(10), '123')
equals(_(123).prune(1,1), '11')
});

test('String: isBlank', function(){
Expand Down

0 comments on commit 58cf4d1

Please sign in to comment.