@oxog/utils 1.0.1 → 1.1.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/CHANGELOG.md +41 -0
- package/README.md +56 -43
- package/dist/chunk-25WW2FCA.js +34 -0
- package/dist/chunk-25WW2FCA.js.map +1 -0
- package/dist/chunk-DEVWOLUI.cjs +112 -0
- package/dist/chunk-DEVWOLUI.cjs.map +1 -0
- package/dist/chunk-IUDFQZIP.js +99 -0
- package/dist/chunk-IUDFQZIP.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-SWG777R6.cjs +40 -0
- package/dist/chunk-SWG777R6.cjs.map +1 -0
- package/dist/index.cjs +210 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -11
- package/dist/index.d.ts +35 -11
- package/dist/index.js +156 -221
- package/dist/index.js.map +1 -1
- package/dist/plugins/async.cjs +90 -107
- package/dist/plugins/async.cjs.map +1 -1
- package/dist/plugins/async.d.cts +21 -7
- package/dist/plugins/async.d.ts +21 -7
- package/dist/plugins/async.js +89 -106
- package/dist/plugins/async.js.map +1 -1
- package/dist/plugins/deep.cjs +183 -59
- package/dist/plugins/deep.cjs.map +1 -1
- package/dist/plugins/deep.d.cts +27 -8
- package/dist/plugins/deep.d.ts +27 -8
- package/dist/plugins/deep.js +183 -59
- package/dist/plugins/deep.js.map +1 -1
- package/dist/plugins/guard.cjs +2 -0
- package/dist/plugins/guard.cjs.map +1 -1
- package/dist/plugins/guard.js +2 -0
- package/dist/plugins/guard.js.map +1 -1
- package/dist/plugins/transform.cjs +6 -3
- package/dist/plugins/transform.cjs.map +1 -1
- package/dist/plugins/transform.js +6 -3
- package/dist/plugins/transform.js.map +1 -1
- package/dist/{types-XmRC5wYO.d.cts → types-C2bIzOSX.d.cts} +52 -13
- package/dist/{types-XmRC5wYO.d.ts → types-C2bIzOSX.d.ts} +52 -13
- package/package.json +15 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { P as Plugin } from './types-
|
|
1
|
+
import { P as Plugin } from './types-C2bIzOSX.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Safely access a deeply nested property in an object.
|
|
5
5
|
*
|
|
6
6
|
* Returns the value at the specified path, or the default value
|
|
7
7
|
* if the path doesn't exist. Supports both dot notation and array syntax.
|
|
8
|
+
* `null`/`undefined` values and functions are treated as missing. Inherited
|
|
9
|
+
* `__proto__`, `constructor` and `prototype` are never traversed.
|
|
8
10
|
*
|
|
9
11
|
* @param obj - The source object to access
|
|
10
12
|
* @param path - The path to the property (dot notation: 'a.b.c')
|
|
@@ -41,7 +43,13 @@ declare function get<T, P extends string, D = undefined>(obj: T, path: P, defaul
|
|
|
41
43
|
* Immutable property setter.
|
|
42
44
|
*
|
|
43
45
|
* Creates a new object with the value at the specified path updated.
|
|
44
|
-
* The original object is not modified
|
|
46
|
+
* The original object is not modified; arrays along the path are copied as
|
|
47
|
+
* arrays and untouched branches are shared with the original.
|
|
48
|
+
* Supports dot and bracket notation (`'items[0].id'`). Missing containers are
|
|
49
|
+
* created as arrays for numeric bracket segments and as objects otherwise.
|
|
50
|
+
*
|
|
51
|
+
* @throws {InvalidPathError} if the path contains `__proto__`, `constructor`
|
|
52
|
+
* or `prototype` (prototype pollution protection).
|
|
45
53
|
*
|
|
46
54
|
* @param obj - The source object
|
|
47
55
|
* @param path - The path to update (dot notation)
|
|
@@ -71,7 +79,10 @@ declare function set<T, P extends string>(obj: T, path: P, value: any): T;
|
|
|
71
79
|
* Mutable property setter.
|
|
72
80
|
*
|
|
73
81
|
* Updates the value at the specified path by mutating the original object.
|
|
74
|
-
* Use this only when mutation is intentional.
|
|
82
|
+
* Use this only when mutation is intentional. Path syntax is the same as {@link set}.
|
|
83
|
+
*
|
|
84
|
+
* @throws {InvalidPathError} if the path contains `__proto__`, `constructor`
|
|
85
|
+
* or `prototype` (prototype pollution protection).
|
|
75
86
|
*
|
|
76
87
|
* @param obj - The source object (will be mutated)
|
|
77
88
|
* @param path - The path to update (dot notation)
|
|
@@ -91,8 +102,9 @@ declare function setMut<T, P extends string>(obj: T, path: P, value: any): T;
|
|
|
91
102
|
/**
|
|
92
103
|
* Check if a path exists in an object.
|
|
93
104
|
*
|
|
94
|
-
* Returns true if the path
|
|
95
|
-
*
|
|
105
|
+
* Returns true if every segment of the path is an own property and the
|
|
106
|
+
* final value is not undefined. Inherited properties (`toString`,
|
|
107
|
+
* `constructor`, ...) and out-of-bounds array indexes return false.
|
|
96
108
|
*
|
|
97
109
|
* @param obj - The source object
|
|
98
110
|
* @param path - The path to check (dot notation)
|
|
@@ -167,7 +179,10 @@ declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): O
|
|
|
167
179
|
* merge({}, { prototype: { evil: true } }); // {} - filtered!
|
|
168
180
|
* ```
|
|
169
181
|
*/
|
|
182
|
+
declare function merge<T extends object, S extends object[]>(target: T, ...sources: S): T & UnionToIntersection<S[number]>;
|
|
170
183
|
declare function merge<T extends object, S extends object>(target: T, ...sources: S[]): T & S;
|
|
184
|
+
/** `A | B` -> `A & B` (used to type the result of merge with several sources). */
|
|
185
|
+
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
171
186
|
/**
|
|
172
187
|
* Type-safe Object.keys().
|
|
173
188
|
*
|
|
@@ -285,7 +300,7 @@ declare namespace object {
|
|
|
285
300
|
*
|
|
286
301
|
* @see {@link keyBy} for indexing by property
|
|
287
302
|
*/
|
|
288
|
-
declare function groupBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string)): Record<string, T[]>;
|
|
303
|
+
declare function groupBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string | number)): Record<string, T[]>;
|
|
289
304
|
/**
|
|
290
305
|
* Create an object keyed by a property value.
|
|
291
306
|
*
|
|
@@ -316,7 +331,7 @@ declare function groupBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) =>
|
|
|
316
331
|
*
|
|
317
332
|
* @see {@link groupBy} for grouping
|
|
318
333
|
*/
|
|
319
|
-
declare function keyBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string)): Record<string, T>;
|
|
334
|
+
declare function keyBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string | number)): Record<string, T>;
|
|
320
335
|
/**
|
|
321
336
|
* Split array into chunks of specified size.
|
|
322
337
|
*
|
|
@@ -334,6 +349,7 @@ declare function keyBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => st
|
|
|
334
349
|
* ```typescript
|
|
335
350
|
* chunk([1, 2, 3], 1); // [[1], [2], [3]]
|
|
336
351
|
* chunk([1, 2, 3], 5); // [[1, 2, 3]]
|
|
352
|
+
* chunk([1, 2, 3], 0); // []
|
|
337
353
|
* ```
|
|
338
354
|
*/
|
|
339
355
|
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
@@ -383,7 +399,7 @@ declare function uniq<T>(arr: T[]): T[];
|
|
|
383
399
|
*
|
|
384
400
|
* @see {@link uniq} for simple deduplication
|
|
385
401
|
*/
|
|
386
|
-
declare function uniqBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) =>
|
|
402
|
+
declare function uniqBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => unknown)): T[];
|
|
387
403
|
/**
|
|
388
404
|
* Flatten nested arrays up to specified depth.
|
|
389
405
|
*
|
|
@@ -481,7 +497,7 @@ declare function last<T>(arr: T[], n?: number): T | T[] | undefined;
|
|
|
481
497
|
* @example Get one random element
|
|
482
498
|
* ```typescript
|
|
483
499
|
* const arr = [1, 2, 3, 4, 5];
|
|
484
|
-
* sample(arr); //
|
|
500
|
+
* sample(arr); // One random element in an array (e.g., [3])
|
|
485
501
|
* ```
|
|
486
502
|
*
|
|
487
503
|
* @example Get multiple random elements
|
|
@@ -608,7 +624,9 @@ declare function capitalize(str: string): string;
|
|
|
608
624
|
* Truncate string to specified length with optional suffix.
|
|
609
625
|
*
|
|
610
626
|
* @param str - String to truncate
|
|
611
|
-
* @param length - Number of characters to keep before
|
|
627
|
+
* @param length - Number of characters (UTF-16 code units) to keep before
|
|
628
|
+
* adding the suffix. A surrogate pair is never split, so slightly fewer
|
|
629
|
+
* units may be kept.
|
|
612
630
|
* @param suffix - Suffix to append when truncated (default: '...')
|
|
613
631
|
* @returns Truncated string
|
|
614
632
|
*
|
|
@@ -1000,7 +1018,13 @@ declare class PluginDependencyMissingError extends UtilsError {
|
|
|
1000
1018
|
* Error thrown when retry attempts are exhausted.
|
|
1001
1019
|
*/
|
|
1002
1020
|
declare class MaxRetriesExceededError extends UtilsError {
|
|
1003
|
-
|
|
1021
|
+
/** Number of attempts that were made. */
|
|
1022
|
+
readonly attempts: number;
|
|
1023
|
+
/**
|
|
1024
|
+
* @param attempts - Number of attempts that were made
|
|
1025
|
+
* @param cause - The error thrown by the last attempt (available as `error.cause`)
|
|
1026
|
+
*/
|
|
1027
|
+
constructor(attempts: number, cause?: unknown);
|
|
1004
1028
|
}
|
|
1005
1029
|
/**
|
|
1006
1030
|
* Error thrown when circular dependency is detected between plugins.
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import { InvalidPathError, PluginAlreadyRegisteredError, PluginDependencyMissingError, PluginInitializationError, PluginNotFoundError, CircularDependencyError } from './chunk-IUDFQZIP.js';
|
|
2
|
+
export { CircularDependencyError, CircularReferenceError, InvalidPathError, KernelAlreadyInitializedError, KernelInitializingError, MaxRetriesExceededError, PluginAlreadyRegisteredError, PluginDependencyMissingError, PluginInitializationError, PluginNotFoundError, TimeoutError, UtilsError } from './chunk-IUDFQZIP.js';
|
|
3
|
+
import { parsePath, UNSAFE_KEYS, hasOwn, hasUnsafeSegment, assignOwn } from './chunk-25WW2FCA.js';
|
|
4
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
6
5
|
|
|
7
6
|
// src/plugins/core/object.ts
|
|
8
7
|
var object_exports = {};
|
|
@@ -23,12 +22,14 @@ function get(obj, path, defaultValue) {
|
|
|
23
22
|
if (obj == null) {
|
|
24
23
|
return defaultValue;
|
|
25
24
|
}
|
|
26
|
-
const keys2 = path.toString().split(/[\.\[]/g).map((k) => k.replace(/[\]']/g, "")).filter((k) => k !== "");
|
|
27
25
|
let result = obj;
|
|
28
|
-
for (const key of
|
|
26
|
+
for (const { key } of parsePath(path)) {
|
|
29
27
|
if (result == null) {
|
|
30
28
|
return defaultValue;
|
|
31
29
|
}
|
|
30
|
+
if (UNSAFE_KEYS.has(key) && !hasOwn(Object(result), key)) {
|
|
31
|
+
return defaultValue;
|
|
32
|
+
}
|
|
32
33
|
result = result[key];
|
|
33
34
|
}
|
|
34
35
|
if (typeof result === "function") {
|
|
@@ -40,35 +41,24 @@ function set(obj, path, value) {
|
|
|
40
41
|
if (obj == null || typeof obj !== "object") {
|
|
41
42
|
return obj;
|
|
42
43
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (Array.isArray(arrayValue)) {
|
|
57
|
-
return {
|
|
58
|
-
...current,
|
|
59
|
-
[arrayPath]: [
|
|
60
|
-
...arrayValue.slice(0, arrayIndex),
|
|
61
|
-
value,
|
|
62
|
-
...arrayValue.slice(arrayIndex + 1)
|
|
63
|
-
]
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return { ...current, [key]: value };
|
|
44
|
+
const segments = parsePath(path);
|
|
45
|
+
if (segments.length === 0) {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
if (hasUnsafeSegment(segments)) {
|
|
49
|
+
throw new InvalidPathError(String(path));
|
|
50
|
+
}
|
|
51
|
+
const deepSet = (current, index) => {
|
|
52
|
+
const { key } = segments[index];
|
|
53
|
+
const copy = Array.isArray(current) ? current.slice() : { ...current };
|
|
54
|
+
if (index === segments.length - 1) {
|
|
55
|
+
copy[key] = value;
|
|
56
|
+
return copy;
|
|
68
57
|
}
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
58
|
+
const next = current[key];
|
|
59
|
+
const child = next != null && typeof next === "object" ? next : segments[index + 1].index ? [] : {};
|
|
60
|
+
copy[key] = deepSet(child, index + 1);
|
|
61
|
+
return copy;
|
|
72
62
|
};
|
|
73
63
|
return deepSet(obj, 0);
|
|
74
64
|
}
|
|
@@ -76,29 +66,31 @@ function setMut(obj, path, value) {
|
|
|
76
66
|
if (obj == null || typeof obj !== "object") {
|
|
77
67
|
return obj;
|
|
78
68
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
const segments = parsePath(path);
|
|
70
|
+
if (segments.length === 0) {
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
if (hasUnsafeSegment(segments)) {
|
|
74
|
+
throw new InvalidPathError(String(path));
|
|
75
|
+
}
|
|
76
|
+
let current = obj;
|
|
77
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
78
|
+
const { key } = segments[i];
|
|
79
|
+
if (current[key] == null || typeof current[key] !== "object") {
|
|
80
|
+
current[key] = segments[i + 1].index ? [] : {};
|
|
85
81
|
}
|
|
86
|
-
|
|
82
|
+
current = current[key];
|
|
87
83
|
}
|
|
88
|
-
|
|
84
|
+
current[segments[segments.length - 1].key] = value;
|
|
89
85
|
return obj;
|
|
90
86
|
}
|
|
91
87
|
function has(obj, path) {
|
|
92
88
|
if (obj == null) {
|
|
93
89
|
return false;
|
|
94
90
|
}
|
|
95
|
-
const keys2 = path.toString().split(/[\.\[]/g).map((k) => k.replace(/[\]']/g, "")).filter((k) => k !== "");
|
|
96
91
|
let result = obj;
|
|
97
|
-
for (const key of
|
|
98
|
-
if (
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
if (result == null || !(key in result)) {
|
|
92
|
+
for (const { key } of parsePath(path)) {
|
|
93
|
+
if (result == null || !hasOwn(Object(result), key)) {
|
|
102
94
|
return false;
|
|
103
95
|
}
|
|
104
96
|
result = result[key];
|
|
@@ -109,7 +101,7 @@ function pick(obj, keys2) {
|
|
|
109
101
|
const result = {};
|
|
110
102
|
for (const key of keys2) {
|
|
111
103
|
if (key in obj) {
|
|
112
|
-
result
|
|
104
|
+
assignOwn(result, key, obj[key]);
|
|
113
105
|
}
|
|
114
106
|
}
|
|
115
107
|
return result;
|
|
@@ -122,11 +114,11 @@ function omit(obj, keys2) {
|
|
|
122
114
|
return result;
|
|
123
115
|
}
|
|
124
116
|
function merge(target, ...sources) {
|
|
125
|
-
const DANGEROUS_KEYS = ["__proto__", "constructor", "prototype"];
|
|
126
117
|
const result = { ...target };
|
|
127
118
|
for (const source of sources) {
|
|
119
|
+
if (source == null) continue;
|
|
128
120
|
for (const key of Object.keys(source)) {
|
|
129
|
-
if (
|
|
121
|
+
if (UNSAFE_KEYS.has(key)) continue;
|
|
130
122
|
result[key] = source[key];
|
|
131
123
|
}
|
|
132
124
|
}
|
|
@@ -163,10 +155,11 @@ function groupBy(arr, key) {
|
|
|
163
155
|
const result = {};
|
|
164
156
|
for (const item of arr) {
|
|
165
157
|
const groupKey = typeof key === "function" ? key(item) : String(item[key]);
|
|
166
|
-
if (
|
|
167
|
-
result[groupKey]
|
|
158
|
+
if (hasOwn(result, groupKey)) {
|
|
159
|
+
result[groupKey].push(item);
|
|
160
|
+
} else {
|
|
161
|
+
assignOwn(result, groupKey, [item]);
|
|
168
162
|
}
|
|
169
|
-
result[groupKey].push(item);
|
|
170
163
|
}
|
|
171
164
|
return result;
|
|
172
165
|
}
|
|
@@ -174,12 +167,16 @@ function keyBy(arr, key) {
|
|
|
174
167
|
const result = {};
|
|
175
168
|
for (const item of arr) {
|
|
176
169
|
const keyValue = typeof key === "function" ? key(item) : String(item[key]);
|
|
177
|
-
result
|
|
170
|
+
assignOwn(result, keyValue, item);
|
|
178
171
|
}
|
|
179
172
|
return result;
|
|
180
173
|
}
|
|
181
174
|
function chunk(arr, size) {
|
|
182
175
|
const result = [];
|
|
176
|
+
size = Math.trunc(size);
|
|
177
|
+
if (!(size >= 1)) {
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
183
180
|
for (let i = 0; i < arr.length; i += size) {
|
|
184
181
|
result.push(arr.slice(i, i + size));
|
|
185
182
|
}
|
|
@@ -215,18 +212,19 @@ function compact(arr) {
|
|
|
215
212
|
return arr.filter(Boolean);
|
|
216
213
|
}
|
|
217
214
|
function first(arr, n = 1) {
|
|
218
|
-
if (arr.length === 0) return void 0;
|
|
219
215
|
if (n === 1) return arr[0];
|
|
220
|
-
|
|
221
|
-
return
|
|
216
|
+
if (arr.length === 0) return void 0;
|
|
217
|
+
return arr.slice(0, Math.max(0, Math.trunc(n) || 0));
|
|
222
218
|
}
|
|
223
219
|
function last(arr, n = 1) {
|
|
224
|
-
if (arr.length === 0) return void 0;
|
|
225
220
|
if (n === 1) return arr[arr.length - 1];
|
|
226
|
-
|
|
221
|
+
if (arr.length === 0) return void 0;
|
|
222
|
+
const count = Math.max(0, Math.trunc(n) || 0);
|
|
223
|
+
return count === 0 ? [] : arr.slice(-count);
|
|
227
224
|
}
|
|
228
225
|
function sample(arr, n = 1) {
|
|
229
|
-
|
|
226
|
+
n = Math.max(0, Math.trunc(n) || 0);
|
|
227
|
+
if (arr.length === 0 || n === 0) return [];
|
|
230
228
|
if (n >= arr.length) return [...arr];
|
|
231
229
|
const shuffled = [...arr];
|
|
232
230
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
|
@@ -268,91 +266,99 @@ function capitalize(str) {
|
|
|
268
266
|
}
|
|
269
267
|
function truncate(str, length, suffix = "...") {
|
|
270
268
|
if (str.length <= length) return str;
|
|
271
|
-
|
|
269
|
+
let end = Math.max(0, Math.trunc(length) || 0);
|
|
270
|
+
if (end > 0 && isHighSurrogate(str.charCodeAt(end - 1)) && isLowSurrogate(str.charCodeAt(end))) {
|
|
271
|
+
end--;
|
|
272
|
+
}
|
|
273
|
+
return str.slice(0, end) + suffix;
|
|
272
274
|
}
|
|
275
|
+
var isHighSurrogate = (code) => code >= 55296 && code <= 56319;
|
|
276
|
+
var isLowSurrogate = (code) => code >= 56320 && code <= 57343;
|
|
273
277
|
function slugify(str) {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
"\u011F": "g",
|
|
281
|
-
"\u011E": "g",
|
|
282
|
-
"\xFC": "u",
|
|
283
|
-
"\xDC": "u",
|
|
284
|
-
"\xF6": "o",
|
|
285
|
-
"\xD6": "o",
|
|
286
|
-
"\xE7": "c",
|
|
287
|
-
"\xC7": "c",
|
|
288
|
-
// Russian (Cyrillic to Latin - basic transliteration)
|
|
289
|
-
"\u0430": "a",
|
|
290
|
-
"\u0431": "b",
|
|
291
|
-
"\u0432": "v",
|
|
292
|
-
"\u0433": "g",
|
|
293
|
-
"\u0434": "d",
|
|
294
|
-
"\u0435": "e",
|
|
295
|
-
"\u0451": "yo",
|
|
296
|
-
"\u0436": "zh",
|
|
297
|
-
"\u0437": "z",
|
|
298
|
-
"\u0438": "i",
|
|
299
|
-
"\u0439": "y",
|
|
300
|
-
"\u043A": "k",
|
|
301
|
-
"\u043B": "l",
|
|
302
|
-
"\u043C": "m",
|
|
303
|
-
"\u043D": "n",
|
|
304
|
-
"\u043E": "o",
|
|
305
|
-
"\u043F": "p",
|
|
306
|
-
"\u0440": "r",
|
|
307
|
-
"\u0441": "s",
|
|
308
|
-
"\u0442": "t",
|
|
309
|
-
"\u0443": "u",
|
|
310
|
-
"\u0444": "f",
|
|
311
|
-
"\u0445": "h",
|
|
312
|
-
"\u0446": "ts",
|
|
313
|
-
"\u0447": "ch",
|
|
314
|
-
"\u0448": "sh",
|
|
315
|
-
"\u0449": "shch",
|
|
316
|
-
"\u044A": "",
|
|
317
|
-
"\u044B": "y",
|
|
318
|
-
"\u044C": "",
|
|
319
|
-
"\u044D": "e",
|
|
320
|
-
"\u044E": "yu",
|
|
321
|
-
"\u044F": "ya",
|
|
322
|
-
// Greek (basic)
|
|
323
|
-
"\u03B1": "a",
|
|
324
|
-
"\u03B2": "b",
|
|
325
|
-
"\u03B3": "g",
|
|
326
|
-
"\u03B4": "d",
|
|
327
|
-
"\u03B5": "e",
|
|
328
|
-
"\u03B6": "z",
|
|
329
|
-
"\u03B7": "i",
|
|
330
|
-
"\u03B8": "th",
|
|
331
|
-
"\u03B9": "i",
|
|
332
|
-
"\u03BA": "k",
|
|
333
|
-
"\u03BB": "l",
|
|
334
|
-
"\u03BC": "m",
|
|
335
|
-
"\u03BD": "n",
|
|
336
|
-
"\u03BE": "x",
|
|
337
|
-
"\u03BF": "o",
|
|
338
|
-
"\u03C0": "p",
|
|
339
|
-
"\u03C1": "r",
|
|
340
|
-
"\u03C3": "s",
|
|
341
|
-
"\u03C4": "t",
|
|
342
|
-
"\u03C5": "y",
|
|
343
|
-
"\u03C6": "f",
|
|
344
|
-
"\u03C7": "ch",
|
|
345
|
-
"\u03C8": "ps",
|
|
346
|
-
"\u03C9": "o"
|
|
278
|
+
const transliterate = (input) => {
|
|
279
|
+
let out = "";
|
|
280
|
+
for (const char of input) {
|
|
281
|
+
out += hasOwn(SLUG_CHAR_MAP, char) ? SLUG_CHAR_MAP[char] : char;
|
|
282
|
+
}
|
|
283
|
+
return out;
|
|
347
284
|
};
|
|
348
|
-
return
|
|
285
|
+
return transliterate(transliterate(str.toLowerCase()).normalize("NFD").replace(/[\u0300-\u036f]/g, "")).replace(/[\s\-_]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
349
286
|
}
|
|
287
|
+
var SLUG_CHAR_MAP = {
|
|
288
|
+
// Turkish
|
|
289
|
+
"\u015F": "s",
|
|
290
|
+
"\u0131": "i",
|
|
291
|
+
"\u011F": "g",
|
|
292
|
+
"\xFC": "u",
|
|
293
|
+
"\xF6": "o",
|
|
294
|
+
"\xE7": "c",
|
|
295
|
+
// Russian (Cyrillic to Latin - basic transliteration)
|
|
296
|
+
"\u0430": "a",
|
|
297
|
+
"\u0431": "b",
|
|
298
|
+
"\u0432": "v",
|
|
299
|
+
"\u0433": "g",
|
|
300
|
+
"\u0434": "d",
|
|
301
|
+
"\u0435": "e",
|
|
302
|
+
"\u0451": "yo",
|
|
303
|
+
"\u0436": "zh",
|
|
304
|
+
"\u0437": "z",
|
|
305
|
+
"\u0438": "i",
|
|
306
|
+
"\u0439": "y",
|
|
307
|
+
"\u043A": "k",
|
|
308
|
+
"\u043B": "l",
|
|
309
|
+
"\u043C": "m",
|
|
310
|
+
"\u043D": "n",
|
|
311
|
+
"\u043E": "o",
|
|
312
|
+
"\u043F": "p",
|
|
313
|
+
"\u0440": "r",
|
|
314
|
+
"\u0441": "s",
|
|
315
|
+
"\u0442": "t",
|
|
316
|
+
"\u0443": "u",
|
|
317
|
+
"\u0444": "f",
|
|
318
|
+
"\u0445": "h",
|
|
319
|
+
"\u0446": "ts",
|
|
320
|
+
"\u0447": "ch",
|
|
321
|
+
"\u0448": "sh",
|
|
322
|
+
"\u0449": "shch",
|
|
323
|
+
"\u044A": "",
|
|
324
|
+
"\u044B": "y",
|
|
325
|
+
"\u044C": "",
|
|
326
|
+
"\u044D": "e",
|
|
327
|
+
"\u044E": "yu",
|
|
328
|
+
"\u044F": "ya",
|
|
329
|
+
// Greek (basic)
|
|
330
|
+
"\u03B1": "a",
|
|
331
|
+
"\u03B2": "b",
|
|
332
|
+
"\u03B3": "g",
|
|
333
|
+
"\u03B4": "d",
|
|
334
|
+
"\u03B5": "e",
|
|
335
|
+
"\u03B6": "z",
|
|
336
|
+
"\u03B7": "i",
|
|
337
|
+
"\u03B8": "th",
|
|
338
|
+
"\u03B9": "i",
|
|
339
|
+
"\u03BA": "k",
|
|
340
|
+
"\u03BB": "l",
|
|
341
|
+
"\u03BC": "m",
|
|
342
|
+
"\u03BD": "n",
|
|
343
|
+
"\u03BE": "x",
|
|
344
|
+
"\u03BF": "o",
|
|
345
|
+
"\u03C0": "p",
|
|
346
|
+
"\u03C1": "r",
|
|
347
|
+
"\u03C3": "s",
|
|
348
|
+
"\u03C2": "s",
|
|
349
|
+
"\u03C4": "t",
|
|
350
|
+
"\u03C5": "y",
|
|
351
|
+
"\u03C6": "f",
|
|
352
|
+
"\u03C7": "ch",
|
|
353
|
+
"\u03C8": "ps",
|
|
354
|
+
"\u03C9": "o"
|
|
355
|
+
};
|
|
350
356
|
function template(str, data) {
|
|
351
357
|
return str.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
|
|
352
358
|
const keys2 = path.trim().split(".");
|
|
353
359
|
let value = data;
|
|
354
360
|
for (const key of keys2) {
|
|
355
|
-
if (value == null) {
|
|
361
|
+
if (value == null || !hasOwn(Object(value), key)) {
|
|
356
362
|
return "";
|
|
357
363
|
}
|
|
358
364
|
value = value[key];
|
|
@@ -507,87 +513,6 @@ var ScopedEventBus = class {
|
|
|
507
513
|
}
|
|
508
514
|
};
|
|
509
515
|
|
|
510
|
-
// src/errors.ts
|
|
511
|
-
var UtilsError = class extends Error {
|
|
512
|
-
code;
|
|
513
|
-
constructor(message, code) {
|
|
514
|
-
super(message);
|
|
515
|
-
this.name = "UtilsError";
|
|
516
|
-
this.code = code;
|
|
517
|
-
Error.captureStackTrace(this, this.constructor);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
var InvalidPathError = class extends UtilsError {
|
|
521
|
-
constructor(path) {
|
|
522
|
-
super(`Invalid path: ${path}`, "INVALID_PATH");
|
|
523
|
-
this.name = "InvalidPathError";
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
var CircularReferenceError = class extends UtilsError {
|
|
527
|
-
constructor() {
|
|
528
|
-
super("Circular reference detected", "CIRCULAR_REF");
|
|
529
|
-
this.name = "CircularReferenceError";
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
var TimeoutError = class extends UtilsError {
|
|
533
|
-
constructor(ms) {
|
|
534
|
-
super(`Operation timed out after ${ms}ms`, "TIMEOUT");
|
|
535
|
-
this.name = "TimeoutError";
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
var PluginAlreadyRegisteredError = class extends UtilsError {
|
|
539
|
-
constructor(name) {
|
|
540
|
-
super(`Plugin "${name}" already registered`, "PLUGIN_ALREADY_REGISTERED");
|
|
541
|
-
this.name = "PluginAlreadyRegisteredError";
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
var PluginNotFoundError = class extends UtilsError {
|
|
545
|
-
constructor(name) {
|
|
546
|
-
super(`Plugin "${name}" not found`, "PLUGIN_NOT_FOUND");
|
|
547
|
-
this.name = "PluginNotFoundError";
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
var PluginDependencyMissingError = class extends UtilsError {
|
|
551
|
-
constructor(plugin, dependency) {
|
|
552
|
-
super(`Plugin "${plugin}" requires "${dependency}" to be registered first`, "PLUGIN_DEPENDENCY_MISSING");
|
|
553
|
-
this.name = "PluginDependencyMissingError";
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
var MaxRetriesExceededError = class extends UtilsError {
|
|
557
|
-
constructor(attempts) {
|
|
558
|
-
super(`Maximum retry attempts (${attempts}) exceeded`, "MAX_RETRIES_EXCEEDED");
|
|
559
|
-
this.name = "MaxRetriesExceededError";
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
var CircularDependencyError = class extends UtilsError {
|
|
563
|
-
constructor(cycle) {
|
|
564
|
-
super(`Circular dependency detected: ${cycle.join(" -> ")}`, "CIRCULAR_DEPENDENCY");
|
|
565
|
-
this.name = "CircularDependencyError";
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
var PluginInitializationError = class extends UtilsError {
|
|
569
|
-
pluginName;
|
|
570
|
-
cause;
|
|
571
|
-
constructor(pluginName, cause) {
|
|
572
|
-
super(`Plugin "${pluginName}" failed to initialize: ${cause.message}`, "PLUGIN_INIT_FAILED");
|
|
573
|
-
this.name = "PluginInitializationError";
|
|
574
|
-
this.pluginName = pluginName;
|
|
575
|
-
this.cause = cause;
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
var KernelAlreadyInitializedError = class extends UtilsError {
|
|
579
|
-
constructor() {
|
|
580
|
-
super("Kernel is already initialized", "KERNEL_ALREADY_INITIALIZED");
|
|
581
|
-
this.name = "KernelAlreadyInitializedError";
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
var KernelInitializingError = class extends UtilsError {
|
|
585
|
-
constructor() {
|
|
586
|
-
super("Kernel is currently initializing", "KERNEL_INITIALIZING");
|
|
587
|
-
this.name = "KernelInitializingError";
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
|
|
591
516
|
// src/kernel.ts
|
|
592
517
|
var Kernel = class {
|
|
593
518
|
plugins = /* @__PURE__ */ new Map();
|
|
@@ -664,6 +589,11 @@ var Kernel = class {
|
|
|
664
589
|
this.initPromise = this.doInit();
|
|
665
590
|
try {
|
|
666
591
|
await this.initPromise;
|
|
592
|
+
} catch (error) {
|
|
593
|
+
if (this.state === "initializing") {
|
|
594
|
+
this.state = "idle";
|
|
595
|
+
}
|
|
596
|
+
throw error;
|
|
667
597
|
} finally {
|
|
668
598
|
this.initPromise = null;
|
|
669
599
|
}
|
|
@@ -671,6 +601,11 @@ var Kernel = class {
|
|
|
671
601
|
async doInit() {
|
|
672
602
|
const sortedEntries = this.topologicalSort();
|
|
673
603
|
const initializedStack = [];
|
|
604
|
+
for (const entry of sortedEntries) {
|
|
605
|
+
if (entry.state === "error" || entry.state === "destroyed") {
|
|
606
|
+
entry.state = "registered";
|
|
607
|
+
}
|
|
608
|
+
}
|
|
674
609
|
for (const entry of sortedEntries) {
|
|
675
610
|
try {
|
|
676
611
|
await this.initPlugin(entry);
|
|
@@ -907,12 +842,12 @@ var Kernel = class {
|
|
|
907
842
|
}
|
|
908
843
|
}
|
|
909
844
|
this.plugins.clear();
|
|
910
|
-
this.eventBus.removeAllListeners();
|
|
911
845
|
this.state = "destroyed";
|
|
912
846
|
this.eventBus.emit("kernel:destroyed");
|
|
847
|
+
this.eventBus.removeAllListeners();
|
|
913
848
|
}
|
|
914
849
|
};
|
|
915
850
|
|
|
916
|
-
export {
|
|
851
|
+
export { EventBus, Kernel, ScopedEventBus, array_exports as array, camelCase, capitalize, chunk, compact, entries, first, flatten, fromEntries, get, groupBy, has, kebabCase, keyBy, keys, last, merge, object_exports as object, omit, pascalCase, pick, sample, set, setMut, slugify, snakeCase, string_exports as string, template, truncate, uniq, uniqBy, values };
|
|
917
852
|
//# sourceMappingURL=index.js.map
|
|
918
853
|
//# sourceMappingURL=index.js.map
|