utils.js 454 B

123456789101112131415161718192021222324
  1. // Wrap lines after 79 chars
  2. exports.wrap = function wrap(str) {
  3. var out = [];
  4. var pad = ' ';
  5. var line = pad;
  6. var chunks = str.split(/,/g);
  7. chunks.forEach(function(chunk, i) {
  8. var append = chunk;
  9. if (i !== chunks.length - 1)
  10. append += ',';
  11. if (line.length + append.length > 79) {
  12. out.push(line);
  13. line = pad;
  14. }
  15. line += append;
  16. });
  17. if (line !== pad)
  18. out.push(line);
  19. return out.join('\n');
  20. };