import { apnumber, intword } from 'journalize';
import formatNumber from './formatNumber';

/**
 * Format a number as a string for use in a sentence according to AP style.
 *
 * @param {number} n
 * @returns {string}
 */
const formatSentenceNumber = function formatSentenceNumber(n, options = {}) {
  if (typeof n !== 'number') return undefined;
  if (n === 0) return 'zero';
  if (n < 10) return apnumber(n);
  if (n >= 1000000) {
    return intword(n);
  }
  return formatNumber(n, options);
};
export default formatSentenceNumber;