@tolki/path 1.0.0 → 1.0.1

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,495 @@
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
+ function D(e) {
4
+ if (p(e) || b(e)) return [];
5
+ if (!m(e) && Number.isNaN(e)) return null;
6
+ if (m(e)) return u(e) && e >= 0 ? [e] : null;
7
+ let t = String(e);
8
+ if (t.length === 0) return [];
9
+ let n = t.split("."), r = [];
10
+ for (let e of n) {
11
+ if (e.length === 0) return null;
12
+ let t = w(e);
13
+ r.push(m(t) && t >= 0 ? t : e);
14
+ }
15
+ return r;
20
16
  }
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;
17
+ function O(e, t) {
18
+ if (p(t)) return !1;
19
+ if (m(t)) return o(e) ? u(t) && t >= 0 && t < e.length : !p(e) && h(e) && $(e, String(t)).found;
20
+ let n = D(t);
21
+ if (!n || n.length === 0) return !1;
22
+ let r = e;
23
+ for (let e of n) if (o(r)) {
24
+ if (!m(e) || e >= r.length) return !1;
25
+ r = r[e];
26
+ } else if (f(r)) {
27
+ let t = T(r, e);
28
+ if (!t.found) return !1;
29
+ r = t.value;
30
+ } else if (h(r) && Object.hasOwn(r, String(e))) r = r[String(e)];
31
+ else return !1;
32
+ return !0;
45
33
  }
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 };
34
+ function k(e, t) {
35
+ if (p(t) || b(t)) return {
36
+ found: !0,
37
+ value: e
38
+ };
39
+ if (m(t)) return o(e) ? !u(t) || t < 0 || t >= e.length ? { found: !1 } : {
40
+ found: !0,
41
+ value: e[t]
42
+ } : !p(e) && h(e) ? $(e, String(t)) : { found: !1 };
43
+ let n = D(t);
44
+ if (!n || n.length === 0) return { found: !1 };
45
+ let r = e;
46
+ for (let e of n) if (o(r)) {
47
+ if (!m(e) || e >= r.length) return { found: !1 };
48
+ r = r[e];
49
+ } else if (f(r)) {
50
+ let t = T(r, e);
51
+ if (!t.found) return { found: !1 };
52
+ r = t.value;
53
+ } else if (h(r) && Object.hasOwn(r, String(e))) r = r[String(e)];
54
+ else return { found: !1 };
55
+ return {
56
+ found: !0,
57
+ value: r
58
+ };
70
59
  }
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);
60
+ function A(e, n) {
61
+ if ((o(n) ? n : [n]).some(l)) throw t();
62
+ return h(e) ? j(e, n) : M(e, n);
75
63
  }
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;
64
+ function j(e, t) {
65
+ let n = p(t) || b(t) ? [] : o(t) ? t : [t], r = { ...e }, i = (e, t) => {
66
+ let n = w(e);
67
+ return !u(n) || n < 0 || n >= t.length ? null : n;
68
+ }, c = (e) => {
69
+ if (o(e)) return e.slice();
70
+ if (f(e)) return new Map(e);
71
+ if (h(e)) {
72
+ let t = Object.getPrototypeOf(e);
73
+ if (t === Object.prototype || p(t)) return { ...e };
74
+ }
75
+ return null;
76
+ }, l = (e, t) => {
77
+ if (Object.hasOwn(r, e)) {
78
+ delete r[t];
79
+ return;
80
+ }
81
+ let n = e.split("."), s = r;
82
+ for (; n.length > 1;) {
83
+ let e = n.shift();
84
+ if (o(s)) {
85
+ let t = i(e, s);
86
+ if (p(t)) return;
87
+ let n = c(s[t]);
88
+ if (p(n)) return;
89
+ s[t] = n, s = n;
90
+ continue;
91
+ }
92
+ if (f(s)) {
93
+ let t = T(s, e), n = t.found ? c(t.value) : null;
94
+ if (p(n)) return;
95
+ E(s, e, n), s = n;
96
+ continue;
97
+ }
98
+ if (!Object.hasOwn(s, e)) return;
99
+ let t = c(s[e]);
100
+ if (p(t)) return;
101
+ s[e] = t, s = t;
102
+ }
103
+ let l = n.shift();
104
+ if (o(s)) {
105
+ let e = i(l, s);
106
+ p(e) || s.splice(e, 1);
107
+ } else f(s) ? a(s, l) : delete s[l];
108
+ };
109
+ for (let e of n) {
110
+ let t = Q(e);
111
+ l(t, s(e) ? String(w(e)) : t);
112
+ }
113
+ return r;
141
114
  }
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;
115
+ function M(e, t) {
116
+ let n = e.slice();
117
+ if (p(t)) return n;
118
+ let r = (e) => {
119
+ let t = n;
120
+ for (let n of e) {
121
+ let e;
122
+ if (o(t)) e = m(n) && n >= 0 ? t[n] : void 0;
123
+ else if (f(t)) {
124
+ let r = T(t, n);
125
+ e = r.found ? r.value : void 0;
126
+ } else Object.hasOwn(t, n) && (e = t[n]);
127
+ if (!o(e) && !_(e) && !f(e) || v(e)) return null;
128
+ let r = o(e) ? e.slice() : f(e) ? new Map(e) : { ...e };
129
+ f(t) ? E(t, n, r) : i(t, n, r), t = r;
130
+ }
131
+ return t;
132
+ }, s = /* @__PURE__ */ new Map();
133
+ for (let e of o(t) ? t : [t]) {
134
+ let t = u(e) ? [e] : Q(e).split(".").map(w), n = t.slice(0, -1), r = JSON.stringify(n), i = s.get(r) ?? {
135
+ parent: n,
136
+ leaves: /* @__PURE__ */ new Set()
137
+ };
138
+ i.leaves.add(t[n.length]), s.set(r, i);
139
+ }
140
+ let c = [...s.values()].sort((e, t) => t.parent.length - e.parent.length);
141
+ for (let { parent: e, leaves: t } of c) {
142
+ let n = r(e);
143
+ if (o(n)) {
144
+ let e = [...t].filter((e) => m(e) && e >= 0).sort((e, t) => t - e);
145
+ for (let t of e) n.splice(t, 1);
146
+ } else if (f(n)) for (let e of t) a(n, e);
147
+ else if (!p(n)) for (let e of t) delete n[e];
148
+ }
149
+ return n;
188
150
  }
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;
151
+ function N(e, t, n) {
152
+ if (p(t)) return n;
153
+ if (!o(e)) return [];
154
+ let r = e.slice(), i = (e, t) => e > t ? t : e;
155
+ if (m(t) || y(t) && t.indexOf(".") === -1) {
156
+ let e = m(t) ? t : w(t);
157
+ if (!u(e) || e < 0) return r;
158
+ let a = i(e, r.length), o = r.slice();
159
+ return a === o.length ? o.push(n) : o[a] = n, o;
160
+ }
161
+ let a = String(t).split("."), s = [];
162
+ for (let e of a) {
163
+ let t = w(e);
164
+ if (!u(t) || t < 0) return r;
165
+ s.push(t);
166
+ }
167
+ let c = r.slice(), l = c;
168
+ for (let e = 0; e < s.length; e++) {
169
+ let t = s[e], a = e === s.length - 1, c = i(t, l.length);
170
+ if (a) {
171
+ c === l.length ? l.push(n) : l[c] = n;
172
+ break;
173
+ }
174
+ if (c === l.length) {
175
+ let e = [];
176
+ l.push(e), l = e;
177
+ continue;
178
+ }
179
+ let u = l[c];
180
+ if (p(u)) {
181
+ let e = [];
182
+ l[c] = e, l = e;
183
+ } else if (o(u)) {
184
+ let e = u.slice();
185
+ l[c] = e, l = e;
186
+ } else return r;
187
+ }
188
+ return c;
236
189
  }
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));
190
+ function P(t, r, ...a) {
191
+ let s = o(t) && !v(t) ? t : [];
192
+ if (p(r) || b(r)) return s.push(...a), s;
193
+ let c = D(r);
194
+ if (!c || c.length === 0) return s;
195
+ let l = (e, t) => {
196
+ if (o(e)) {
197
+ if (!m(t)) return null;
198
+ let n = Math.min(t, e.length);
199
+ return n < e.length ? {
200
+ slot: n,
201
+ found: !0,
202
+ value: e[n]
203
+ } : {
204
+ slot: n,
205
+ found: !1
206
+ };
207
+ }
208
+ if (f(e)) return {
209
+ slot: t,
210
+ ...T(e, t)
211
+ };
212
+ let n = String(t);
213
+ return Object.hasOwn(e, n) ? {
214
+ slot: n,
215
+ found: !0,
216
+ value: e[n]
217
+ } : {
218
+ slot: n,
219
+ found: !1
220
+ };
221
+ }, u = (e, t, n) => {
222
+ f(e) ? E(e, t, n) : i(e, t, n);
223
+ }, d = s;
224
+ for (let [e, t] of c.slice(0, -1).entries()) {
225
+ let n = l(d, t);
226
+ if (p(n)) return s;
227
+ let r = n.value;
228
+ if (v(r)) return s;
229
+ if (o(r) || _(r) || f(r)) {
230
+ d = r;
231
+ continue;
232
+ }
233
+ let i = m(c[e + 1]) ? [] : {};
234
+ u(d, n.slot, i), d = i;
235
+ }
236
+ let h = l(d, c[c.length - 1]);
237
+ if (p(h)) return s;
238
+ let g = h.found ? h.value : [];
239
+ if (h.found || u(d, h.slot, g), o(g)) return v(g) || g.push(...a), s;
240
+ if (f(g) || _(g) && !v(g)) {
241
+ let e = C(g);
242
+ for (let t of a) f(g) ? g.set(e++, t) : i(g, String(e++), t);
243
+ return s;
244
+ }
245
+ throw new e(n(g, r));
290
246
  }
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
- );
247
+ function F(e, t = "", n = Infinity) {
248
+ return h(e) ? I(e, t, n) : o(e) ? L(e, t, n) : L(p(e) ? [] : [e], t, n);
297
249
  }
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;
250
+ function I(e, t = "", n = Infinity) {
251
+ if (!h(e)) return {};
252
+ let r = {}, a = (e, t, s) => {
253
+ for (let [c, l] of S(e)) {
254
+ let e = `${t}${String(c)}`;
255
+ 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);
256
+ }
257
+ };
258
+ return a(e, t, 0), r;
316
259
  }
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;
260
+ function L(e, t = "", n = Infinity) {
261
+ if (!o(e)) return {};
262
+ let r = e, a = {}, s = (e, t, r) => {
263
+ for (let c = 0; c < e.length; c++) {
264
+ let l = e[c], u = `${t}${c}`;
265
+ if (r < n && o(l) && l.length > 0) s(l, `${u}.`, r + 1);
266
+ else if (r < n && (_(l) && Object.keys(l).length > 0 || f(l) && S(l).length > 0)) for (let [e, t] of Object.entries(I(l, `${u}.`, n - r - 1))) i(a, e, t);
267
+ else i(a, u, l);
268
+ }
269
+ };
270
+ return s(r, t, 0), a;
347
271
  }
