import u from "../utils.mjs";
function f(e) {
  return u.matchAll(/\w+|\[(\w*)]/g, e).map((o) => o[0] === "[]" ? "" : o[1] || o[0]);
}
function y(e) {
  const o = {}, r = Object.keys(e);
  let i;
  const n = r.length;
  let c;
  for (i = 0; i < n; i++)
    c = r[i], o[c] = e[c];
  return o;
}
function m(e) {
  function o(r, i, n, c) {
    let s = r[c++];
    const l = Number.isFinite(+s), t = c >= r.length;
    return s = !s && u.isArray(n) ? n.length : s, t ? (u.hasOwnProp(n, s) ? n[s] = [n[s], i] : n[s] = i, !l) : ((!n[s] || !u.isObject(n[s])) && (n[s] = []), o(r, i, n[s], c) && u.isArray(n[s]) && (n[s] = y(n[s])), !l);
  }
  if (u.isFormData(e) && u.isFunction(e.entries)) {
    const r = {};
    return u.forEachEntry(e, (i, n) => {
      o(f(i), n, r, 0);
    }), r;
  }
  return null;
}
export {
  m as default
};
