import formatNum from './formatNumber';
import formatPercent from './formatPercent';
import formatSentence from './formatSentenceNumber';

/**
 * Format a number for presentation. This could be a big integer that needs
 * comma separation, a percentage represented as a number between 0 and 1, etc.
 *
 * @param {number} n
 *   The number to format
 * @param {Object} [options]
 *   Additional configuration options:
 *   - `format`: The format to use. Type: `'number'|'percent'|'sentence'`.
 *     Default: `'number'`.
 *   - `locale`: The locale to use for number formatting. Type: `string`.
 *     Default: `'en-US'`.
 * @returns {string}
 */
const formatNumber = function formatNumber(n, options = {}) {
  const {
    format = 'number',
    locale = 'en-US',
    maximumFractionDigits,
    minimumFractionDigits
  } = options;
  const formatOpts = {
    locale,
    maximumFractionDigits,
    minimumFractionDigits
  };
  if (format === 'percent') {
    return formatPercent(n, formatOpts);
  }
  if (format === 'sentence') {
    return formatSentence(n, formatOpts);
  }
  return formatNum(n, formatOpts);
};
export default formatNumber;