function J(t) {
  return Math.abs(t = Math.round(t)) >= 1e21 ? t.toLocaleString("en").replace(/,/g, "") : t.toString(10);
}
function N(t, i) {
  if ((o = (t = i ? t.toExponential(i - 1) : t.toExponential()).indexOf("e")) < 0) return null;
  var o, r = t.slice(0, o);
  return [
    r.length > 1 ? r[0] + r.slice(2) : r,
    +t.slice(o + 1)
  ];
}
function K(t) {
  return t = N(Math.abs(t)), t ? t[1] : NaN;
}
function P(t, i) {
  return function(o, r) {
    for (var n = o.length, s = [], d = 0, u = t[0], y = 0; n > 0 && u > 0 && (y + u + 1 > r && (u = Math.max(1, r - y)), s.push(o.substring(n -= u, n + u)), !((y += u + 1) > r)); )
      u = t[d = (d + 1) % t.length];
    return s.reverse().join(i);
  };
}
function Q(t) {
  return function(i) {
    return i.replace(/[0-9]/g, function(o) {
      return t[+o];
    });
  };
}
var R = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
function E(t) {
  if (!(i = R.exec(t))) throw new Error("invalid format: " + t);
  var i;
  return new $({
    fill: i[1],
    align: i[2],
    sign: i[3],
    symbol: i[4],
    zero: i[5],
    width: i[6],
    comma: i[7],
    precision: i[8] && i[8].slice(1),
    trim: i[9],
    type: i[10]
  });
}
E.prototype = $.prototype;
function $(t) {
  this.fill = t.fill === void 0 ? " " : t.fill + "", this.align = t.align === void 0 ? ">" : t.align + "", this.sign = t.sign === void 0 ? "-" : t.sign + "", this.symbol = t.symbol === void 0 ? "" : t.symbol + "", this.zero = !!t.zero, this.width = t.width === void 0 ? void 0 : +t.width, this.comma = !!t.comma, this.precision = t.precision === void 0 ? void 0 : +t.precision, this.trim = !!t.trim, this.type = t.type === void 0 ? "" : t.type + "";
}
$.prototype.toString = function() {
  return this.fill + this.align + this.sign + this.symbol + (this.zero ? "0" : "") + (this.width === void 0 ? "" : Math.max(1, this.width | 0)) + (this.comma ? "," : "") + (this.precision === void 0 ? "" : "." + Math.max(0, this.precision | 0)) + (this.trim ? "~" : "") + this.type;
};
function V(t) {
  t: for (var i = t.length, o = 1, r = -1, n; o < i; ++o)
    switch (t[o]) {
      case ".":
        r = n = o;
        break;
      case "0":
        r === 0 && (r = o), n = o;
        break;
      default:
        if (!+t[o]) break t;
        r > 0 && (r = 0);
        break;
    }
  return r > 0 ? t.slice(0, r) + t.slice(n + 1) : t;
}
var q;
function W(t, i) {
  var o = N(t, i);
  if (!o) return t + "";
  var r = o[0], n = o[1], s = n - (q = Math.max(-8, Math.min(8, Math.floor(n / 3))) * 3) + 1, d = r.length;
  return s === d ? r : s > d ? r + new Array(s - d + 1).join("0") : s > 0 ? r.slice(0, s) + "." + r.slice(s) : "0." + new Array(1 - s).join("0") + N(t, Math.max(0, i + s - 1))[0];
}
function O(t, i) {
  var o = N(t, i);
  if (!o) return t + "";
  var r = o[0], n = o[1];
  return n < 0 ? "0." + new Array(-n).join("0") + r : r.length > n + 1 ? r.slice(0, n + 1) + "." + r.slice(n + 1) : r + new Array(n - r.length + 2).join("0");
}
const T = {
  "%": (t, i) => (t * 100).toFixed(i),
  b: (t) => Math.round(t).toString(2),
  c: (t) => t + "",
  d: J,
  e: (t, i) => t.toExponential(i),
  f: (t, i) => t.toFixed(i),
  g: (t, i) => t.toPrecision(i),
  o: (t) => Math.round(t).toString(8),
  p: (t, i) => O(t * 100, i),
  r: O,
  s: W,
  X: (t) => Math.round(t).toString(16).toUpperCase(),
  x: (t) => Math.round(t).toString(16)
};
function U(t) {
  return t;
}
var Y = Array.prototype.map, Z = ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y"];
function _(t) {
  var i = t.grouping === void 0 || t.thousands === void 0 ? U : P(Y.call(t.grouping, Number), t.thousands + ""), o = t.currency === void 0 ? "" : t.currency[0] + "", r = t.currency === void 0 ? "" : t.currency[1] + "", n = t.decimal === void 0 ? "." : t.decimal + "", s = t.numerals === void 0 ? U : Q(Y.call(t.numerals, String)), d = t.percent === void 0 ? "%" : t.percent + "", u = t.minus === void 0 ? "−" : t.minus + "", y = t.nan === void 0 ? "NaN" : t.nan + "";
  function C(a) {
    a = E(a);
    var M = a.fill, b = a.align, h = a.sign, w = a.symbol, v = a.zero, x = a.width, j = a.comma, g = a.precision, F = a.trim, c = a.type;
    c === "n" ? (j = !0, c = "g") : T[c] || (g === void 0 && (g = 12), F = !0, c = "g"), (v || M === "0" && b === "=") && (v = !0, M = "0", b = "=");
    var D = w === "$" ? o : w === "#" && /[boxX]/.test(c) ? "0" + c.toLowerCase() : "", H = w === "$" ? r : /[%p]/.test(c) ? d : "", L = T[c], I = /[defgprs%]/.test(c);
    g = g === void 0 ? 6 : /[gprs]/.test(c) ? Math.max(1, Math.min(21, g)) : Math.max(0, Math.min(20, g));
    function X(e) {
      var m = D, l = H, p, G, k;
      if (c === "c")
        l = L(e) + l, e = "";
      else {
        e = +e;
        var S = e < 0 || 1 / e < 0;
        if (e = isNaN(e) ? y : L(Math.abs(e), g), F && (e = V(e)), S && +e == 0 && h !== "+" && (S = !1), m = (S ? h === "(" ? h : u : h === "-" || h === "(" ? "" : h) + m, l = (c === "s" ? Z[8 + q / 3] : "") + l + (S && h === "(" ? ")" : ""), I) {
          for (p = -1, G = e.length; ++p < G; )
            if (k = e.charCodeAt(p), 48 > k || k > 57) {
              l = (k === 46 ? n + e.slice(p + 1) : e.slice(p)) + l, e = e.slice(0, p);
              break;
            }
        }
      }
      j && !v && (e = i(e, 1 / 0));
      var z = m.length + e.length + l.length, f = z < x ? new Array(x - z + 1).join(M) : "";
      switch (j && v && (e = i(f + e, f.length ? x - l.length : 1 / 0), f = ""), b) {
        case "<":
          e = m + e + l + f;
          break;
        case "=":
          e = m + f + e + l;
          break;
        case "^":
          e = f.slice(0, z = f.length >> 1) + m + e + l + f.slice(z);
          break;
        default:
          e = f + m + e + l;
          break;
      }
      return s(e);
    }
    return X.toString = function() {
      return a + "";
    }, X;
  }
  function B(a, M) {
    var b = C((a = E(a), a.type = "f", a)), h = Math.max(-8, Math.min(8, Math.floor(K(M) / 3))) * 3, w = Math.pow(10, -h), v = Z[8 + h / 3];
    return function(x) {
      return b(w * x) + v;
    };
  }
  return {
    format: C,
    formatPrefix: B
  };
}
var A, tt, it;
et({
  thousands: ",",
  grouping: [3],
  currency: ["$", ""]
});
function et(t) {
  return A = _(t), tt = A.format, it = A.formatPrefix, A;
}
export {
  K as J,
  E as N,
  tt as n,
  it as t
};
