@fluixi/utils 1.0.0-alpha.83 → 1.0.0-alpha.84
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/index.cjs +2858 -1
- package/dist/index.mjs +2838 -1
- package/dist/lib/array/advanced.cjs +2227 -1
- package/dist/lib/array/advanced.mjs +2204 -1
- package/dist/lib/array/array.cjs +57 -1
- package/dist/lib/array/array.mjs +36 -1
- package/dist/lib/array/index.cjs +2344 -1
- package/dist/lib/array/index.mjs +2322 -1
- package/dist/lib/array/utils.cjs +103 -1
- package/dist/lib/array/utils.mjs +82 -1
- package/dist/lib/color/color.cjs +2190 -1
- package/dist/lib/color/color.mjs +2167 -1
- package/dist/lib/color/constants.cjs +380 -1
- package/dist/lib/color/constants.mjs +359 -1
- package/dist/lib/color/conversions.cjs +629 -1
- package/dist/lib/color/conversions.mjs +608 -1
- package/dist/lib/color/helpers.cjs +2534 -1
- package/dist/lib/color/helpers.mjs +2511 -1
- package/dist/lib/color/index.cjs +2641 -1
- package/dist/lib/color/index.mjs +2619 -1
- package/dist/lib/color/types.cjs +18 -1
- package/dist/lib/color/utils.cjs +962 -1
- package/dist/lib/color/utils.mjs +939 -1
- package/dist/lib/compare/comparators.cjs +171 -1
- package/dist/lib/compare/comparators.mjs +150 -1
- package/dist/lib/compare/index.cjs +172 -1
- package/dist/lib/compare/index.mjs +152 -1
- package/dist/lib/crypto/hash.cjs +83 -1
- package/dist/lib/crypto/hash.mjs +62 -1
- package/dist/lib/crypto/index.cjs +85 -1
- package/dist/lib/crypto/index.mjs +62 -1
- package/dist/lib/dom/events.cjs +40 -1
- package/dist/lib/dom/events.mjs +19 -1
- package/dist/lib/dom/index.cjs +78 -1
- package/dist/lib/dom/index.mjs +56 -1
- package/dist/lib/dom/utils.cjs +57 -1
- package/dist/lib/dom/utils.mjs +36 -1
- package/dist/lib/functions/functions.cjs +366 -1
- package/dist/lib/functions/functions.mjs +345 -1
- package/dist/lib/functions/index.cjs +369 -1
- package/dist/lib/functions/index.mjs +347 -1
- package/dist/lib/functions/types.cjs +18 -1
- package/dist/lib/helpers.cjs +78 -1
- package/dist/lib/helpers.mjs +59 -1
- package/dist/lib/index.cjs +2857 -1
- package/dist/lib/index.mjs +2836 -1
- package/dist/lib/maths/constants.cjs +70 -1
- package/dist/lib/maths/constants.mjs +50 -1
- package/dist/lib/maths/fn/advanced.cjs +231 -1
- package/dist/lib/maths/fn/advanced.mjs +208 -1
- package/dist/lib/maths/fn/basic.cjs +212 -1
- package/dist/lib/maths/fn/basic.mjs +191 -1
- package/dist/lib/maths/fn/complex.cjs +268 -1
- package/dist/lib/maths/fn/complex.mjs +247 -1
- package/dist/lib/maths/fn/index.cjs +877 -1
- package/dist/lib/maths/fn/index.mjs +855 -1
- package/dist/lib/maths/fn/trigo.cjs +179 -1
- package/dist/lib/maths/fn/trigo.mjs +156 -1
- package/dist/lib/maths/fn/vector.cjs +728 -1
- package/dist/lib/maths/fn/vector.mjs +707 -1
- package/dist/lib/maths/formatter.cjs +61 -1
- package/dist/lib/maths/formatter.mjs +40 -1
- package/dist/lib/maths/guards.cjs +164 -1
- package/dist/lib/maths/guards.mjs +144 -1
- package/dist/lib/maths/index.cjs +1152 -1
- package/dist/lib/maths/index.mjs +1130 -1
- package/dist/lib/maths/parser.cjs +75 -1
- package/dist/lib/maths/parser.mjs +54 -1
- package/dist/lib/maths/random.cjs +49 -1
- package/dist/lib/maths/random.mjs +28 -1
- package/dist/lib/maths/types/advanced.cjs +18 -1
- package/dist/lib/maths/types/basic.cjs +18 -1
- package/dist/lib/maths/types/index.cjs +19 -1
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -1
- package/dist/lib/maths/types/operations.cjs +18 -1
- package/dist/lib/object/clone.cjs +88 -1
- package/dist/lib/object/clone.mjs +65 -1
- package/dist/lib/object/diff.cjs +573 -1
- package/dist/lib/object/diff.mjs +550 -1
- package/dist/lib/object/getter-setter.cjs +2351 -1
- package/dist/lib/object/getter-setter.mjs +2330 -1
- package/dist/lib/object/index.cjs +3956 -6
- package/dist/lib/object/index.mjs +3936 -6
- package/dist/lib/object/merge.cjs +1029 -1
- package/dist/lib/object/merge.mjs +1006 -1
- package/dist/lib/object/object.cjs +280 -1
- package/dist/lib/object/object.mjs +257 -1
- package/dist/lib/object/omit.cjs +2022 -1
- package/dist/lib/object/omit.mjs +1999 -1
- package/dist/lib/object/reconcile.cjs +126 -1
- package/dist/lib/object/reconcile.mjs +105 -1
- package/dist/lib/object/selector.cjs +303 -1
- package/dist/lib/object/selector.mjs +282 -1
- package/dist/lib/object/sort.cjs +209 -1
- package/dist/lib/object/sort.mjs +186 -1
- package/dist/lib/object/transform.cjs +2211 -1
- package/dist/lib/object/transform.mjs +2190 -1
- package/dist/lib/object/types.cjs +18 -1
- package/dist/lib/object/utils.cjs +326 -6
- package/dist/lib/object/utils.mjs +305 -6
- package/dist/lib/primitive/boolean/boolean.cjs +407 -1
- package/dist/lib/primitive/boolean/boolean.mjs +386 -1
- package/dist/lib/primitive/boolean/index.cjs +382 -1
- package/dist/lib/primitive/boolean/index.mjs +359 -1
- package/dist/lib/primitive/boolean/types.cjs +18 -1
- package/dist/lib/primitive/date/date.cjs +1126 -1
- package/dist/lib/primitive/date/date.mjs +1105 -1
- package/dist/lib/primitive/date/index.cjs +1128 -1
- package/dist/lib/primitive/date/index.mjs +1105 -1
- package/dist/lib/primitive/date/types.cjs +18 -1
- package/dist/lib/primitive/index.cjs +2338 -5
- package/dist/lib/primitive/index.mjs +2316 -5
- package/dist/lib/primitive/string/index.cjs +875 -5
- package/dist/lib/primitive/string/index.mjs +852 -5
- package/dist/lib/primitive/string/parser-2.cjs +543 -8
- package/dist/lib/primitive/string/parser-2.mjs +522 -8
- package/dist/lib/primitive/string/parser.cjs +236 -3
- package/dist/lib/primitive/string/parser.mjs +215 -3
- package/dist/lib/primitive/string/string.cjs +926 -5
- package/dist/lib/primitive/string/string.mjs +903 -5
- package/dist/lib/primitive/string/types.cjs +18 -1
- package/dist/lib/primitive/types.cjs +18 -1
- package/dist/lib/url/index.cjs +327 -1
- package/dist/lib/url/index.mjs +304 -1
- package/dist/lib/url/parser.cjs +325 -1
- package/dist/lib/url/parser.mjs +304 -1
- package/dist/lib/url/types.cjs +18 -1
- package/package.json +5 -5
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/lib/object/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -1,6 +1,326 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/object/utils.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
isClass: () => isClass,
|
|
24
|
+
isEmptyObject: () => isEmptyObject,
|
|
25
|
+
isObject: () => isObject,
|
|
26
|
+
isPlainObject: () => isPlainObject,
|
|
27
|
+
toJSONString: () => toJSONString,
|
|
28
|
+
traverseStructure: () => traverseStructure
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(utils_exports);
|
|
31
|
+
var isObject = (value) => {
|
|
32
|
+
if (value == null) return false;
|
|
33
|
+
if (Array.isArray(value)) return false;
|
|
34
|
+
if (typeof value === "function") return false;
|
|
35
|
+
if (value instanceof Date) return false;
|
|
36
|
+
if (value instanceof RegExp) return false;
|
|
37
|
+
if (value instanceof Map) return false;
|
|
38
|
+
if (value instanceof Set) return false;
|
|
39
|
+
if (value instanceof Error) return false;
|
|
40
|
+
return typeof value === "object";
|
|
41
|
+
};
|
|
42
|
+
function isPlainObject(v) {
|
|
43
|
+
if (typeof v !== "object" || v === null) return false;
|
|
44
|
+
const proto = Object.getPrototypeOf(v);
|
|
45
|
+
return proto === Object.prototype || proto === null;
|
|
46
|
+
}
|
|
47
|
+
function isClass(obj) {
|
|
48
|
+
return typeof obj === "function" && /^class\s/.test(Function.prototype.toString.call(obj));
|
|
49
|
+
}
|
|
50
|
+
var isEmptyObject = (value) => {
|
|
51
|
+
if (!isObject(value)) return false;
|
|
52
|
+
return Object.keys(value).length === 0;
|
|
53
|
+
};
|
|
54
|
+
var traverseStructure = (current, segments, depth, maxDepth) => {
|
|
55
|
+
if (depth > maxDepth) return void 0;
|
|
56
|
+
if (segments.length === 0) return current;
|
|
57
|
+
const segment = segments[0];
|
|
58
|
+
const remaining = segments.slice(1);
|
|
59
|
+
if (segment.type === "descendant") {
|
|
60
|
+
const result = traverseStructure(current, remaining, depth + 1, maxDepth);
|
|
61
|
+
if (result !== void 0) {
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
if (current && typeof current === "object") {
|
|
65
|
+
if (Array.isArray(current)) {
|
|
66
|
+
const arrResult = [];
|
|
67
|
+
for (let i = 0; i < current.length; i++) {
|
|
68
|
+
const itemResult = traverseStructure(
|
|
69
|
+
current[i],
|
|
70
|
+
segments,
|
|
71
|
+
depth + 1,
|
|
72
|
+
maxDepth
|
|
73
|
+
);
|
|
74
|
+
if (itemResult !== void 0) {
|
|
75
|
+
arrResult[i] = itemResult;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return arrResult.length > 0 ? arrResult : void 0;
|
|
79
|
+
} else {
|
|
80
|
+
const objResult = {};
|
|
81
|
+
for (const key in current) {
|
|
82
|
+
if (current.hasOwnProperty(key)) {
|
|
83
|
+
const itemResult = traverseStructure(
|
|
84
|
+
current[key],
|
|
85
|
+
segments,
|
|
86
|
+
depth + 1,
|
|
87
|
+
maxDepth
|
|
88
|
+
);
|
|
89
|
+
if (itemResult !== void 0) {
|
|
90
|
+
objResult[key] = itemResult;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return Object.keys(objResult).length > 0 ? objResult : void 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
switch (segment.type) {
|
|
100
|
+
case "property":
|
|
101
|
+
if (isObject(current) && segment.value && String(segment.value) in current) {
|
|
102
|
+
const next = current[String(segment.value)];
|
|
103
|
+
const result = traverseStructure(next, remaining, depth + 1, maxDepth);
|
|
104
|
+
if (result !== void 0) {
|
|
105
|
+
return { [String(segment.value)]: result };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
case "index":
|
|
110
|
+
if (Array.isArray(current)) {
|
|
111
|
+
const index = segment.value;
|
|
112
|
+
if (index >= 0 && index < current.length) {
|
|
113
|
+
const result = traverseStructure(
|
|
114
|
+
current[index],
|
|
115
|
+
remaining,
|
|
116
|
+
depth + 1,
|
|
117
|
+
maxDepth
|
|
118
|
+
);
|
|
119
|
+
if (result !== void 0) {
|
|
120
|
+
const arr = new Array(current.length).filter(
|
|
121
|
+
(a) => a !== void 0
|
|
122
|
+
);
|
|
123
|
+
arr[index] = result;
|
|
124
|
+
return arr;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} else if (current && typeof current === "object") {
|
|
128
|
+
const key = String(segment.value);
|
|
129
|
+
if (key in current) {
|
|
130
|
+
const result = traverseStructure(
|
|
131
|
+
current[key],
|
|
132
|
+
remaining,
|
|
133
|
+
depth + 1,
|
|
134
|
+
maxDepth
|
|
135
|
+
);
|
|
136
|
+
if (result !== void 0) {
|
|
137
|
+
return { [key]: result };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
case "wildcard":
|
|
143
|
+
if (current && typeof current === "object") {
|
|
144
|
+
if (Array.isArray(current)) {
|
|
145
|
+
const arrResult = [];
|
|
146
|
+
let hasResults = false;
|
|
147
|
+
for (let i = 0; i < current.length; i++) {
|
|
148
|
+
const result = traverseStructure(
|
|
149
|
+
current[i],
|
|
150
|
+
remaining,
|
|
151
|
+
depth + 1,
|
|
152
|
+
maxDepth
|
|
153
|
+
);
|
|
154
|
+
if (result !== void 0) {
|
|
155
|
+
arrResult[i] = result;
|
|
156
|
+
hasResults = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return hasResults ? arrResult : void 0;
|
|
160
|
+
} else {
|
|
161
|
+
const objResult = {};
|
|
162
|
+
let hasResults = false;
|
|
163
|
+
for (const key in current) {
|
|
164
|
+
if (current.hasOwnProperty(key)) {
|
|
165
|
+
const result = traverseStructure(
|
|
166
|
+
current[key],
|
|
167
|
+
remaining,
|
|
168
|
+
depth + 1,
|
|
169
|
+
maxDepth
|
|
170
|
+
);
|
|
171
|
+
if (result !== void 0) {
|
|
172
|
+
objResult[key] = result;
|
|
173
|
+
hasResults = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return hasResults ? objResult : void 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
case "slice":
|
|
182
|
+
if (Array.isArray(current)) {
|
|
183
|
+
const [start, end] = segment.value;
|
|
184
|
+
const actualStart = Math.max(0, start);
|
|
185
|
+
const actualEnd = Math.min(
|
|
186
|
+
current.length,
|
|
187
|
+
end === Infinity ? current.length : end
|
|
188
|
+
);
|
|
189
|
+
const arrResult = [];
|
|
190
|
+
let hasResults = false;
|
|
191
|
+
for (let i = actualStart; i < actualEnd; i++) {
|
|
192
|
+
const result = traverseStructure(
|
|
193
|
+
current[i],
|
|
194
|
+
remaining,
|
|
195
|
+
depth + 1,
|
|
196
|
+
maxDepth
|
|
197
|
+
);
|
|
198
|
+
if (result !== void 0) {
|
|
199
|
+
arrResult[i] = result;
|
|
200
|
+
hasResults = true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return hasResults ? arrResult : void 0;
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
case "union":
|
|
207
|
+
if (Array.isArray(current)) {
|
|
208
|
+
const indices = segment.value;
|
|
209
|
+
const arrResult = [];
|
|
210
|
+
let hasResults = false;
|
|
211
|
+
for (const index of indices) {
|
|
212
|
+
if (index >= 0 && index < current.length) {
|
|
213
|
+
const result = traverseStructure(
|
|
214
|
+
current[index],
|
|
215
|
+
remaining,
|
|
216
|
+
depth + 1,
|
|
217
|
+
maxDepth
|
|
218
|
+
);
|
|
219
|
+
if (result !== void 0) {
|
|
220
|
+
arrResult[index] = result;
|
|
221
|
+
hasResults = true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return hasResults ? arrResult : void 0;
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
case "filter":
|
|
229
|
+
if (Array.isArray(current)) {
|
|
230
|
+
const filterFn = segment.value;
|
|
231
|
+
const arrResult = [];
|
|
232
|
+
let hasResults = false;
|
|
233
|
+
for (let i = 0; i < current.length; i++) {
|
|
234
|
+
if (filterFn(current[i])) {
|
|
235
|
+
const result = traverseStructure(
|
|
236
|
+
current[i],
|
|
237
|
+
remaining,
|
|
238
|
+
depth + 1,
|
|
239
|
+
maxDepth
|
|
240
|
+
);
|
|
241
|
+
if (result !== void 0) {
|
|
242
|
+
arrResult[i] = result;
|
|
243
|
+
hasResults = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return hasResults ? arrResult : void 0;
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
return void 0;
|
|
252
|
+
};
|
|
253
|
+
function toJSONString(value, space = 0) {
|
|
254
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
255
|
+
const gap = (n) => space ? " ".repeat(n) : "";
|
|
256
|
+
const nl = (n) => space ? `
|
|
257
|
+
${" ".repeat(n)}` : "";
|
|
258
|
+
const esc = (s) => s.replace(/[\u0000-\u001F"\\]/g, (c) => {
|
|
259
|
+
switch (c) {
|
|
260
|
+
case '"':
|
|
261
|
+
return '\\"';
|
|
262
|
+
case "\\":
|
|
263
|
+
return "\\\\";
|
|
264
|
+
case "\b":
|
|
265
|
+
return "\\b";
|
|
266
|
+
case "\f":
|
|
267
|
+
return "\\f";
|
|
268
|
+
case "\n":
|
|
269
|
+
return "\\n";
|
|
270
|
+
case "\r":
|
|
271
|
+
return "\\r";
|
|
272
|
+
case " ":
|
|
273
|
+
return "\\t";
|
|
274
|
+
default:
|
|
275
|
+
const code = c.charCodeAt(0).toString(16).padStart(4, "0");
|
|
276
|
+
return `\\u${code}`;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const ser = (v, indent) => {
|
|
280
|
+
if (v === null) return "null";
|
|
281
|
+
const t = typeof v;
|
|
282
|
+
if (t === "number") return Number.isFinite(v) ? String(v) : "null";
|
|
283
|
+
if (t === "boolean") return v ? "true" : "false";
|
|
284
|
+
if (t === "string") {
|
|
285
|
+
}
|
|
286
|
+
if (t === "bigint") return `"${String(v)}"`;
|
|
287
|
+
if (t === "function" || t === "undefined" || t === "symbol")
|
|
288
|
+
return void 0;
|
|
289
|
+
if (Array.isArray(v)) {
|
|
290
|
+
if (seen.has(v))
|
|
291
|
+
throw new TypeError("Converting circular structure to JSON");
|
|
292
|
+
seen.add(v);
|
|
293
|
+
const next = indent + space;
|
|
294
|
+
const parts = v.map((x) => {
|
|
295
|
+
const s = ser(x, next);
|
|
296
|
+
return s === void 0 ? "null" : s;
|
|
297
|
+
});
|
|
298
|
+
seen.delete(v);
|
|
299
|
+
if (!space) return `[${parts.join(",")}]`;
|
|
300
|
+
return `[${nl(next)}${parts.join(`,${nl(next)}`)}${nl(indent)}]`;
|
|
301
|
+
}
|
|
302
|
+
if (t === "object") {
|
|
303
|
+
if (seen.has(v))
|
|
304
|
+
throw new TypeError("Converting circular structure to JSON");
|
|
305
|
+
seen.add(v);
|
|
306
|
+
const keys = Object.keys(v);
|
|
307
|
+
const next = indent + space;
|
|
308
|
+
const parts = [];
|
|
309
|
+
for (const k of keys) {
|
|
310
|
+
const s = ser(v[k], next);
|
|
311
|
+
if (s !== void 0) {
|
|
312
|
+
if (!space) parts.push(`"${esc(k)}":${s}`);
|
|
313
|
+
else parts.push(`${gap(next)}"${esc(k)}": ${s}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
seen.delete(v);
|
|
317
|
+
if (!space) return `{${parts.join(",")}}`;
|
|
318
|
+
return `{
|
|
319
|
+
${parts.join(",\n")}
|
|
320
|
+
${gap(indent)}}`;
|
|
321
|
+
}
|
|
322
|
+
return void 0;
|
|
323
|
+
};
|
|
324
|
+
const out = ser(value, 0);
|
|
325
|
+
return out === void 0 ? void 0 : out;
|
|
326
|
+
}
|
|
@@ -1,6 +1,305 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// src/lib/object/utils.ts
|
|
2
|
+
var isObject = (value) => {
|
|
3
|
+
if (value == null) return false;
|
|
4
|
+
if (Array.isArray(value)) return false;
|
|
5
|
+
if (typeof value === "function") return false;
|
|
6
|
+
if (value instanceof Date) return false;
|
|
7
|
+
if (value instanceof RegExp) return false;
|
|
8
|
+
if (value instanceof Map) return false;
|
|
9
|
+
if (value instanceof Set) return false;
|
|
10
|
+
if (value instanceof Error) return false;
|
|
11
|
+
return typeof value === "object";
|
|
12
|
+
};
|
|
13
|
+
function isPlainObject(v) {
|
|
14
|
+
if (typeof v !== "object" || v === null) return false;
|
|
15
|
+
const proto = Object.getPrototypeOf(v);
|
|
16
|
+
return proto === Object.prototype || proto === null;
|
|
17
|
+
}
|
|
18
|
+
function isClass(obj) {
|
|
19
|
+
return typeof obj === "function" && /^class\s/.test(Function.prototype.toString.call(obj));
|
|
20
|
+
}
|
|
21
|
+
var isEmptyObject = (value) => {
|
|
22
|
+
if (!isObject(value)) return false;
|
|
23
|
+
return Object.keys(value).length === 0;
|
|
24
|
+
};
|
|
25
|
+
var traverseStructure = (current, segments, depth, maxDepth) => {
|
|
26
|
+
if (depth > maxDepth) return void 0;
|
|
27
|
+
if (segments.length === 0) return current;
|
|
28
|
+
const segment = segments[0];
|
|
29
|
+
const remaining = segments.slice(1);
|
|
30
|
+
if (segment.type === "descendant") {
|
|
31
|
+
const result = traverseStructure(current, remaining, depth + 1, maxDepth);
|
|
32
|
+
if (result !== void 0) {
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
if (current && typeof current === "object") {
|
|
36
|
+
if (Array.isArray(current)) {
|
|
37
|
+
const arrResult = [];
|
|
38
|
+
for (let i = 0; i < current.length; i++) {
|
|
39
|
+
const itemResult = traverseStructure(
|
|
40
|
+
current[i],
|
|
41
|
+
segments,
|
|
42
|
+
depth + 1,
|
|
43
|
+
maxDepth
|
|
44
|
+
);
|
|
45
|
+
if (itemResult !== void 0) {
|
|
46
|
+
arrResult[i] = itemResult;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return arrResult.length > 0 ? arrResult : void 0;
|
|
50
|
+
} else {
|
|
51
|
+
const objResult = {};
|
|
52
|
+
for (const key in current) {
|
|
53
|
+
if (current.hasOwnProperty(key)) {
|
|
54
|
+
const itemResult = traverseStructure(
|
|
55
|
+
current[key],
|
|
56
|
+
segments,
|
|
57
|
+
depth + 1,
|
|
58
|
+
maxDepth
|
|
59
|
+
);
|
|
60
|
+
if (itemResult !== void 0) {
|
|
61
|
+
objResult[key] = itemResult;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return Object.keys(objResult).length > 0 ? objResult : void 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
switch (segment.type) {
|
|
71
|
+
case "property":
|
|
72
|
+
if (isObject(current) && segment.value && String(segment.value) in current) {
|
|
73
|
+
const next = current[String(segment.value)];
|
|
74
|
+
const result = traverseStructure(next, remaining, depth + 1, maxDepth);
|
|
75
|
+
if (result !== void 0) {
|
|
76
|
+
return { [String(segment.value)]: result };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case "index":
|
|
81
|
+
if (Array.isArray(current)) {
|
|
82
|
+
const index = segment.value;
|
|
83
|
+
if (index >= 0 && index < current.length) {
|
|
84
|
+
const result = traverseStructure(
|
|
85
|
+
current[index],
|
|
86
|
+
remaining,
|
|
87
|
+
depth + 1,
|
|
88
|
+
maxDepth
|
|
89
|
+
);
|
|
90
|
+
if (result !== void 0) {
|
|
91
|
+
const arr = new Array(current.length).filter(
|
|
92
|
+
(a) => a !== void 0
|
|
93
|
+
);
|
|
94
|
+
arr[index] = result;
|
|
95
|
+
return arr;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else if (current && typeof current === "object") {
|
|
99
|
+
const key = String(segment.value);
|
|
100
|
+
if (key in current) {
|
|
101
|
+
const result = traverseStructure(
|
|
102
|
+
current[key],
|
|
103
|
+
remaining,
|
|
104
|
+
depth + 1,
|
|
105
|
+
maxDepth
|
|
106
|
+
);
|
|
107
|
+
if (result !== void 0) {
|
|
108
|
+
return { [key]: result };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case "wildcard":
|
|
114
|
+
if (current && typeof current === "object") {
|
|
115
|
+
if (Array.isArray(current)) {
|
|
116
|
+
const arrResult = [];
|
|
117
|
+
let hasResults = false;
|
|
118
|
+
for (let i = 0; i < current.length; i++) {
|
|
119
|
+
const result = traverseStructure(
|
|
120
|
+
current[i],
|
|
121
|
+
remaining,
|
|
122
|
+
depth + 1,
|
|
123
|
+
maxDepth
|
|
124
|
+
);
|
|
125
|
+
if (result !== void 0) {
|
|
126
|
+
arrResult[i] = result;
|
|
127
|
+
hasResults = true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return hasResults ? arrResult : void 0;
|
|
131
|
+
} else {
|
|
132
|
+
const objResult = {};
|
|
133
|
+
let hasResults = false;
|
|
134
|
+
for (const key in current) {
|
|
135
|
+
if (current.hasOwnProperty(key)) {
|
|
136
|
+
const result = traverseStructure(
|
|
137
|
+
current[key],
|
|
138
|
+
remaining,
|
|
139
|
+
depth + 1,
|
|
140
|
+
maxDepth
|
|
141
|
+
);
|
|
142
|
+
if (result !== void 0) {
|
|
143
|
+
objResult[key] = result;
|
|
144
|
+
hasResults = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return hasResults ? objResult : void 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case "slice":
|
|
153
|
+
if (Array.isArray(current)) {
|
|
154
|
+
const [start, end] = segment.value;
|
|
155
|
+
const actualStart = Math.max(0, start);
|
|
156
|
+
const actualEnd = Math.min(
|
|
157
|
+
current.length,
|
|
158
|
+
end === Infinity ? current.length : end
|
|
159
|
+
);
|
|
160
|
+
const arrResult = [];
|
|
161
|
+
let hasResults = false;
|
|
162
|
+
for (let i = actualStart; i < actualEnd; i++) {
|
|
163
|
+
const result = traverseStructure(
|
|
164
|
+
current[i],
|
|
165
|
+
remaining,
|
|
166
|
+
depth + 1,
|
|
167
|
+
maxDepth
|
|
168
|
+
);
|
|
169
|
+
if (result !== void 0) {
|
|
170
|
+
arrResult[i] = result;
|
|
171
|
+
hasResults = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return hasResults ? arrResult : void 0;
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
case "union":
|
|
178
|
+
if (Array.isArray(current)) {
|
|
179
|
+
const indices = segment.value;
|
|
180
|
+
const arrResult = [];
|
|
181
|
+
let hasResults = false;
|
|
182
|
+
for (const index of indices) {
|
|
183
|
+
if (index >= 0 && index < current.length) {
|
|
184
|
+
const result = traverseStructure(
|
|
185
|
+
current[index],
|
|
186
|
+
remaining,
|
|
187
|
+
depth + 1,
|
|
188
|
+
maxDepth
|
|
189
|
+
);
|
|
190
|
+
if (result !== void 0) {
|
|
191
|
+
arrResult[index] = result;
|
|
192
|
+
hasResults = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return hasResults ? arrResult : void 0;
|
|
197
|
+
}
|
|
198
|
+
break;
|
|
199
|
+
case "filter":
|
|
200
|
+
if (Array.isArray(current)) {
|
|
201
|
+
const filterFn = segment.value;
|
|
202
|
+
const arrResult = [];
|
|
203
|
+
let hasResults = false;
|
|
204
|
+
for (let i = 0; i < current.length; i++) {
|
|
205
|
+
if (filterFn(current[i])) {
|
|
206
|
+
const result = traverseStructure(
|
|
207
|
+
current[i],
|
|
208
|
+
remaining,
|
|
209
|
+
depth + 1,
|
|
210
|
+
maxDepth
|
|
211
|
+
);
|
|
212
|
+
if (result !== void 0) {
|
|
213
|
+
arrResult[i] = result;
|
|
214
|
+
hasResults = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return hasResults ? arrResult : void 0;
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
return void 0;
|
|
223
|
+
};
|
|
224
|
+
function toJSONString(value, space = 0) {
|
|
225
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
226
|
+
const gap = (n) => space ? " ".repeat(n) : "";
|
|
227
|
+
const nl = (n) => space ? `
|
|
228
|
+
${" ".repeat(n)}` : "";
|
|
229
|
+
const esc = (s) => s.replace(/[\u0000-\u001F"\\]/g, (c) => {
|
|
230
|
+
switch (c) {
|
|
231
|
+
case '"':
|
|
232
|
+
return '\\"';
|
|
233
|
+
case "\\":
|
|
234
|
+
return "\\\\";
|
|
235
|
+
case "\b":
|
|
236
|
+
return "\\b";
|
|
237
|
+
case "\f":
|
|
238
|
+
return "\\f";
|
|
239
|
+
case "\n":
|
|
240
|
+
return "\\n";
|
|
241
|
+
case "\r":
|
|
242
|
+
return "\\r";
|
|
243
|
+
case " ":
|
|
244
|
+
return "\\t";
|
|
245
|
+
default:
|
|
246
|
+
const code = c.charCodeAt(0).toString(16).padStart(4, "0");
|
|
247
|
+
return `\\u${code}`;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const ser = (v, indent) => {
|
|
251
|
+
if (v === null) return "null";
|
|
252
|
+
const t = typeof v;
|
|
253
|
+
if (t === "number") return Number.isFinite(v) ? String(v) : "null";
|
|
254
|
+
if (t === "boolean") return v ? "true" : "false";
|
|
255
|
+
if (t === "string") {
|
|
256
|
+
}
|
|
257
|
+
if (t === "bigint") return `"${String(v)}"`;
|
|
258
|
+
if (t === "function" || t === "undefined" || t === "symbol")
|
|
259
|
+
return void 0;
|
|
260
|
+
if (Array.isArray(v)) {
|
|
261
|
+
if (seen.has(v))
|
|
262
|
+
throw new TypeError("Converting circular structure to JSON");
|
|
263
|
+
seen.add(v);
|
|
264
|
+
const next = indent + space;
|
|
265
|
+
const parts = v.map((x) => {
|
|
266
|
+
const s = ser(x, next);
|
|
267
|
+
return s === void 0 ? "null" : s;
|
|
268
|
+
});
|
|
269
|
+
seen.delete(v);
|
|
270
|
+
if (!space) return `[${parts.join(",")}]`;
|
|
271
|
+
return `[${nl(next)}${parts.join(`,${nl(next)}`)}${nl(indent)}]`;
|
|
272
|
+
}
|
|
273
|
+
if (t === "object") {
|
|
274
|
+
if (seen.has(v))
|
|
275
|
+
throw new TypeError("Converting circular structure to JSON");
|
|
276
|
+
seen.add(v);
|
|
277
|
+
const keys = Object.keys(v);
|
|
278
|
+
const next = indent + space;
|
|
279
|
+
const parts = [];
|
|
280
|
+
for (const k of keys) {
|
|
281
|
+
const s = ser(v[k], next);
|
|
282
|
+
if (s !== void 0) {
|
|
283
|
+
if (!space) parts.push(`"${esc(k)}":${s}`);
|
|
284
|
+
else parts.push(`${gap(next)}"${esc(k)}": ${s}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
seen.delete(v);
|
|
288
|
+
if (!space) return `{${parts.join(",")}}`;
|
|
289
|
+
return `{
|
|
290
|
+
${parts.join(",\n")}
|
|
291
|
+
${gap(indent)}}`;
|
|
292
|
+
}
|
|
293
|
+
return void 0;
|
|
294
|
+
};
|
|
295
|
+
const out = ser(value, 0);
|
|
296
|
+
return out === void 0 ? void 0 : out;
|
|
297
|
+
}
|
|
298
|
+
export {
|
|
299
|
+
isClass,
|
|
300
|
+
isEmptyObject,
|
|
301
|
+
isObject,
|
|
302
|
+
isPlainObject,
|
|
303
|
+
toJSONString,
|
|
304
|
+
traverseStructure
|
|
305
|
+
};
|