src/index.js
function formatQuantity(value, encode, pad) {
  if (['string', 'number', 'object'].indexOf(typeof value) === -1 || value === null) {
    return value;
  }

  const numberValue = numberToBN(value);
  const numPadding = numberValue.lt(ten) && pad === true && !numberValue.isZero() ? '0' : '';

  if (numberToBN(value).isNeg()) { throw new Error(`[ethjs-format] while formatting quantity '${numberValue.toString(10)}', invalid negative number. Number must be positive or zero.`); }

  return encode ? `0x${numPadding}${numberValue.toString(16)}` : numberValue;
}
function formatQuantity(value, encode, pad) {
  if (['string', 'number', 'object'].indexOf(typeof value) === -1 || value === null) {
    return value;
  }

  const numberValue = numberToBN(value);
  const numPadding = numberValue.lt(ten) && pad === true && !numberValue.isZero() ? '0' : '';

  if (numberToBN(value).isNeg()) { throw new Error(`[ethjs-format] while formatting quantity '${numberValue.toString(10)}', invalid negative number. Number must be positive or zero.`); }

  return encode ? `0x${numPadding}${numberValue.toString(16)}` : numberValue;
}
Format quantity values, either encode to hex or decode to BigNumber
should intake null, stringNumber, number, BN

@method formatQuantity
@param {String|BigNumber|Number} value quantity or tag to convert
@param {Boolean} encode to hex or decode to BigNumber
@returns {Optional} output to BigNumber or string
@throws error if value is a float