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