src/index.js
function formatData(value, byteLength) {
  var output = value; // eslint-disable-line
  var outputByteLength = 0; // eslint-disable-line

  // prefix only under strict conditions, else bypass
  if (typeof value === 'string') {
    output = `0x${padToEven(stripHexPrefix(value))}`;
    outputByteLength = getBinarySize(output);
  }

  // format double padded zeros.
  if (output === '0x00') { output = '0x0'; }

  // throw if bytelength is not correct
  if (typeof byteLength === 'number' && value !== null && output !== '0x' && output !== '0x0' // support empty values
    && (!/^[0-9A-Fa-f]+$/.test(stripHexPrefix(output)) || outputByteLength !== 2 + byteLength * 2)) {
    throw new Error(`[ethjs-format] hex string '${output}' must be an alphanumeric ${2 + byteLength * 2} utf8 byte hex (chars: a-fA-F) string, is ${outputByteLength} bytes`);
  }

  return output;
}
function formatData(value, byteLength) {
  var output = value; // eslint-disable-line
  var outputByteLength = 0; // eslint-disable-line

  // prefix only under strict conditions, else bypass
  if (typeof value === 'string') {
    output = `0x${padToEven(stripHexPrefix(value))}`;
    outputByteLength = getBinarySize(output);
  }

  // format double padded zeros.
  if (output === '0x00') { output = '0x0'; }

  // throw if bytelength is not correct
  if (typeof byteLength === 'number' && value !== null && output !== '0x' && output !== '0x0' // support empty values
    && (!/^[0-9A-Fa-f]+$/.test(stripHexPrefix(output)) || outputByteLength !== 2 + byteLength * 2)) {
    throw new Error(`[ethjs-format] hex string '${output}' must be an alphanumeric ${2 + byteLength * 2} utf8 byte hex (chars: a-fA-F) string, is ${outputByteLength} bytes`);
  }

  return output;
}
FormatData under strict conditions hex prefix

@method formatData
@param {String} value the bytes data to be formatted
@param {Number} byteLength the required byte length (usually 20 or 32)
@returns {String} output output formatted data
@throws error if minimum length isnt met