nci/lib/utils.js

23 lines
464 B
JavaScript
Raw Normal View History

2014-12-02 21:21:07 +00:00
'use strict';
2015-05-07 19:03:57 +00:00
exports.prune = function(str, length) {
var result = '',
words = str.split(' ');
do {
result += words.shift() + ' ';
} while (words.length && result.length < length);
2015-05-20 20:20:51 +00:00
return result.replace(/ $/, words.length ? '...' : '');
2015-05-07 19:03:57 +00:00
};
2015-10-03 14:14:41 +00:00
exports.lpad = function(str, length, chr) {
chr = chr || '0';
while (str.length < length) str = chr + str;
return str;
};
exports.toNumberStr = function(number) {
return exports.lpad(String(number), 20);
};