mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 07:45:09 +00:00
23 lines
464 B
JavaScript
23 lines
464 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(/ $/, words.length ? '...' : '');
|
|
};
|
|
|
|
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);
|
|
};
|