@tolki/path 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/path.js CHANGED
@@ -1,684 +1,521 @@
1
- import { isNull as p, isUndefined as a, isNumber as m, isInteger as I, phpArrayKey as b, isArray as h, isObject as x, isMap as O, readMapKey as K, isIllegalOffset as B, arrayKeyExistsError as G, isFloat as X, deleteMapKey as _, isString as H, isPrototypeObject as M, isPlainObject as N, nextIntegerKey as Q, defineKey as v, InvalidArgumentException as Y, arrayValueMessage as Z, keyedEntries as P, isIntegerLikeKey as D, isObjectAny as L, castableToArray as F, writeMapKey as A, isUnsafeKey as T, toPhpKeyString as y, isFunction as J } from "@tolki/utils";
2
- function V(n) {
3
- if (p(n) || a(n))
4
- return [];
5
- if (!m(n) && Number.isNaN(n))
6
- return null;
7
- if (m(n))
8
- return I(n) && n >= 0 ? [n] : null;
9
- const e = String(n);
10
- if (e.length === 0)
11
- return [];
12
- const u = e.split("."), s = [];
13
- for (const t of u) {
14
- if (t.length === 0)
15
- return null;
16
- const l = b(t);
17
- s.push(m(l) && l >= 0 ? l : t);
18
- }
19
- return s;
1
+ import { InvalidArgumentException as e, arrayKeyExistsError as t, arrayValueMessage as n, castableToArray as r, defineKey as i, deleteMapKey as a, isArray as o, isFloat as s, isFunction as c, isIllegalOffset as l, isInteger as u, isIntegerLikeKey as d, isMap as f, isNull as p, isNumber as m, isObject as h, isObjectAny as g, isPlainObject as _, isPrototypeObject as v, isString as y, isUndefined as b, isUnsafeKey as x, keyedEntries as S, nextIntegerKey as C, phpArrayKey as w, readMapKey as T, toPhpKeyString as ee, writeMapKey as E } from "@tolki/utils";
2
+ // src/path.ts
3
+ /* @__NO_SIDE_EFFECTS__ */
4
+ function D(e) {
5
+ if (p(e) || b(e)) return [];
6
+ if (!m(e) && Number.isNaN(e)) return null;
7
+ if (m(e)) return u(e) && e >= 0 ? [e] : null;
8
+ let t = String(e);
9
+ if (t.length === 0) return [];
10
+ let n = t.split("."), r = [];
11
+ for (let e of n) {
12
+ if (e.length === 0) return null;
13
+ let t = w(e);
14
+ r.push(m(t) && t >= 0 ? t : e);
15
+ }
16
+ return r;
20
17
  }
21
- function cn(n, e) {
22
- if (p(e))
23
- return !1;
24
- if (m(e))
25
- return h(n) ? I(e) && e >= 0 && e < n.length : !p(n) && x(n) && E(n, String(e)).found;
26
- const u = V(e);
27
- if (!u || u.length === 0)
28
- return !1;
29
- let s = n;
30
- for (const t of u)
31
- if (h(s)) {
32
- if (!m(t) || t >= s.length)
33
- return !1;
34
- s = s[t];
35
- } else if (O(s)) {
36
- const l = K(s, t);
37
- if (!l.found)
38
- return !1;
39
- s = l.value;
40
- } else if (x(s) && Object.hasOwn(s, String(t)))
41
- s = s[String(t)];
42
- else
43
- return !1;
44
- return !0;
18
+ /* @__NO_SIDE_EFFECTS__ */
19
+ function O(e, t) {
20
+ if (p(t)) return !1;
21
+ if (m(t)) return o(e) ? u(t) && t >= 0 && t < e.length : !p(e) && h(e) && $(e, String(t)).found;
22
+ let n = /* @__PURE__ */ D(t);
23
+ if (!n || n.length === 0) return !1;
24
+ let r = e;
25
+ for (let e of n) if (o(r)) {
26
+ if (!m(e) || e >= r.length) return !1;
27
+ r = r[e];
28
+ } else if (f(r)) {
29
+ let t = T(r, e);
30
+ if (!t.found) return !1;
31
+ r = t.value;
32
+ } else if (h(r) && Object.hasOwn(r, String(e))) r = r[String(e)];
33
+ else return !1;
34
+ return !0;
45
35
  }
46
- function U(n, e) {
47
- if (p(e) || a(e))
48
- return { found: !0, value: n };
49
- if (m(e))
50
- return h(n) ? !I(e) || e < 0 || e >= n.length ? { found: !1 } : { found: !0, value: n[e] } : !p(n) && x(n) ? E(n, String(e)) : { found: !1 };
51
- const u = V(e);
52
- if (!u || u.length === 0)
53
- return { found: !1 };
54
- let s = n;
55
- for (const t of u)
56
- if (h(s)) {
57
- if (!m(t) || t >= s.length)
58
- return { found: !1 };
59
- s = s[t];
60
- } else if (O(s)) {
61
- const l = K(s, t);
62
- if (!l.found)
63
- return { found: !1 };
64
- s = l.value;
65
- } else if (x(s) && Object.hasOwn(s, String(t)))
66
- s = s[String(t)];
67
- else
68
- return { found: !1 };
69
- return { found: !0, value: s };
36
+ /* @__NO_SIDE_EFFECTS__ */
37
+ function k(e, t) {
38
+ if (p(t) || b(t)) return {
39
+ found: !0,
40
+ value: e
41
+ };
42
+ if (m(t)) return o(e) ? !u(t) || t < 0 || t >= e.length ? { found: !1 } : {
43
+ found: !0,
44
+ value: e[t]
45
+ } : !p(e) && h(e) ? $(e, String(t)) : { found: !1 };
46
+ let n = /* @__PURE__ */ D(t);
47
+ if (!n || n.length === 0) return { found: !1 };
48
+ let r = e;
49
+ for (let e of n) if (o(r)) {
50
+ if (!m(e) || e >= r.length) return { found: !1 };
51
+ r = r[e];
52
+ } else if (f(r)) {
53
+ let t = T(r, e);
54
+ if (!t.found) return { found: !1 };
55
+ r = t.value;
56
+ } else if (h(r) && Object.hasOwn(r, String(e))) r = r[String(e)];
57
+ else return { found: !1 };
58
+ return {
59
+ found: !0,
60
+ value: r
61
+ };
70
62
  }
71
- function ln(n, e) {
72
- if ((h(e) ? e : [e]).some(B))
73
- throw G();
74
- return x(n) ? k(n, e) : nn(n, e);
63
+ /* @__NO_SIDE_EFFECTS__ */
64
+ function A(e, n) {
65
+ if ((o(n) ? n : [n]).some(l)) throw t();
66
+ return h(e) ? /* @__PURE__ */ j(e, n) : /* @__PURE__ */ M(e, n);
75
67
  }
76
- function k(n, e) {
77
- const u = p(e) || a(e) ? [] : h(e) ? e : [e], s = { ...n }, t = (f, o) => {
78
- const i = b(f);
79
- return !I(i) || i < 0 || i >= o.length ? null : i;
80
- }, l = (f) => {
81
- if (h(f))
82
- return f.slice();
83
- if (O(f))
84
- return new Map(f);
85
- if (x(f)) {
86
- const o = Object.getPrototypeOf(f);
87
- if (o === Object.prototype || p(o))
88
- return { ...f };
89
- }
90
- return null;
91
- }, c = (f, o) => {
92
- if (Object.hasOwn(s, f)) {
93
- delete s[o];
94
- return;
95
- }
96
- const i = f.split(".");
97
- let r = s;
98
- for (; i.length > 1; ) {
99
- const d = i.shift();
100
- if (h(r)) {
101
- const w = t(d, r);
102
- if (p(w))
103
- return;
104
- const j = l(r[w]);
105
- if (p(j))
106
- return;
107
- r[w] = j, r = j;
108
- continue;
109
- }
110
- if (O(r)) {
111
- const w = K(r, d), j = w.found ? l(w.value) : null;
112
- if (p(j))
113
- return;
114
- A(r, d, j), r = j;
115
- continue;
116
- }
117
- if (!Object.hasOwn(r, d))
118
- return;
119
- const S = l(r[d]);
120
- if (p(S))
121
- return;
122
- r[d] = S, r = S;
123
- }
124
- const g = i.shift();
125
- if (h(r)) {
126
- const d = t(g, r);
127
- p(d) || r.splice(d, 1);
128
- return;
129
- }
130
- if (O(r)) {
131
- _(r, g);
132
- return;
133
- }
134
- delete r[g];
135
- };
136
- for (const f of u) {
137
- const o = z(f);
138
- c(o, X(f) ? String(b(f)) : o);
139
- }
140
- return s;
68
+ /* @__NO_SIDE_EFFECTS__ */
69
+ function j(e, t) {
70
+ let n = p(t) || b(t) ? [] : o(t) ? t : [t], r = { ...e }, i = (e, t) => {
71
+ let n = w(e);
72
+ return !u(n) || n < 0 || n >= t.length ? null : n;
73
+ }, c = (e) => {
74
+ if (o(e)) return e.slice();
75
+ if (f(e)) return new Map(e);
76
+ if (h(e)) {
77
+ let t = Object.getPrototypeOf(e);
78
+ if (t === Object.prototype || p(t)) return { ...e };
79
+ }
80
+ return null;
81
+ }, l = (e, t) => {
82
+ if (Object.hasOwn(r, e)) {
83
+ delete r[t];
84
+ return;
85
+ }
86
+ let n = e.split("."), s = r;
87
+ for (; n.length > 1;) {
88
+ let e = n.shift();
89
+ if (o(s)) {
90
+ let t = i(e, s);
91
+ if (p(t)) return;
92
+ let n = c(s[t]);
93
+ if (p(n)) return;
94
+ s[t] = n, s = n;
95
+ continue;
96
+ }
97
+ if (f(s)) {
98
+ let t = T(s, e), n = t.found ? c(t.value) : null;
99
+ if (p(n)) return;
100
+ E(s, e, n), s = n;
101
+ continue;
102
+ }
103
+ if (!Object.hasOwn(s, e)) return;
104
+ let t = c(s[e]);
105
+ if (p(t)) return;
106
+ s[e] = t, s = t;
107
+ }
108
+ let l = n.shift();
109
+ if (o(s)) {
110
+ let e = i(l, s);
111
+ p(e) || s.splice(e, 1);
112
+ } else f(s) ? a(s, l) : delete s[l];
113
+ };
114
+ for (let e of n) {
115
+ let t = Q(e);
116
+ l(t, s(e) ? String(w(e)) : t);
117
+ }
118
+ return r;
141
119
  }
142
- function nn(n, e) {
143
- const u = n.slice();
144
- if (p(e))
145
- return u;
146
- const s = (c) => {
147
- let f = u;
148
- for (const o of c) {
149
- let i;
150
- if (h(f))
151
- i = m(o) && o >= 0 ? f[o] : void 0;
152
- else if (O(f)) {
153
- const g = K(f, o);
154
- i = g.found ? g.value : void 0;
155
- } else Object.hasOwn(f, o) && (i = f[o]);
156
- if (!h(i) && !N(i) && !O(i) || M(i))
157
- return null;
158
- const r = h(i) ? i.slice() : O(i) ? new Map(i) : { ...i };
159
- O(f) ? A(f, o, r) : v(
160
- f,
161
- o,
162
- r
163
- ), f = r;
164
- }
165
- return f;
166
- }, t = /* @__PURE__ */ new Map();
167
- for (const c of h(e) ? e : [e]) {
168
- const f = I(c) ? [c] : z(c).split(".").map(b), o = f.slice(0, -1), i = JSON.stringify(o), r = t.get(i) ?? { parent: o, leaves: /* @__PURE__ */ new Set() };
169
- r.leaves.add(f[o.length]), t.set(i, r);
170
- }
171
- const l = [...t.values()].sort(
172
- (c, f) => f.parent.length - c.parent.length
173
- );
174
- for (const { parent: c, leaves: f } of l) {
175
- const o = s(c);
176
- if (h(o)) {
177
- const i = [...f].filter((r) => m(r) && r >= 0).sort((r, g) => g - r);
178
- for (const r of i)
179
- o.splice(r, 1);
180
- } else if (O(o))
181
- for (const i of f)
182
- _(o, i);
183
- else if (!p(o))
184
- for (const i of f)
185
- delete o[i];
186
- }
187
- return u;
120
+ /* @__NO_SIDE_EFFECTS__ */
121
+ function M(e, t) {
122
+ let n = e.slice();
123
+ if (p(t)) return n;
124
+ let r = (e) => {
125
+ let t = n;
126
+ for (let n of e) {
127
+ let e;
128
+ if (o(t)) e = m(n) && n >= 0 ? t[n] : void 0;
129
+ else if (f(t)) {
130
+ let r = T(t, n);
131
+ e = r.found ? r.value : void 0;
132
+ } else Object.hasOwn(t, n) && (e = t[n]);
133
+ if (!o(e) && !_(e) && !f(e) || v(e)) return null;
134
+ let r = o(e) ? e.slice() : f(e) ? new Map(e) : { ...e };
135
+ f(t) ? E(t, n, r) : i(t, n, r), t = r;
136
+ }
137
+ return t;
138
+ }, s = /* @__PURE__ */ new Map();
139
+ for (let e of o(t) ? t : [t]) {
140
+ let t = u(e) ? [e] : Q(e).split(".").map(w), n = t.slice(0, -1), r = JSON.stringify(n), i = s.get(r) ?? {
141
+ parent: n,
142
+ leaves: /* @__PURE__ */ new Set()
143
+ };
144
+ i.leaves.add(t[n.length]), s.set(r, i);
145
+ }
146
+ let c = [...s.values()].sort((e, t) => t.parent.length - e.parent.length);
147
+ for (let { parent: e, leaves: t } of c) {
148
+ let n = r(e);
149
+ if (o(n)) {
150
+ let e = [...t].filter((e) => m(e) && e >= 0).sort((e, t) => t - e);
151
+ for (let t of e) n.splice(t, 1);
152
+ } else if (f(n)) for (let e of t) a(n, e);
153
+ else if (!p(n)) for (let e of t) delete n[e];
154
+ }
155
+ return n;
188
156
  }
189
- function gn(n, e, u) {
190
- if (p(e))
191
- return u;
192
- if (!h(n))
193
- return [];
194
- const s = n.slice(), t = (i, r) => i > r ? r : i;
195
- if (m(e) || H(e) && e.indexOf(".") === -1) {
196
- const i = m(e) ? e : b(e);
197
- if (!I(i) || i < 0)
198
- return s;
199
- const r = t(i, s.length), g = s.slice();
200
- return r === g.length ? g.push(u) : g[r] = u, g;
201
- }
202
- const l = String(e).split("."), c = [];
203
- for (const i of l) {
204
- const r = b(i);
205
- if (!I(r) || r < 0)
206
- return s;
207
- c.push(r);
208
- }
209
- const f = s.slice();
210
- let o = f;
211
- for (let i = 0; i < c.length; i++) {
212
- const r = c[i], g = i === c.length - 1, d = t(r, o.length);
213
- if (g) {
214
- d === o.length ? o.push(u) : o[d] = u;
215
- break;
216
- }
217
- if (d === o.length) {
218
- const w = [];
219
- o.push(w), o = w;
220
- continue;
221
- }
222
- const S = o[d];
223
- if (p(S)) {
224
- const w = [];
225
- o[d] = w, o = w;
226
- continue;
227
- }
228
- if (h(S)) {
229
- const w = S.slice();
230
- o[d] = w, o = w;
231
- continue;
232
- }
233
- return s;
234
- }
235
- return f;
157
+ /* @__NO_SIDE_EFFECTS__ */
158
+ function N(e, t, n) {
159
+ if (p(t)) return n;
160
+ if (!o(e)) return [];
161
+ let r = e.slice(), i = (e, t) => e > t ? t : e;
162
+ if (m(t) || y(t) && t.indexOf(".") === -1) {
163
+ let e = m(t) ? t : w(t);
164
+ if (!u(e) || e < 0) return r;
165
+ let a = i(e, r.length), o = r.slice();
166
+ return a === o.length ? o.push(n) : o[a] = n, o;
167
+ }
168
+ let a = String(t).split("."), s = [];
169
+ for (let e of a) {
170
+ let t = w(e);
171
+ if (!u(t) || t < 0) return r;
172
+ s.push(t);
173
+ }
174
+ let c = r.slice(), l = c;
175
+ for (let e = 0; e < s.length; e++) {
176
+ let t = s[e], a = e === s.length - 1, c = i(t, l.length);
177
+ if (a) {
178
+ c === l.length ? l.push(n) : l[c] = n;
179
+ break;
180
+ }
181
+ if (c === l.length) {
182
+ let e = [];
183
+ l.push(e), l = e;
184
+ continue;
185
+ }
186
+ let u = l[c];
187
+ if (p(u)) {
188
+ let e = [];
189
+ l[c] = e, l = e;
190
+ } else if (o(u)) {
191
+ let e = u.slice();
192
+ l[c] = e, l = e;
193
+ } else return r;
194
+ }
195
+ return c;
236
196
  }
237
- function hn(n, e, ...u) {
238
- const s = h(n) && !M(n) ? n : [];
239
- if (p(e) || a(e))
240
- return s.push(...u), s;
241
- const t = V(e);
242
- if (!t || t.length === 0)
243
- return s;
244
- const l = (r, g) => {
245
- if (h(r)) {
246
- if (!m(g))
247
- return null;
248
- const S = Math.min(g, r.length);
249
- return S < r.length ? { slot: S, found: !0, value: r[S] } : { slot: S, found: !1 };
250
- }
251
- if (O(r))
252
- return { slot: g, ...K(r, g) };
253
- const d = String(g);
254
- return Object.hasOwn(r, d) ? { slot: d, found: !0, value: r[d] } : { slot: d, found: !1 };
255
- }, c = (r, g, d) => {
256
- if (O(r)) {
257
- A(r, g, d);
258
- return;
259
- }
260
- v(r, g, d);
261
- };
262
- let f = s;
263
- for (const [r, g] of t.slice(0, -1).entries()) {
264
- const d = l(f, g);
265
- if (p(d))
266
- return s;
267
- const S = d.value;
268
- if (M(S))
269
- return s;
270
- if (h(S) || N(S) || O(S)) {
271
- f = S;
272
- continue;
273
- }
274
- const w = m(t[r + 1]) ? [] : {};
275
- c(f, d.slot, w), f = w;
276
- }
277
- const o = l(f, t[t.length - 1]);
278
- if (p(o))
279
- return s;
280
- const i = o.found ? o.value : [];
281
- if (o.found || c(f, o.slot, i), h(i))
282
- return M(i) || i.push(...u), s;
283
- if (O(i) || N(i) && !M(i)) {
284
- let r = Q(i);
285
- for (const g of u)
286
- O(i) ? i.set(r++, g) : v(i, String(r++), g);
287
- return s;
288
- }
289
- throw new Y(Z(i, e));
197
+ function P(t, r, ...a) {
198
+ let s = o(t) && !v(t) ? t : [];
199
+ if (p(r) || b(r)) return s.push(...a), s;
200
+ let c = /* @__PURE__ */ D(r);
201
+ if (!c || c.length === 0) return s;
202
+ let l = (e, t) => {
203
+ if (o(e)) {
204
+ if (!m(t)) return null;
205
+ let n = Math.min(t, e.length);
206
+ return n < e.length ? {
207
+ slot: n,
208
+ found: !0,
209
+ value: e[n]
210
+ } : {
211
+ slot: n,
212
+ found: !1
213
+ };
214
+ }
215
+ if (f(e)) return {
216
+ slot: t,
217
+ ...T(e, t)
218
+ };
219
+ let n = String(t);
220
+ return Object.hasOwn(e, n) ? {
221
+ slot: n,
222
+ found: !0,
223
+ value: e[n]
224
+ } : {
225
+ slot: n,
226
+ found: !1
227
+ };
228
+ }, u = (e, t, n) => {
229
+ f(e) ? E(e, t, n) : i(e, t, n);
230
+ }, d = s;
231
+ for (let [e, t] of c.slice(0, -1).entries()) {
232
+ let n = l(d, t);
233
+ if (p(n)) return s;
234
+ let r = n.value;
235
+ if (v(r)) return s;
236
+ if (o(r) || _(r) || f(r)) {
237
+ d = r;
238
+ continue;
239
+ }
240
+ let i = m(c[e + 1]) ? [] : {};
241
+ u(d, n.slot, i), d = i;
242
+ }
243
+ let h = l(d, c[c.length - 1]);
244
+ if (p(h)) return s;
245
+ let g = h.found ? h.value : [];
246
+ if (h.found || u(d, h.slot, g), o(g)) return v(g) || g.push(...a), s;
247
+ if (f(g) || _(g) && !v(g)) {
248
+ let e = C(g);
249
+ for (let t of a) f(g) ? g.set(e++, t) : i(g, String(e++), t);
250
+ return s;
251
+ }
252
+ throw new e(n(g, r));
290
253
  }
291
- function pn(n, e = "", u = 1 / 0) {
292
- return x(n) ? R(n, e, u) : h(n) ? W(n, e, u) : W(
293
- p(n) ? [] : [n],
294
- e,
295
- u
296
- );
254
+ /* @__NO_SIDE_EFFECTS__ */
255
+ function F(e, t = "", n = Infinity) {
256
+ return h(e) ? /* @__PURE__ */ I(e, t, n) : o(e) ? /* @__PURE__ */ L(e, t, n) : /* @__PURE__ */ L(p(e) ? [] : [e], t, n);
297
257
  }
298
- function R(n, e = "", u = 1 / 0) {
299
- if (!x(n))
300
- return {};
301
- const s = {}, t = (l, c, f) => {
302
- for (const [o, i] of P(l)) {
303
- const r = `${c}${String(o)}`;
304
- f < u && h(i) && i.length > 0 ? t(
305
- i,
306
- `${r}.`,
307
- f + 1
308
- ) : f < u && (N(i) && Object.keys(i).length > 0 || O(i) && P(i).length > 0) ? t(
309
- i,
310
- `${r}.`,
311
- f + 1
312
- ) : v(s, r, i);
313
- }
314
- };
315
- return t(n, e, 0), s;
258
+ /* @__NO_SIDE_EFFECTS__ */
259
+ function I(e, t = "", n = Infinity) {
260
+ if (!h(e)) return {};
261
+ let r = {}, a = (e, t, s) => {
262
+ for (let [c, l] of S(e)) {
263
+ let e = `${t}${String(c)}`;
264
+ s < n && o(l) && l.length > 0 || s < n && (_(l) && Object.keys(l).length > 0 || f(l) && S(l).length > 0) ? a(l, `${e}.`, s + 1) : i(r, e, l);
265
+ }
266
+ };
267
+ return a(e, t, 0), r;
316
268
  }
317
- function W(n, e = "", u = 1 / 0) {
318
- if (!h(n))
319
- return {};
320
- const s = n, t = {}, l = (c, f, o) => {
321
- for (let i = 0; i < c.length; i++) {
322
- const r = c[i], g = `${f}${i}`;
323
- if (o < u && h(r) && r.length > 0)
324
- l(r, `${g}.`, o + 1);
325
- else if (o < u && (N(r) && Object.keys(r).length > 0 || O(r) && P(r).length > 0))
326
- for (const [d, S] of Object.entries(
327
- R(
328
- r,
329
- `${g}.`,
330
- u - o - 1
331
- )
332
- ))
333
- v(
334
- t,
335
- d,
336
- S
337
- );
338
- else
339
- v(
340
- t,
341
- g,
342
- r
343
- );
344
- }
345
- };
346
- return l(s, e, 0), t;
269
+ /* @__NO_SIDE_EFFECTS__ */
270
+ function L(e, t = "", n = Infinity) {
271
+ if (!o(e)) return {};
272
+ let r = e, a = {}, s = (e, t, r) => {
273
+ for (let c = 0; c < e.length; c++) {
274
+ let l = e[c], u = `${t}${c}`;
275
+ if (r < n && o(l) && l.length > 0) s(l, `${u}.`, r + 1);
276
+ else if (r < n && (_(l) && Object.keys(l).length > 0 || f(l) && S(l).length > 0)) for (let [e, t] of Object.entries(/* @__PURE__ */ I(l, `${u}.`, n - r - 1))) i(a, e, t);
277
+ else i(a, u, l);
278
+ }
279
+ };
280
+ return s(r, t, 0), a;
347
281
  }
348
- function dn(n) {
349
- return x(n) ? en(n) : on(n);
282
+ /* @__NO_SIDE_EFFECTS__ */
283
+ function R(e) {
284
+ return h(e) ? /* @__PURE__ */ V(e) : /* @__PURE__ */ W(e);
350
285
  }
351
- function tn(n, e) {
352
- const u = [...e].sort(
353
- (s, t) => t.split(".").length - s.split(".").length
354
- );
355
- for (const s of u) {
356
- const t = s.split("."), l = t[t.length - 1], c = t.slice(0, -1), f = c.length === 0 ? n : C(n, c.join("."));
357
- if (!x(f))
358
- continue;
359
- const o = f[l];
360
- if (!x(o))
361
- continue;
362
- const i = Object.keys(o);
363
- i.length > 0 && i.every((g, d) => g === String(d)) && v(
364
- f,
365
- l,
366
- i.map((g) => o[g])
367
- );
368
- }
286
+ function z(e, t, n) {
287
+ let r = /* @__PURE__ */ G(e, t);
288
+ if (!(o(r) || f(r) || _(r)) || n.has(r)) return r;
289
+ let a = o(r) ? r.slice() : f(r) ? new Map(r) : { ...r };
290
+ return f(e) ? E(e, t, a) : i(e, t, a), n.add(a), a;
369
291
  }
370
- function en(n) {
371
- const e = {}, u = /* @__PURE__ */ new Set();
372
- for (const [s, t] of P(n)) {
373
- const l = fn(e, s, t);
374
- for (const [f, o] of Object.entries(l))
375
- v(e, f, o);
376
- const c = s.split(".");
377
- for (let f = 1; f < c.length; f++)
378
- u.add(c.slice(0, f).join("."));
379
- }
380
- return tn(
381
- e,
382
- u
383
- ), e;
292
+ function B(e, t) {
293
+ let n = new WeakSet([e]), r = [...t].sort((e, t) => t.split(".").length - e.split(".").length);
294
+ for (let t of r) {
295
+ let r = t.split("."), a = r[r.length - 1], o = e;
296
+ for (let e of r.slice(0, -1)) if (o = z(o, e, n), !n.has(o)) break;
297
+ if (!h(o) || !n.has(o)) continue;
298
+ let s = o[a];
299
+ if (!h(s)) continue;
300
+ let c = Object.keys(s);
301
+ c.length > 0 && c.every((e, t) => e === String(t)) && i(o, a, c.map((e) => s[e]));
302
+ }
384
303
  }
385
- const rn = 2 ** 24 - 2;
386
- function sn(n) {
387
- return D(n) && Number(n) <= rn;
304
+ /* @__NO_SIDE_EFFECTS__ */
305
+ function V(e) {
306
+ let t = {}, n = /* @__PURE__ */ new Set();
307
+ for (let [r, a] of S(e)) {
308
+ let e = /* @__PURE__ */ Z(t, r, a);
309
+ for (let [n, r] of Object.entries(e)) i(t, n, r);
310
+ let o = r.split(".");
311
+ for (let e = 1; e < o.length; e++) n.add(o.slice(0, e).join("."));
312
+ }
313
+ return B(t, n), t;
388
314
  }
389
- function on(n) {
390
- const e = [];
391
- for (const [u, s] of P(n ?? {})) {
392
- if (u.length === 0)
393
- continue;
394
- const t = u.split(".");
395
- if (t.some((c) => !sn(c)))
396
- continue;
397
- let l = e;
398
- for (let c = 0; c < t.length; c++) {
399
- const f = Number(t[c]);
400
- if (c === t.length - 1)
401
- l[f] = s;
402
- else {
403
- const i = l[f];
404
- if (p(i) || a(i)) {
405
- const r = [];
406
- l[f] = r, l = r;
407
- } else if (h(i))
408
- l = i;
409
- else
410
- break;
411
- }
412
- }
413
- }
414
- return e;
315
+ var H = 2 ** 24 - 2;
316
+ /* @__NO_SIDE_EFFECTS__ */
317
+ function U(e) {
318
+ return d(e) && Number(e) <= H;
415
319
  }
416
- function C(n, e) {
417
- if (p(n) || a(n) || !L(n))
418
- return;
419
- const s = String(e).split(".");
420
- let t = n;
421
- for (const l of s) {
422
- if (p(t) || a(t) || !L(t))
423
- return;
424
- if (h(t)) {
425
- const c = b(l);
426
- if (!m(c) || !Object.hasOwn(t, c))
427
- return;
428
- t = t[c];
429
- } else if (O(t)) {
430
- const c = K(t, l);
431
- if (!c.found)
432
- return;
433
- t = c.value;
434
- } else {
435
- if (!Object.hasOwn(t, l))
436
- return;
437
- t = t[l];
438
- }
439
- }
440
- return t;
320
+ /* @__NO_SIDE_EFFECTS__ */
321
+ function W(e) {
322
+ let t = [], n = new WeakSet([t]);
323
+ for (let [r, i] of S(e ?? {})) {
324
+ if (r.length === 0) continue;
325
+ let e = r.split(".");
326
+ if (e.some((e) => !/* @__PURE__ */ U(e))) continue;
327
+ let a = t;
328
+ for (let t = 0; t < e.length; t++) {
329
+ let r = Number(e[t]);
330
+ if (t === e.length - 1) a[r] = i;
331
+ else {
332
+ let e = a[r];
333
+ if (p(e) || b(e)) {
334
+ let e = [];
335
+ a[r] = e, n.add(e), a = e;
336
+ } else if (o(e)) {
337
+ let t = n.has(e) ? e : e.slice();
338
+ a[r] = t, n.add(t), a = t;
339
+ } else break;
340
+ }
341
+ }
342
+ }
343
+ return t;
441
344
  }
442
- function On(n, e, u = null) {
443
- const s = () => J(u) ? u() : u;
444
- if (p(e))
445
- return n;
446
- if (m(e)) {
447
- if (!h(n))
448
- return s();
449
- const o = F(n), { found: i, value: r } = U(o, e);
450
- return i ? r : s();
451
- }
452
- const t = String(e);
453
- if (!t.includes(".")) {
454
- if (!h(n))
455
- return s();
456
- const o = F(n), { found: i, value: r } = U(o, e);
457
- return i ? r : s();
458
- }
459
- if (t.split(".").every((o) => {
460
- const i = b(o);
461
- return m(i) && i >= 0;
462
- })) {
463
- if (!h(n))
464
- return s();
465
- const o = F(n), { found: i, value: r } = U(o, e);
466
- return i ? r : s();
467
- }
468
- const f = C(n, t);
469
- return a(f) ? s() : f;
345
+ /* @__NO_SIDE_EFFECTS__ */
346
+ function G(e, t) {
347
+ if (p(e) || b(e) || !g(e)) return;
348
+ let n = String(t).split("."), r = e;
349
+ for (let e of n) {
350
+ if (p(r) || b(r) || !g(r)) return;
351
+ if (o(r)) {
352
+ let t = w(e);
353
+ if (!m(t) || !Object.hasOwn(r, t)) return;
354
+ r = r[t];
355
+ } else if (f(r)) {
356
+ let t = T(r, e);
357
+ if (!t.found) return;
358
+ r = t.value;
359
+ } else {
360
+ if (!Object.hasOwn(r, e)) return;
361
+ r = r[e];
362
+ }
363
+ }
364
+ return r;
470
365
  }
471
- function $(n) {
472
- return h(n) || N(n) || O(n);
366
+ /* @__NO_SIDE_EFFECTS__ */
367
+ function K(e, t, n = null) {
368
+ let i = () => c(n) ? n() : n;
369
+ if (p(t)) return e;
370
+ if (m(t)) {
371
+ if (!o(e)) return i();
372
+ let { found: n, value: a } = /* @__PURE__ */ k(r(e), t);
373
+ return n ? a : i();
374
+ }
375
+ let a = String(t);
376
+ if (!a.includes(".") || a.split(".").every((e) => {
377
+ let t = w(e);
378
+ return m(t) && t >= 0;
379
+ })) {
380
+ if (!o(e)) return i();
381
+ let { found: n, value: a } = /* @__PURE__ */ k(r(e), t);
382
+ return n ? a : i();
383
+ }
384
+ let s = /* @__PURE__ */ G(e, a);
385
+ return b(s) ? i() : s;
473
386
  }
474
- function q(n, e, u) {
475
- if (M(n))
476
- return n;
477
- if (p(e) || a(e))
478
- return n.length = 0, h(u) ? n.push(...u) : n.push(u), n;
479
- if (m(e)) {
480
- if (I(e) && e >= 0) {
481
- for (; n.length <= e; )
482
- n.push(void 0);
483
- n[e] = u;
484
- }
485
- return n;
486
- }
487
- const s = e.toString().split(".").map(b);
488
- let t = n;
489
- const l = s[0];
490
- !(m(l) && l >= 0) && t.length === 0 && (t.push({}), t = t[0]);
491
- for (let f = 0; f < s.length - 1; f++) {
492
- const o = s[f], i = s[f + 1];
493
- if (m(o) && o >= 0 && h(t)) {
494
- for (; t.length <= o; )
495
- t.push(void 0);
496
- const r = t[o];
497
- $(r) || (t[o] = m(i) ? [] : {}), t = t[o];
498
- } else if (O(t)) {
499
- const r = String(o);
500
- let g = K(t, r).value;
501
- $(g) || (g = m(i) ? [] : {}, A(t, r, g)), t = g;
502
- } else {
503
- const r = t, g = String(o), d = T(g), S = d && !Object.hasOwn(r, g) ? void 0 : r[g];
504
- $(S) ? d && v(
505
- r,
506
- g,
507
- h(S) ? [...S] : O(S) ? new Map(S) : {
508
- ...S
509
- }
510
- ) : v(
511
- r,
512
- g,
513
- m(i) ? [] : {}
514
- ), t = r[g];
515
- }
516
- if (M(t))
517
- return n;
518
- }
519
- const c = s[s.length - 1];
520
- if (m(c) && c >= 0 && h(t)) {
521
- for (; t.length <= c; )
522
- t.push(void 0);
523
- t[c] = u;
524
- } else O(t) ? A(t, String(c), u) : !p(t) && L(t) && v(
525
- t,
526
- String(c),
527
- u
528
- );
529
- return n;
387
+ function q(e) {
388
+ return o(e) || _(e) || f(e);
530
389
  }
531
- function Sn(n, e, ...u) {
532
- if (M(n))
533
- return n;
534
- if (p(e) || a(e))
535
- return h(n) ? (n.push(...u), n) : [...u];
536
- if (!h(n)) {
537
- const l = [];
538
- return q(l, e, u.length === 1 ? u[0] : u), l;
539
- }
540
- const s = e.toString().split(".");
541
- if (s.length === 1) {
542
- const l = b(s[0]);
543
- return m(l) && l >= 0 && n.push(...u), n;
544
- }
545
- let t = n;
546
- for (let l = 0; l < s.length - 1; l++) {
547
- const c = s[l];
548
- if (!c) continue;
549
- const f = b(c);
550
- if (m(f) && f >= 0 && h(t)) {
551
- for (; t.length <= f; )
552
- t.push(void 0);
553
- (p(t[f]) || !x(t[f])) && (t[f] = []), t = t[f];
554
- } else if (!p(t) && x(t)) {
555
- const o = t, i = T(c), r = i && !Object.hasOwn(o, c) ? void 0 : o[c];
556
- p(r) || !x(r) ? v(o, c, []) : i && v(o, c, {
557
- ...r
558
- }), t = o[c];
559
- } else
560
- return n;
561
- }
562
- return h(t) && t.push(...u), n;
390
+ function J(e, t, n) {
391
+ if (v(e)) return e;
392
+ if (p(t) || b(t)) return e.length = 0, o(n) ? e.push(...n) : e.push(n), e;
393
+ if (m(t)) {
394
+ if (u(t) && t >= 0) {
395
+ for (; e.length <= t;) e.push(void 0);
396
+ e[t] = n;
397
+ }
398
+ return e;
399
+ }
400
+ let r = t.toString().split(".").map(w), a = e, s = r[0];
401
+ !(m(s) && s >= 0) && a.length === 0 && (a.push({}), a = a[0]);
402
+ for (let t = 0; t < r.length - 1; t++) {
403
+ let n = r[t], s = r[t + 1];
404
+ if (m(n) && n >= 0 && o(a)) {
405
+ for (; a.length <= n;) a.push(void 0);
406
+ let e = a[n];
407
+ q(e) || (a[n] = m(s) ? [] : {}), a = a[n];
408
+ } else if (f(a)) {
409
+ let e = String(n), t = T(a, e).value;
410
+ q(t) || (t = m(s) ? [] : {}, E(a, e, t)), a = t;
411
+ } else {
412
+ let e = a, t = String(n), r = x(t), c = r && !Object.hasOwn(e, t) ? void 0 : e[t];
413
+ q(c) ? r && i(e, t, o(c) ? [...c] : f(c) ? new Map(c) : { ...c }) : i(e, t, m(s) ? [] : {}), a = e[t];
414
+ }
415
+ if (v(a)) return e;
416
+ }
417
+ let c = r[r.length - 1];
418
+ if (m(c) && c >= 0 && o(a)) {
419
+ for (; a.length <= c;) a.push(void 0);
420
+ a[c] = n;
421
+ } else f(a) ? E(a, String(c), n) : !p(a) && g(a) && i(a, String(c), n);
422
+ return e;
563
423
  }
564
- function mn(n, e, u) {
565
- if (p(e) || a(e))
566
- return u;
567
- if (!h(n))
568
- return [];
569
- const s = (l) => {
570
- if (p(l) || a(l) || !L(l))
571
- return l;
572
- if (h(l))
573
- return l.map(s);
574
- if (O(l))
575
- return new Map(
576
- [...l].map(([f, o]) => [
577
- f,
578
- s(o)
579
- ])
580
- );
581
- if (!N(l))
582
- return l;
583
- const c = {};
584
- for (const [f, o] of Object.entries(l))
585
- v(c, f, s(o));
586
- return c;
587
- }, t = s(n);
588
- return q(t, e, u);
424
+ function Y(e, t, ...n) {
425
+ if (v(e)) return e;
426
+ if (p(t) || b(t)) return o(e) ? (e.push(...n), e) : [...n];
427
+ if (!o(e)) {
428
+ let e = [];
429
+ return J(e, t, n.length === 1 ? n[0] : n), e;
430
+ }
431
+ let r = t.toString().split(".");
432
+ if (r.length === 1) {
433
+ let t = w(r[0]);
434
+ return m(t) && t >= 0 && e.push(...n), e;
435
+ }
436
+ let a = e;
437
+ for (let t = 0; t < r.length - 1; t++) {
438
+ let n = r[t];
439
+ if (!n) continue;
440
+ let s = w(n);
441
+ if (m(s) && s >= 0 && o(a)) {
442
+ for (; a.length <= s;) a.push(void 0);
443
+ (p(a[s]) || !h(a[s])) && (a[s] = []), a = a[s];
444
+ } else if (!p(a) && h(a)) {
445
+ let e = a, t = x(n), r = t && !Object.hasOwn(e, n) ? void 0 : e[n];
446
+ p(r) || !h(r) ? i(e, n, []) : t && i(e, n, { ...r }), a = e[n];
447
+ } else return e;
448
+ }
449
+ return o(a) && a.push(...n), e;
589
450
  }
590
- function xn(n, e) {
591
- if (p(e) || a(e))
592
- return p(n) || a(n) ? !1 : h(n) ? n.length > 0 : x(n) ? Object.keys(n).length > 0 : !0;
593
- if (m(e))
594
- return h(n) ? e >= 0 && e < n.length : x(n) && E(n, String(e)).found;
595
- if (!h(n) && !x(n))
596
- return !1;
597
- const u = e.toString();
598
- if (x(n)) {
599
- if (E(n, u).found)
600
- return !0;
601
- if (!u.includes("."))
602
- return !1;
603
- }
604
- const s = C(n, u);
605
- return !a(s);
451
+ /* @__NO_SIDE_EFFECTS__ */
452
+ function X(e, t, n) {
453
+ if (p(t) || b(t)) return n;
454
+ if (!o(e)) return [];
455
+ let r = (e) => {
456
+ if (p(e) || b(e) || !g(e)) return e;
457
+ if (o(e)) return e.map(r);
458
+ if (f(e)) return new Map([...e].map(([e, t]) => [e, r(t)]));
459
+ if (!_(e)) return e;
460
+ let t = {};
461
+ for (let [n, a] of Object.entries(e)) i(t, n, r(a));
462
+ return t;
463
+ };
464
+ return J(r(e), t, n);
606
465
  }
607
- function an(n, e, u = null) {
608
- const s = () => J(u) ? u() : u;
609
- if (p(e))
610
- return n;
611
- if (!x(n))
612
- return s();
613
- const t = String(e), l = E(n, t);
614
- if (l.found)
615
- return a(l.value) ? s() : l.value;
616
- if (!t.includes("."))
617
- return s();
618
- const c = C(n, t);
619
- return a(c) ? s() : c;
466
+ /* @__NO_SIDE_EFFECTS__ */
467
+ function te(e, t) {
468
+ if (p(t) || b(t)) return p(e) || b(e) ? !1 : o(e) ? e.length > 0 : !h(e) || Object.keys(e).length > 0;
469
+ if (m(t)) return o(e) ? t >= 0 && t < e.length : h(e) && $(e, String(t)).found;
470
+ if (!o(e) && !h(e)) return !1;
471
+ let n = t.toString();
472
+ if (h(e)) {
473
+ if ($(e, n).found) return !0;
474
+ if (!n.includes(".")) return !1;
475
+ }
476
+ return !b(/* @__PURE__ */ G(e, n));
620
477
  }
621
- function fn(n, e, u) {
622
- if (p(e))
623
- return u;
624
- x(n) || (n = {});
625
- const s = { ...n }, t = String(e);
626
- if (!t.includes("."))
627
- return v(s, t, u), s;
628
- const l = t.split(".");
629
- let c = s;
630
- const f = l.length - 1;
631
- for (const [o, i] of l.entries()) {
632
- if (o === f) {
633
- O(c) ? A(c, i, u) : v(c, i, u);
634
- break;
635
- }
636
- const r = O(c) ? K(c, i).value : T(i) && !Object.hasOwn(c, i) ? void 0 : c[i], g = $(r) ? h(r) ? [...r] : O(r) ? new Map(r) : { ...r } : {};
637
- O(c) ? A(c, i, g) : v(c, i, g), c = g;
638
- }
639
- return s;
478
+ /* @__NO_SIDE_EFFECTS__ */
479
+ function ne(e, t, n = null) {
480
+ let r = () => c(n) ? n() : n;
481
+ if (p(t)) return e;
482
+ if (!h(e)) return r();
483
+ let i = String(t), a = $(e, i);
484
+ if (a.found) return b(a.value) ? r() : a.value;
485
+ if (!i.includes(".")) return r();
486
+ let o = /* @__PURE__ */ G(e, i);
487
+ return b(o) ? r() : o;
640
488
  }
641
- function wn(n, e) {
642
- if (!x(n) || p(e))
643
- return !1;
644
- const u = String(e);
645
- if (E(n, u).found)
646
- return !0;
647
- if (!u.includes("."))
648
- return !1;
649
- const s = C(n, u);
650
- return !a(s);
489
+ /* @__NO_SIDE_EFFECTS__ */
490
+ function Z(e, t, n) {
491
+ if (p(t)) return n;
492
+ h(e) || (e = {});
493
+ let r = { ...e }, a = String(t);
494
+ if (!a.includes(".")) return i(r, a, n), r;
495
+ let s = a.split("."), c = r, l = s.length - 1;
496
+ for (let [e, t] of s.entries()) {
497
+ if (e === l) {
498
+ f(c) ? E(c, t, n) : i(c, t, n);
499
+ break;
500
+ }
501
+ let r = f(c) ? T(c, t).value : x(t) && !Object.hasOwn(c, t) ? void 0 : c[t], a = q(r) ? o(r) ? [...r] : f(r) ? new Map(r) : { ...r } : {};
502
+ f(c) ? E(c, t, a) : i(c, t, a), c = a;
503
+ }
504
+ return r;
651
505
  }
652
- function z(n) {
653
- return p(n) || a(n) || X(n) ? y(n) : String(n);
506
+ /* @__NO_SIDE_EFFECTS__ */
507
+ function re(e, t) {
508
+ if (!h(e) || p(t)) return !1;
509
+ let n = String(t);
510
+ return $(e, n).found ? !0 : n.includes(".") ? !b(/* @__PURE__ */ G(e, n)) : !1;
654
511
  }
655
- function E(n, e) {
656
- return O(n) ? K(n, e) : Object.hasOwn(n, e) ? { found: !0, value: n[e] } : { found: !1 };
512
+ function Q(e) {
513
+ return p(e) || b(e) || s(e) ? ee(e) : String(e);
657
514
  }
658
- export {
659
- rn as MAX_UNDOT_INDEX,
660
- pn as dotFlatten,
661
- W as dotFlattenArray,
662
- R as dotFlattenObject,
663
- ln as forgetKeys,
664
- nn as forgetKeysArray,
665
- k as forgetKeysObject,
666
- On as getMixedValue,
667
- C as getNestedValue,
668
- an as getObjectValue,
669
- U as getRaw,
670
- xn as hasMixed,
671
- wn as hasObjectKey,
672
- cn as hasPath,
673
- sn as isCanonicalUndotIndex,
674
- V as parseSegments,
675
- Sn as pushMixed,
676
- hn as pushWithPath,
677
- gn as setImmutable,
678
- q as setMixed,
679
- mn as setMixedImmutable,
680
- fn as setObjectValue,
681
- dn as undotExpand,
682
- on as undotExpandArray,
683
- en as undotExpandObject
684
- };
515
+ function $(e, t) {
516
+ return f(e) ? T(e, t) : Object.hasOwn(e, t) ? {
517
+ found: !0,
518
+ value: e[t]
519
+ } : { found: !1 };
520
+ }
521
+ export { H as MAX_UNDOT_INDEX, F as dotFlatten, L as dotFlattenArray, I as dotFlattenObject, A as forgetKeys, M as forgetKeysArray, j as forgetKeysObject, K as getMixedValue, G as getNestedValue, ne as getObjectValue, k as getRaw, te as hasMixed, re as hasObjectKey, O as hasPath, U as isCanonicalUndotIndex, D as parseSegments, Y as pushMixed, P as pushWithPath, N as setImmutable, J as setMixed, X as setMixedImmutable, Z as setObjectValue, R as undotExpand, W as undotExpandArray, V as undotExpandObject };