import w from "../../../../../../../../_virtual/window.js";
var s = function(r) {
  return r.toString(2).length;
}, T = function(r) {
  return Math.ceil(s(r) / 8);
}, U = function(r) {
  return ArrayBuffer.isView === "function" ? ArrayBuffer.isView(r) : r && r.buffer instanceof ArrayBuffer;
}, x = function(r) {
  return U(r);
}, h = function(r) {
  return r instanceof Uint8Array ? r : (!Array.isArray(r) && !x(r) && !(r instanceof ArrayBuffer) && (typeof r != "number" || typeof r == "number" && r !== r ? r = 0 : r = [r]), new Uint8Array(r && r.buffer || r, r && r.byteOffset || 0, r && r.byteLength || 0));
}, t = w.BigInt || Number, A = [t("0x1"), t("0x100"), t("0x10000"), t("0x1000000"), t("0x100000000"), t("0x10000000000"), t("0x1000000000000"), t("0x100000000000000"), t("0x10000000000000000")];
(function() {
  var i = new Uint16Array([65484]), r = new Uint8Array(i.buffer, i.byteOffset, i.byteLength);
  return r[0] === 255 ? "big" : r[0] === 204 ? "little" : "unknown";
})();
var C = function(r, n) {
  var f = n === void 0 ? {} : n, o = f.signed, v = o === void 0 ? !1 : o, u = f.le, e = u === void 0 ? !1 : u;
  r = h(r);
  var a = e ? "reduce" : "reduceRight", c = r[a] ? r[a] : Array.prototype[a], y = c.call(r, function(g, B, p) {
    var d = e ? p : Math.abs(p + 1 - r.length);
    return g + t(B) * A[d];
  }, t(0));
  if (v) {
    var l = A[r.length] / t(2) - t(1);
    y = t(y), y > l && (y -= l, y -= l, y -= t(2));
  }
  return Number(y);
}, L = function(r, n) {
  var f = {}, o = f.le, v = o === void 0 ? !1 : o;
  (typeof r != "bigint" && typeof r != "number" || typeof r == "number" && r !== r) && (r = 0), r = t(r);
  for (var u = T(r), e = new Uint8Array(new ArrayBuffer(u)), a = 0; a < u; a++) {
    var c = v ? a : Math.abs(a + 1 - e.length);
    e[c] = Number(r / A[a] & t(255)), r < 0 && (e[c] = Math.abs(~e[c]), e[c] -= a === 0 ? 1 : 2);
  }
  return e;
}, F = function(r, n) {
  if (typeof r != "string" && r && typeof r.toString == "function" && (r = r.toString()), typeof r != "string")
    return new Uint8Array();
  n || (r = unescape(encodeURIComponent(r)));
  for (var f = new Uint8Array(r.length), o = 0; o < r.length; o++)
    f[o] = r.charCodeAt(o);
  return f;
}, M = function() {
  for (var r = arguments.length, n = new Array(r), f = 0; f < r; f++)
    n[f] = arguments[f];
  if (n = n.filter(function(e) {
    return e && (e.byteLength || e.length) && typeof e != "string";
  }), n.length <= 1)
    return h(n[0]);
  var o = n.reduce(function(e, a, c) {
    return e + (a.byteLength || a.length);
  }, 0), v = new Uint8Array(o), u = 0;
  return n.forEach(function(e) {
    e = h(e), v.set(e, u), u += e.byteLength;
  }), v;
}, $ = function(r, n, f) {
  var o = f === void 0 ? {} : f, v = o.offset, u = v === void 0 ? 0 : v, e = o.mask, a = e === void 0 ? [] : e;
  r = h(r), n = h(n);
  var c = n.every ? n.every : Array.prototype.every;
  return n.length && r.length - u >= n.length && // ie 11 doesn't support every on uin8
  c.call(n, function(y, l) {
    var g = a[l] ? a[l] & r[u + l] : r[u + l];
    return y === g;
  });
};
export {
  $ as bytesMatch,
  C as bytesToNumber,
  M as concatTypedArrays,
  s as countBits,
  T as countBytes,
  U as isArrayBufferView,
  x as isTypedArray,
  L as numberToBytes,
  F as stringToBytes,
  h as toUint8
};
//# sourceMappingURL=byte-helpers.js.map
