function parsePercent(percent, max) {
  switch (percent) {
    case 'center':
    case 'middle':
      percent = '50%';
      break;
    case 'left':
    case 'top':
      percent = '0%';
      break;
    case 'right':
    case 'bottom':
      percent = '100%';
      break;
  }
  if (typeof percent === 'string') {
    if (percent.replace(/^\s+|\s+$/g, '').match(/%$/)) {
      return parseFloat(percent) / 100 * max;
    }
    return parseFloat(percent);
  }
  return percent == null ? NaN : +percent;
}

export { parsePercent };
