nci/lib/utils.js
2015-05-07 22:08:46 +03:00

13 lines
262 B
JavaScript

'use strict';
exports.prune = function(str, length) {
var result = '',
words = str.split(' ');
do {
result += words.shift() + ' ';
} while (words.length && result.length < length);
return result.replace(/ $/, result.length <= length ? '' : '...');
};