"use strict";

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

var _dayjs = _interopRequireDefault(require("dayjs"));

var _relativeTime = _interopRequireDefault(require("dayjs/plugin/relativeTime"));

var _updateLocale = _interopRequireDefault(require("dayjs/plugin/updateLocale"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

_dayjs.default.extend(_relativeTime.default);

_dayjs.default.extend(_updateLocale.default);

_dayjs.default.updateLocale("en", {
  relativeTime: {
    future: "in %s",
    past: "%s ago",
    s: "seconds",
    m: "1m",
    mm: "%dm",
    h: "1h",
    hh: "%dh",
    d: "1d",
    dd: "%dd",
    M: "1mo",
    MM: "%dmo",
    y: "1y",
    yy: "%dy"
  }
});

function toFixedIfNecessary(value, dp) {
  return +parseFloat(value).toFixed(dp);
}

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

function formatBytes(bytes) {
  var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
  if (bytes === 0) return "0B";
  var k = 1024;
  var dm = decimals < 0 ? 0 : decimals;
  var sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  var i = Math.floor(Math.log(bytes) / Math.log(k));
  return "".concat(parseFloat((bytes / Math.pow(k, i)).toFixed(dm)), " ").concat(sizes[i]);
}