"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.abbreviateNumber = abbreviateNumber;

function abbreviateNumber() {
  var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  if (typeof count === "string") {
    count = parseInt(count);
  }

  if (global.Intl && global.Intl.NumberFormat) {
    var numberFormat = Intl.NumberFormat(options.locale || "en", {
      notation: "compact" // compactDisplay: "short",

    });
    return numberFormat.format(count);
  } //Comaptibility


  var COUNT_ABBRS = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
  var _options$withAbbr = options.withAbbr,
      withAbbr = _options$withAbbr === void 0 ? true : _options$withAbbr,
      _options$decimals = options.decimals,
      decimals = _options$decimals === void 0 ? 2 : _options$decimals;
  var i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
  var result = parseFloat((count / Math.pow(1000, i)).toFixed(decimals));

  if (withAbbr) {
    result += "".concat(COUNT_ABBRS[i]);
  }

  return result;
}