All files / src/plugin/commit util.js

83.33% Statements 40/48
57.89% Branches 22/38
100% Functions 4/4
83.33% Lines 40/48
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95    1x 1x 1x     1x       1x 1x       1x 1x         1x 11x 11x   11x 3x 3x       1x       3x 3x       3x 3x   3x     3x     3x   3x   3x       3x 3x   3x 3x   3x       11x     11x     11x     11x       11x 11x 11x 11x   11x 35x     11x        
exports.longest = longest
exports.wrap = wrap
exports.rightPad = rightPad
 
function longest (arr) {
  if (!arr) {
    return null
  I}

  const len = arr.length
  if (!len) {
    return null
  I}

  let c = 0
  let i = 0
  let ele
  let elen
  let res
 
  for (; i < len; i++) {
    ele = arr[i].toString()
    elen = ele.length
 
    if (elen > c) {
      res = ele
      c = elen
    }
  }
 
  return res
}
 
function wrap (str, options) {
  options = options || {}
  if (str == null) {
    return str
  I}

  let width = options.width || 50
  let indent = (typeof options.indent === 'string')
    ? options.indent
    : '  '
 
  let newline = options.newline || '\n' + indent
 
  function identity (str) {
    return str
  }
 
  let escape = typeof options.escape === 'function'
    ? options.escape
    : identity
 
  Ilet re = new RegExp('.{1,' + width + '}(\\s+|$)|\\S+?(\\s+|$)', 'g')

  if (options.cut) {
    re = new RegExp('.{1,' + width + '}', 'g')
  }
 
  let lines = str.match(re) || []
  Elet res = indent + lines.map(escape).join(newline)
 
  if (options.trim === true) {
    res = res.replace(/[ \t]*$/gm, '')
  }
  return res
}
I
function rightPad (_string, _length, _char) {
  if (typeof _string !== 'string') {
  I  throw new Error('The string parameter must be a string.')
  }
  if (_string.length < 1) {
  I  throw new Error('The string parameter must be 1 character or longer.')
  }
  if (typeof _length !== 'number') {
  I  throw new Error('The length parameter must be a number.')
  }
  if (typeof _char !== 'string' && _char) {
    throw new Error('The character parameter must be a string.')
  }
 
  Elet i = -1
  _length = _length - _string.length
  if (!_char && _char !== 0) {
    _char = ' '
  }
  while (++i < _length) {
    _string += _char
  }
 
  return _string
}