lib/index.js
function parseType (type) {
  var size
  var ret
  if (isArray(type)) {
    size = parseTypeArray(type)
    var subArray = type.slice(0, type.lastIndexOf('['))
    subArray = parseType(subArray)
    ret = {
      isArray: true,
      name: type,
      size: size,
      memoryUsage: size === 'dynamic' ? 32 : subArray.memoryUsage * size,
      subArray: subArray
    }
    return ret
  } else {
    var rawType
    switch (type) {
      case 'address':
        rawType = 'uint160'
        break
      case 'bool':
        rawType = 'uint8'
        break
      case 'string':
        rawType = 'bytes'
        break
    }
    ret = {
      rawType: rawType,
      name: type,
      memoryUsage: 32
    }

    if ((type.startsWith('bytes') && type !== 'bytes') || type.startsWith('uint') || type.startsWith('int')) {
      ret.size = parseTypeN(type)
    } else if (type.startsWith('ufixed') || type.startsWith('fixed')) {
      ret.size = parseTypeNxM(type)
    }

    if (type.startsWith('bytes') && type !== 'bytes' && (ret.size < 1 || ret.size > 32)) {
      throw new Error('Invalid bytes<N> width: ' + ret.size)
    }
    if ((type.startsWith('uint') || type.startsWith('int')) && (ret.size % 8 || ret.size < 8 || ret.size > 256)) {
      throw new Error('Invalid int/uint<N> width: ' + ret.size)
    }
    return ret
  }
}
function parseType (type) {
  var size
  var ret
  if (isArray(type)) {
    size = parseTypeArray(type)
    var subArray = type.slice(0, type.lastIndexOf('['))
    subArray = parseType(subArray)
    ret = {
      isArray: true,
      name: type,
      size: size,
      memoryUsage: size === 'dynamic' ? 32 : subArray.memoryUsage * size,
      subArray: subArray
    }
    return ret
  } else {
    var rawType
    switch (type) {
      case 'address':
        rawType = 'uint160'
        break
      case 'bool':
        rawType = 'uint8'
        break
      case 'string':
        rawType = 'bytes'
        break
    }
    ret = {
      rawType: rawType,
      name: type,
      memoryUsage: 32
    }

    if ((type.startsWith('bytes') && type !== 'bytes') || type.startsWith('uint') || type.startsWith('int')) {
      ret.size = parseTypeN(type)
    } else if (type.startsWith('ufixed') || type.startsWith('fixed')) {
      ret.size = parseTypeNxM(type)
    }

    if (type.startsWith('bytes') && type !== 'bytes' && (ret.size < 1 || ret.size > 32)) {
      throw new Error('Invalid bytes<N> width: ' + ret.size)
    }
    if ((type.startsWith('uint') || type.startsWith('int')) && (ret.size % 8 || ret.size < 8 || ret.size > 256)) {
      throw new Error('Invalid int/uint<N> width: ' + ret.size)
    }
    return ret
  }
}
function parseType ( type ) { var size var ret if ( isArray ( type ) ) { size = parseTypeArray ( type ) var subArray = type . slice ( 0 , type . lastIndexOf ( '[' ) ) subArray = parseType ( subArray ) ret = { isArray : true , name : type , size : size , memoryUsage : size === 'dynamic' ? 32 : subArray . memoryUsage * size , subArray : subArray } return ret } else { var rawType switch ( type ) { case 'address' : rawType = 'uint160' break case 'bool' : rawType = 'uint8' break case 'string' : rawType = 'bytes' break } ret = { rawType : rawType , name : type , memoryUsage : 32 } if ( ( type . startsWith ( 'bytes' ) && type !== 'bytes' ) || type . startsWith ( 'uint' ) || type . startsWith ( 'int' ) ) { ret . size = parseTypeN ( type ) } else if ( type . startsWith ( 'ufixed' ) || type . startsWith ( 'fixed' ) ) { ret . size = parseTypeNxM ( type ) } if ( type . startsWith ( 'bytes' ) && type !== 'bytes' && ( ret . size < 1 || ret . size > 32 ) ) { throw new Error ( 'Invalid bytes<N> width: ' + ret . size ) } if ( ( type . startsWith ( 'uint' ) || type . startsWith ( 'int' ) ) && ( ret . size % 8 || ret . size < 8 || ret . size > 256 ) ) { throw new Error ( 'Invalid int/uint<N> width: ' + ret . size ) } return ret } }
Parse the given type @returns: {} containing the type itself, memory usage and (including size and subArray if applicable)
Parse the given type