lines.js 334 B

123456789101112131415
  1. 'use strict';
  2. const strip = require('./strip');
  3. /**
  4. * @param {string} msg
  5. * @param {number} perLine
  6. */
  7. module.exports = function (msg, perLine) {
  8. let lines = String(strip(msg) || '').split(/\r?\n/);
  9. if (!perLine) return lines.length;
  10. return lines.map(l => Math.ceil(l.length / perLine))
  11. .reduce((a, b) => a + b);
  12. };