{"size": 754, "ext": "js", "max_stars_repo_path": "lib/shiftLeft.js", "max_stars_repo_name": "piu130/buffer-math", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/shiftLeft.js", "max_issues_repo_name": "piu130/buffer-math", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/shiftLeft.js", "max_forks_repo_name": "piu130/buffer-math", "max_forks_repo_forks_event_min_datetime": "2020-03-07T02:00:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-07T02:00:39.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 30.16, "max_line_length": 96, "alphanum_fraction": 0.6193633952}
const trimAfter = require('./trimAfter')

/**
 * Shift left operation.
 * @param {Buffer} buffer - Buffer.
 * @param {number} number - Bits to shift.
 * @param {Buffer} [result=Buffer.alloc(buffer.length + (number >> 3) + 1)] - Result buffer.
 * @returns {Buffer} Result.
 */
module.exports = (buffer, number, result = Buffer.alloc(buffer.length + (number >> 3) + 1)) => {
  if (number < 0) return require('./shiftRight')(buffer, -number, result)

  const bits = number & 7
  const bytes = number >> 3

  let carry = 0
  for (let i = 0, j = bytes; i < buffer.length; i++, j++) {
    const shifted = buffer[i] << bits
    result[j] = carry | shifted
    carry = (shifted & 0xFF00) >> 8
  }
  result[result.length - 1] = carry
  return trimAfter(result)
}