348
- function dn(n) {
349
- return x(n) ? en(n) : on(n);
272
+ function R(e) {
273
+ return h(e) ? B(e) : U(e);
350
274
  }
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
- }
275
+ function z(e, t) {
276
+ let n = [...t].sort((e, t) => t.split(".").length - e.split(".").length);
277
+ for (let t of n) {
278
+ let n = t.split("."), r = n[n.length - 1], a = n.slice(0, -1), o = a.length === 0 ? e : W(e, a.join("."));
279
+ if (!h(o)) continue;
280
+ let s = o[r];
281
+ if (!h(s)) continue;
282
+ let c = Object.keys(s);
283
+ c.length > 0 && c.every((e, t) => e === String(t)) && i(o, r, c.map((e) => s[e]));
284
+ }
369
285
  }
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;
286
+ function B(e) {
287
+ let t = {}, n = /* @__PURE__ */ new Set();
288
+ for (let [r, a] of S(e)) {
289
+ let e = Z(t, r, a);
290
+ for (let [n, r] of Object.entries(e)) i(t, n, r);
291
+ let o = r.split(".");
292
+ for (let e = 1; e < o.length; e++) n.add(o.slice(0, e).join("."));
293
+ }
294
+ return z(t, n), t;
384
295
  }
385
- const rn = 2 ** 24 - 2;
386
- function sn(n) {
387
- return D(n) && Number(n) <= rn;
296
+ var V = 2 ** 24 - 2;
297
+ function H(e) {
298
+ return d(e) && Number(e) <= V;
388
299
  }
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;
300
+ function U(e) {
301
+ let t = [];
302
+ for (let [n, r] of S(e ?? {})) {
303
+ if (n.length === 0) continue;
304
+ let e = n.split(".");
305
+ if (e.some((e) => !H(e))) continue;
306
+ let i = t;
307
+ for (let t = 0; t < e.length; t++) {
308
+ let n = Number(e[t]);
309
+ if (t === e.length - 1) i[n] = r;
310
+ else {
311
+ let e = i[n];
312
+ if (p(e) || b(e)) {
313
+ let e = [];
314
+ i[n] = e, i = e;
315
+ } else if (o(e)) i = e;
316
+ else break;
317
+ }
318
+ }
319
+ }
320
+ return t;
415
321
  }
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;
322
+ function W(e, t) {
323
+ if (p(e) || b(e) || !g(e)) return;
324
+ let n = String(t).split("."), r = e;
325
+ for (let e of n) {
326
+ if (p(r) || b(r) || !g(r)) return;
327
+ if (o(r)) {
328
+ let t = w(e);
329
+ if (!m(t) || !Object.hasOwn(r, t)) return;
330
+ r = r[t];
331
+ } else if (f(r)) {
332
+ let t = T(r, e);
333
+ if (!t.found) return;
334
+ r = t.value;
335
+ } else {
336
+ if (!Object.hasOwn(r, e)) return;
337
+ r = r[e];
338
+ }
339
+ }
340
+ return r;
441
341
  }
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;
342
+ function G(e, t, n = null) {
343
+ let i = () => c(n) ? n() : n;
344
+ if (p(t)) return e;
345
+ if (m(t)) {
346
+ if (!o(e)) return i();
347
+ let { found: n, value: a } = k(r(e), t);
348
+ return n ? a : i();
349
+ }
350
+ let a = String(t);
351
+ if (!a.includes(".") || a.split(".").every((e) => {
352
+ let t = w(e);
353
+ return m(t) && t >= 0;
354
+ })) {
355
+ if (!o(e)) return i();
356
+ let { found: n, value: a } = k(r(e), t);
357
+ return n ? a : i();
358
+ }
359
+ let s = W(e, a);
360
+ return b(s) ? i() : s;
470
361
  }
471
- function $(n) {
472
- return h(n) || N(n) || O(n);
362
+ function K(e) {
363
+ return o(e) || _(e) || f(e);
473
364
  }
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;
365
+ function q(e, t, n) {
366
+ if (v(e)) return e;
367
+ if (p(t) || b(t)) return e.length = 0, o(n) ? e.push(...n) : e.push(n), e;
368
+ if (m(t)) {
369
+ if (u(t) && t >= 0) {
370
+ for (; e.length <= t;) e.push(void 0);
371
+ e[t] = n;
372
+ }
373
+ return e;
374
+ }
375
+ let r = t.toString().split(".").map(w), a = e, s = r[0];
376
+ !(m(s) && s >= 0) && a.length === 0 && (a.push({}), a = a[0]);
377
+ for (let t = 0; t < r.length - 1; t++) {
378
+ let n = r[t], s = r[t + 1];
379
+ if (m(n) && n >= 0 && o(a)) {
380
+ for (; a.length <= n;) a.push(void 0);
381
+ let e = a[n];
382
+ K(e) || (a[n] = m(s) ? [] : {}), a = a[n];
383
+ } else if (f(a)) {
384
+ let e = String(n), t = T(a, e).value;
385
+ K(t) || (t = m(s) ? [] : {}, E(a, e, t)), a = t;
386
+ } else {
387
+ let e = a, t = String(n), r = x(t), c = r && !Object.hasOwn(e, t) ? void 0 : e[t];
388
+ K(c) ? r && i(e, t, o(c) ? [...c] : f(c) ? new Map(c) : { ...c }) : i(e, t, m(s) ? [] : {}), a = e[t];
389
+ }
390
+ if (v(a)) return e;
391
+ }
392
+ let c = r[r.length - 1];
393
+ if (m(c) && c >= 0 && o(a)) {
394
+ for (; a.length <= c;) a.push(void 0);
395
+ a[c] = n;
396
+ } else f(a) ? E(a, String(c), n) : !p(a) && g(a) && i(a, String(c), n);
397
+ return e;
530
398
  }
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;
399
+ function J(e, t, ...n) {
400
+ if (v(e)) return e;
401
+ if (p(t) || b(t)) return o(e) ? (e.push(...n), e) : [...n];
402
+ if (!o(e)) {
403
+ let e = [];
404
+ return q(e, t, n.length === 1 ? n[0] : n), e;
405
+ }
406
+ let r = t.toString().split(".");
407
+ if (r.length === 1) {
408
+ let t = w(r[0]);
409
+ return m(t) && t >= 0 && e.push(...n), e;
410
+ }
411
+ let a = e;
412
+ for (let t = 0; t < r.length - 1; t++) {
413
+ let n = r[t];
414
+ if (!n) continue;
415
+ let s = w(n);
416
+ if (m(s) && s >= 0 && o(a)) {
417
+ for (; a.length <= s;) a.push(void 0);
418
+ (p(a[s]) || !h(a[s])) && (a[s] = []), a = a[s];
419
+ } else if (!p(a) && h(a)) {
420
+ let e = a, t = x(n), r = t && !Object.hasOwn(e, n) ? void 0 : e[n];
421
+ p(r) || !h(r) ? i(e, n, []) : t && i(e, n, { ...r }), a = e[n];
422
+ } else return e;
423
+ }
424
+ return o(a) && a.push(...n), e;
563
425
  }
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);
426
+ function Y(e, t, n) {
427
+ if (p(t) || b(t)) return n;
428
+ if (!o(e)) return [];
429
+ let r = (e) => {
430
+ if (p(e) || b(e) || !g(e)) return e;
431
+ if (o(e)) return e.map(r);
432
+ if (f(e)) return new Map([...e].map(([e, t]) => [e, r(t)]));
433
+ if (!_(e)) return e;
434
+ let t = {};
435
+ for (let [n, a] of Object.entries(e)) i(t, n, r(a));
436
+ return t;
437
+ };
438
+ return q(r(e), t, n);
589
439
  }
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);
440
+ function X(e, t) {
441
+ if (p(t) || b(t)) return p(e) || b(e) ? !1 : o(e) ? e.length > 0 : !h(e) || Object.keys(e).length > 0;
442
+ if (m(t)) return o(e) ? t >= 0 && t < e.length : h(e) && $(e, String(t)).found;
443
+ if (!o(e) && !h(e)) return !1;
444
+ let n = t.toString();
445
+ if (h(e)) {
446
+ if ($(e, n).found) return !0;
447
+ if (!n.includes(".")) return !1;
448
+ }
449
+ let r = W(e, n);
450
+ return !b(r);
606
451
  }
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;
452
+ function te(e, t, n = null) {
453
+ let r = () => c(n) ? n() : n;
454
+ if (p(t)) return e;
455
+ if (!h(e)) return r();
456
+ let i = String(t), a = $(e, i);
457
+ if (a.found) return b(a.value) ? r() : a.value;
458
+ if (!i.includes(".")) return r();
459
+ let o = W(e, i);
460
+ return b(o) ? r() : o;
620
461
  }
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;
462
+ function Z(e, t, n) {
463
+ if (p(t)) return n;
464
+ h(e) || (e = {});
465
+ let r = { ...e }, a = String(t);
466
+ if (!a.includes(".")) return i(r, a, n), r;
467
+ let s = a.split("."), c = r, l = s.length - 1;
468
+ for (let [e, t] of s.entries()) {
469
+ if (e === l) {
470
+ f(c) ? E(c, t, n) : i(c, t, n);
471
+ break;
472
+ }
473
+ let r = f(c) ? T(c, t).value : x(t) && !Object.hasOwn(c, t) ? void 0 : c[t], a = K(r) ? o(r) ? [...r] : f(r) ? new Map(r) : { ...r } : {};
474
+ f(c) ? E(c, t, a) : i(c, t, a), c = a;
475
+ }
476
+ return r;
640
477
  }
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);
478
+ function ne(e, t) {
479
+ if (!h(e) || p(t)) return !1;
480
+ let n = String(t);
481
+ if ($(e, n).found) return !0;
482
+ if (!n.includes(".")) return !1;
483
+ let r = W(e, n);
484
+ return !b(r);
651
485
  }
652
- function z(n) {
653
- return p(n) || a(n) || X(n) ? y(n) : String(n);
486
+ function Q(e) {
487
+ return p(e) || b(e) || s(e) ? ee(e) : String(e);
654
488
  }
655
- function E(n, e) {
656
- return O(n) ? K(n, e) : Object.hasOwn(n, e) ? { found: !0, value: n[e] } : { found: !1 };
489
+ function $(e, t) {
490
+ return f(e) ? T(e, t) : Object.hasOwn(e, t) ? {
491
+ found: !0,
492
+ value: e[t]
493
+ } : { found: !1 };
657
494
  }
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
- };
495
+ export { V as MAX_UNDOT_INDEX, F as dotFlatten, L as dotFlattenArray, I as dotFlattenObject, A as forgetKeys, M as forgetKeysArray, j as forgetKeysObject, G as getMixedValue, W as getNestedValue, te as getObjectValue, k as getRaw, X as hasMixed, ne as hasObjectKey, O as hasPath, H as isCanonicalUndotIndex, D as parseSegments, J as pushMixed, P as pushWithPath, N as setImmutable, q as setMixed, Y as setMixedImmutable, Z as setObjectValue, R as undotExpand, U as undotExpandArray, B as undotExpandObject };