You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
454 B

4 years ago
  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. };