@oxog/utils 1.0.0
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 +44 -0
- package/LICENSE +21 -0
- package/README.md +297 -0
- package/dist/index.cjs +645 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +780 -0
- package/dist/index.d.ts +780 -0
- package/dist/index.js +611 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/async.cjs +188 -0
- package/dist/plugins/async.cjs.map +1 -0
- package/dist/plugins/async.d.cts +169 -0
- package/dist/plugins/async.d.ts +169 -0
- package/dist/plugins/async.js +182 -0
- package/dist/plugins/async.js.map +1 -0
- package/dist/plugins/deep.cjs +157 -0
- package/dist/plugins/deep.cjs.map +1 -0
- package/dist/plugins/deep.d.cts +157 -0
- package/dist/plugins/deep.d.ts +157 -0
- package/dist/plugins/deep.js +152 -0
- package/dist/plugins/deep.js.map +1 -0
- package/dist/plugins/guard.cjs +47 -0
- package/dist/plugins/guard.cjs.map +1 -0
- package/dist/plugins/guard.d.cts +213 -0
- package/dist/plugins/guard.d.ts +213 -0
- package/dist/plugins/guard.js +38 -0
- package/dist/plugins/guard.js.map +1 -0
- package/dist/plugins/transform.cjs +49 -0
- package/dist/plugins/transform.cjs.map +1 -0
- package/dist/plugins/transform.d.cts +231 -0
- package/dist/plugins/transform.d.ts +231 -0
- package/dist/plugins/transform.js +42 -0
- package/dist/plugins/transform.js.map +1 -0
- package/dist/types-XmRC5wYO.d.cts +97 -0
- package/dist/types-XmRC5wYO.d.ts +97 -0
- package/package.json +115 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import { P as Plugin } from './types-XmRC5wYO.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Safely access a deeply nested property in an object.
|
|
5
|
+
*
|
|
6
|
+
* Returns the value at the specified path, or the default value
|
|
7
|
+
* if the path doesn't exist. Supports both dot notation and array syntax.
|
|
8
|
+
*
|
|
9
|
+
* @param obj - The source object to access
|
|
10
|
+
* @param path - The path to the property (dot notation: 'a.b.c')
|
|
11
|
+
* @param defaultValue - Value to return if path doesn't exist
|
|
12
|
+
* @returns The value at path, or defaultValue if not found
|
|
13
|
+
*
|
|
14
|
+
* @example Basic usage
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const user = { name: 'Ersin', address: { city: 'Istanbul' } };
|
|
17
|
+
* get(user, 'address.city'); // 'Istanbul'
|
|
18
|
+
* get(user, 'address.zip'); // undefined
|
|
19
|
+
* get(user, 'address.zip', '00000'); // '00000'
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example With TypeScript inference
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const user = { name: 'Ersin', age: 30 };
|
|
25
|
+
* const name = get(user, 'name'); // TypeScript knows: string
|
|
26
|
+
* const age = get(user, 'age'); // TypeScript knows: number
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example With array notation
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const data = { items: [{ id: 1 }, { id: 2 }] };
|
|
32
|
+
* get(data, 'items[0].id'); // 1
|
|
33
|
+
* get(data, 'items[1].id'); // 2
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see {@link set} for setting properties
|
|
37
|
+
* @see {@link has} for checking existence
|
|
38
|
+
*/
|
|
39
|
+
declare function get<T, P extends string, D = undefined>(obj: T, path: P, defaultValue?: D): any;
|
|
40
|
+
/**
|
|
41
|
+
* Immutable property setter.
|
|
42
|
+
*
|
|
43
|
+
* Creates a new object with the value at the specified path updated.
|
|
44
|
+
* The original object is not modified.
|
|
45
|
+
*
|
|
46
|
+
* @param obj - The source object
|
|
47
|
+
* @param path - The path to update (dot notation)
|
|
48
|
+
* @param value - The value to set
|
|
49
|
+
* @returns A new object with the updated value
|
|
50
|
+
*
|
|
51
|
+
* @example Basic usage
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const user = { name: 'Ersin', age: 30 };
|
|
54
|
+
* const updated = set(user, 'age', 31);
|
|
55
|
+
* console.log(user.age); // 30 (unchanged)
|
|
56
|
+
* console.log(updated.age); // 31
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Nested path
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const user = { profile: { name: 'Ersin' } };
|
|
62
|
+
* const updated = set(user, 'profile.name', 'Ali');
|
|
63
|
+
* console.log(updated.profile.name); // 'Ali'
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see {@link get} for getting properties
|
|
67
|
+
* @see {@link setMut} for mutable version
|
|
68
|
+
*/
|
|
69
|
+
declare function set<T, P extends string>(obj: T, path: P, value: any): T;
|
|
70
|
+
/**
|
|
71
|
+
* Mutable property setter.
|
|
72
|
+
*
|
|
73
|
+
* Updates the value at the specified path by mutating the original object.
|
|
74
|
+
* Use this only when mutation is intentional.
|
|
75
|
+
*
|
|
76
|
+
* @param obj - The source object (will be mutated)
|
|
77
|
+
* @param path - The path to update (dot notation)
|
|
78
|
+
* @param value - The value to set
|
|
79
|
+
* @returns The modified object (same reference)
|
|
80
|
+
*
|
|
81
|
+
* @example Basic usage
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const user = { name: 'Ersin', age: 30 };
|
|
84
|
+
* setMut(user, 'age', 31);
|
|
85
|
+
* console.log(user.age); // 31 (mutated)
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @see {@link set} for immutable version
|
|
89
|
+
*/
|
|
90
|
+
declare function setMut<T, P extends string>(obj: T, path: P, value: any): T;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a path exists in an object.
|
|
93
|
+
*
|
|
94
|
+
* Returns true if the path resolves to a value that is not undefined.
|
|
95
|
+
* For arrays, returns true even for out-of-bounds indices.
|
|
96
|
+
*
|
|
97
|
+
* @param obj - The source object
|
|
98
|
+
* @param path - The path to check (dot notation)
|
|
99
|
+
* @returns True if path exists
|
|
100
|
+
*
|
|
101
|
+
* @example Basic usage
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const user = { name: 'Ersin', address: { city: 'Istanbul' } };
|
|
104
|
+
* has(user, 'name'); // true
|
|
105
|
+
* has(user, 'address.city'); // true
|
|
106
|
+
* has(user, 'address.country'); // false
|
|
107
|
+
* has(user, 'age'); // false
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @see {@link get} for getting properties
|
|
111
|
+
* @see {@link set} for setting properties
|
|
112
|
+
*/
|
|
113
|
+
declare function has<T, P extends string>(obj: T, path: P): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Create a new object with only the specified keys.
|
|
116
|
+
*
|
|
117
|
+
* @param obj - The source object
|
|
118
|
+
* @param keys - Array of keys to pick
|
|
119
|
+
* @returns New object with only specified keys
|
|
120
|
+
*
|
|
121
|
+
* @example Basic usage
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const user = { name: 'Ersin', age: 30, city: 'Istanbul' };
|
|
124
|
+
* pick(user, ['name', 'age']); // { name: 'Ersin', age: 30 }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link omit} for excluding keys
|
|
128
|
+
*/
|
|
129
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
130
|
+
/**
|
|
131
|
+
* Create a new object without the specified keys.
|
|
132
|
+
*
|
|
133
|
+
* @param obj - The source object
|
|
134
|
+
* @param keys - Array of keys to omit
|
|
135
|
+
* @returns New object without specified keys
|
|
136
|
+
*
|
|
137
|
+
* @example Basic usage
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const user = { name: 'Ersin', age: 30, city: 'Istanbul' };
|
|
140
|
+
* omit(user, ['age']); // { name: 'Ersin', city: 'Istanbul' }
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @see {@link pick} for selecting keys
|
|
144
|
+
*/
|
|
145
|
+
declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
146
|
+
/**
|
|
147
|
+
* Safely merge objects together.
|
|
148
|
+
*
|
|
149
|
+
* Creates a new object with properties from all sources merged into target.
|
|
150
|
+
* Prototype pollution protection: filters out __proto__, constructor, prototype.
|
|
151
|
+
*
|
|
152
|
+
* @param target - Target object
|
|
153
|
+
* @param sources - Source objects to merge
|
|
154
|
+
* @returns New merged object
|
|
155
|
+
*
|
|
156
|
+
* @example Basic usage
|
|
157
|
+
* ```typescript
|
|
158
|
+
* merge({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
|
|
159
|
+
* merge({ a: 1 }, { a: 2 }); // { a: 2 } (later sources override)
|
|
160
|
+
* merge({ a: 1 }, { b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example Prototype pollution protection
|
|
164
|
+
* ```typescript
|
|
165
|
+
* merge({}, { __proto__: { evil: true } }); // {} - filtered!
|
|
166
|
+
* merge({}, { constructor: { evil: true } }); // {} - filtered!
|
|
167
|
+
* merge({}, { prototype: { evil: true } }); // {} - filtered!
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
declare function merge<T extends object, S extends object>(target: T, ...sources: S[]): T & S;
|
|
171
|
+
/**
|
|
172
|
+
* Type-safe Object.keys().
|
|
173
|
+
*
|
|
174
|
+
* Returns array of object's own enumerable property names with proper typing.
|
|
175
|
+
*
|
|
176
|
+
* @param obj - The source object
|
|
177
|
+
* @returns Array of keys
|
|
178
|
+
*
|
|
179
|
+
* @example Basic usage
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const user = { name: 'Ersin', age: 30 };
|
|
182
|
+
* keys(user); // ['name', 'age'] (TypeScript knows these are 'name' | 'age')
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @see {@link values} for getting values
|
|
186
|
+
* @see {@link entries} for getting key-value pairs
|
|
187
|
+
*/
|
|
188
|
+
declare function keys<T extends object>(obj: T): Array<keyof T>;
|
|
189
|
+
/**
|
|
190
|
+
* Type-safe Object.values().
|
|
191
|
+
*
|
|
192
|
+
* Returns array of object's own enumerable property values with proper typing.
|
|
193
|
+
*
|
|
194
|
+
* @param obj - The source object
|
|
195
|
+
* @returns Array of values
|
|
196
|
+
*
|
|
197
|
+
* @example Basic usage
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const user = { name: 'Ersin', age: 30 };
|
|
200
|
+
* values(user); // ['Ersin', 30] (TypeScript knows these are string | number)
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @see {@link keys} for getting keys
|
|
204
|
+
* @see {@link entries} for getting key-value pairs
|
|
205
|
+
*/
|
|
206
|
+
declare function values<T extends object>(obj: T): Array<T[keyof T]>;
|
|
207
|
+
/**
|
|
208
|
+
* Type-safe Object.entries().
|
|
209
|
+
*
|
|
210
|
+
* Returns array of object's own enumerable string-keyed property [key, value] pairs.
|
|
211
|
+
*
|
|
212
|
+
* @param obj - The source object
|
|
213
|
+
* @returns Array of [key, value] tuples
|
|
214
|
+
*
|
|
215
|
+
* @example Basic usage
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const user = { name: 'Ersin', age: 30 };
|
|
218
|
+
* entries(user); // [['name', 'Ersin'], ['age', 30]]
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @see {@link keys} for getting keys
|
|
222
|
+
* @see {@link values} for getting values
|
|
223
|
+
*/
|
|
224
|
+
declare function entries<T extends object>(obj: T): Array<[keyof T, T[keyof T]]>;
|
|
225
|
+
/**
|
|
226
|
+
* Type-safe Object.fromEntries().
|
|
227
|
+
*
|
|
228
|
+
* Creates an object from key-value pairs.
|
|
229
|
+
*
|
|
230
|
+
* @param entries - Array of [key, value] tuples
|
|
231
|
+
* @returns New object created from entries
|
|
232
|
+
*
|
|
233
|
+
* @example Basic usage
|
|
234
|
+
* ```typescript
|
|
235
|
+
* fromEntries([['a', 1], ['b', 2]]); // { a: 1, b: 2 }
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @see {@link entries} for getting key-value pairs
|
|
239
|
+
*/
|
|
240
|
+
declare function fromEntries<V>(entries: Iterable<[PropertyKey, V]>): Record<string, V>;
|
|
241
|
+
|
|
242
|
+
declare const object_entries: typeof entries;
|
|
243
|
+
declare const object_fromEntries: typeof fromEntries;
|
|
244
|
+
declare const object_get: typeof get;
|
|
245
|
+
declare const object_has: typeof has;
|
|
246
|
+
declare const object_keys: typeof keys;
|
|
247
|
+
declare const object_merge: typeof merge;
|
|
248
|
+
declare const object_omit: typeof omit;
|
|
249
|
+
declare const object_pick: typeof pick;
|
|
250
|
+
declare const object_set: typeof set;
|
|
251
|
+
declare const object_setMut: typeof setMut;
|
|
252
|
+
declare const object_values: typeof values;
|
|
253
|
+
declare namespace object {
|
|
254
|
+
export { object_entries as entries, object_fromEntries as fromEntries, object_get as get, object_has as has, object_keys as keys, object_merge as merge, object_omit as omit, object_pick as pick, object_set as set, object_setMut as setMut, object_values as values };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Group array items by a key or function.
|
|
259
|
+
*
|
|
260
|
+
* Creates an object where keys are the result of grouping function
|
|
261
|
+
* and values are arrays of items that belong to that group.
|
|
262
|
+
*
|
|
263
|
+
* @param arr - The array to group
|
|
264
|
+
* @param key - Property name or grouping function
|
|
265
|
+
* @returns Object with grouped items
|
|
266
|
+
*
|
|
267
|
+
* @example Group by property
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const users = [
|
|
270
|
+
* { id: 1, name: 'Alice', role: 'admin' },
|
|
271
|
+
* { id: 2, name: 'Bob', role: 'user' },
|
|
272
|
+
* { id: 3, name: 'Charlie', role: 'user' }
|
|
273
|
+
* ];
|
|
274
|
+
* groupBy(users, 'role');
|
|
275
|
+
* // { admin: [{ id: 1, name: 'Alice', role: 'admin' }],
|
|
276
|
+
* // user: [{ id: 2, name: 'Bob', role: 'user' }, { id: 3, name: 'Charlie', role: 'user' }] }
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @example Group by function
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const numbers = [1, 2, 3, 4, 5, 6];
|
|
282
|
+
* groupBy(numbers, (n) => n % 2 === 0 ? 'even' : 'odd');
|
|
283
|
+
* // { even: [2, 4, 6], odd: [1, 3, 5] }
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @see {@link keyBy} for indexing by property
|
|
287
|
+
*/
|
|
288
|
+
declare function groupBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string)): Record<string, T[]>;
|
|
289
|
+
/**
|
|
290
|
+
* Create an object keyed by a property value.
|
|
291
|
+
*
|
|
292
|
+
* Creates a lookup object where keys are property values and
|
|
293
|
+
* values are the original array items.
|
|
294
|
+
*
|
|
295
|
+
* @param arr - The array to index
|
|
296
|
+
* @param key - Property name or key function
|
|
297
|
+
* @returns Object indexed by key
|
|
298
|
+
*
|
|
299
|
+
* @example Basic usage
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const users = [
|
|
302
|
+
* { id: 1, name: 'Alice' },
|
|
303
|
+
* { id: 2, name: 'Bob' },
|
|
304
|
+
* { id: 3, name: 'Charlie' }
|
|
305
|
+
* ];
|
|
306
|
+
* keyBy(users, 'id');
|
|
307
|
+
* // { 1: { id: 1, name: 'Alice' }, 2: { id: 2, name: 'Bob' }, 3: { id: 3, name: 'Charlie' } }
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* @example With function
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const users = [{ id: 1 }, { id: 2 }];
|
|
313
|
+
* keyBy(users, (u) => `user_${u.id}`);
|
|
314
|
+
* // { user_1: { id: 1 }, user_2: { id: 2 } }
|
|
315
|
+
* ```
|
|
316
|
+
*
|
|
317
|
+
* @see {@link groupBy} for grouping
|
|
318
|
+
*/
|
|
319
|
+
declare function keyBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string)): Record<string, T>;
|
|
320
|
+
/**
|
|
321
|
+
* Split array into chunks of specified size.
|
|
322
|
+
*
|
|
323
|
+
* @param arr - The array to chunk
|
|
324
|
+
* @param size - Size of each chunk
|
|
325
|
+
* @returns Array of chunks
|
|
326
|
+
*
|
|
327
|
+
* @example Basic usage
|
|
328
|
+
* ```typescript
|
|
329
|
+
* chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
330
|
+
* chunk([1, 2, 3, 4, 5], 3); // [[1, 2, 3], [4, 5]]
|
|
331
|
+
* ```
|
|
332
|
+
*
|
|
333
|
+
* @example Edge cases
|
|
334
|
+
* ```typescript
|
|
335
|
+
* chunk([1, 2, 3], 1); // [[1], [2], [3]]
|
|
336
|
+
* chunk([1, 2, 3], 5); // [[1, 2, 3]]
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
340
|
+
/**
|
|
341
|
+
* Remove duplicate values from array (shallow comparison).
|
|
342
|
+
*
|
|
343
|
+
* @param arr - The array to deduplicate
|
|
344
|
+
* @returns New array without duplicates
|
|
345
|
+
*
|
|
346
|
+
* @example Basic usage
|
|
347
|
+
* ```typescript
|
|
348
|
+
* uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
|
|
349
|
+
* uniq(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* @see {@link uniqBy} for key-based deduplication
|
|
353
|
+
*/
|
|
354
|
+
declare function uniq<T>(arr: T[]): T[];
|
|
355
|
+
/**
|
|
356
|
+
* Remove duplicate values based on a key or function.
|
|
357
|
+
*
|
|
358
|
+
* @param arr - The array to deduplicate
|
|
359
|
+
* @param key - Property name or key function
|
|
360
|
+
* @returns New array without duplicates
|
|
361
|
+
*
|
|
362
|
+
* @example By property
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const users = [
|
|
365
|
+
* { id: 1, name: 'Alice' },
|
|
366
|
+
* { id: 2, name: 'Bob' },
|
|
367
|
+
* { id: 1, name: 'Alice Duplicate' }
|
|
368
|
+
* ];
|
|
369
|
+
* uniqBy(users, 'id');
|
|
370
|
+
* // [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @example By function
|
|
374
|
+
* ```typescript
|
|
375
|
+
* const users = [
|
|
376
|
+
* { id: 1, name: 'Alice' },
|
|
377
|
+
* { id: 2, name: 'Bob' },
|
|
378
|
+
* { id: 1, name: 'Alice Duplicate' }
|
|
379
|
+
* ];
|
|
380
|
+
* uniqBy(users, (u) => u.id);
|
|
381
|
+
* // [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* @see {@link uniq} for simple deduplication
|
|
385
|
+
*/
|
|
386
|
+
declare function uniqBy<T, K extends keyof T>(arr: T[], key: K | ((item: T) => string)): T[];
|
|
387
|
+
/**
|
|
388
|
+
* Flatten nested arrays up to specified depth.
|
|
389
|
+
*
|
|
390
|
+
* @param arr - The array to flatten
|
|
391
|
+
* @param depth - Maximum depth to flatten (default: 1)
|
|
392
|
+
* @returns Flattened array
|
|
393
|
+
*
|
|
394
|
+
* @example Basic usage
|
|
395
|
+
* ```typescript
|
|
396
|
+
* flatten([[1, 2], [3, 4]]); // [1, 2, 3, 4]
|
|
397
|
+
* flatten([[1, 2], [3, [4, 5]]]); // [1, 2, 3, [4, 5]]
|
|
398
|
+
* ```
|
|
399
|
+
*
|
|
400
|
+
* @example With depth
|
|
401
|
+
* ```typescript
|
|
402
|
+
* flatten([[1, 2], [3, [4, 5]]], 2); // [1, 2, 3, 4, 5]
|
|
403
|
+
* flatten([[[1, 2]], [[3, 4]]], 2); // [[1, 2], [3, 4]]
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
declare function flatten<T>(arr: T[], depth?: number): any[];
|
|
407
|
+
/**
|
|
408
|
+
* Remove falsy values from array.
|
|
409
|
+
*
|
|
410
|
+
* Falsy values: false, 0, '', null, undefined, NaN
|
|
411
|
+
*
|
|
412
|
+
* @param arr - The array to compact
|
|
413
|
+
* @returns New array without falsy values
|
|
414
|
+
*
|
|
415
|
+
* @example Basic usage
|
|
416
|
+
* ```typescript
|
|
417
|
+
* compact([0, 1, false, 2, '', 3, null, 4, undefined, 5, NaN, 6]);
|
|
418
|
+
* // [1, 2, 3, 4, 5, 6]
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
declare function compact<T>(arr: T[]): T[];
|
|
422
|
+
/**
|
|
423
|
+
* Get first n elements from array.
|
|
424
|
+
*
|
|
425
|
+
* @param arr - The source array
|
|
426
|
+
* @param n - Number of elements to get (default: 1)
|
|
427
|
+
* @returns First n elements, or single element if n=1
|
|
428
|
+
*
|
|
429
|
+
* @example Get first element
|
|
430
|
+
* ```typescript
|
|
431
|
+
* first([1, 2, 3]); // 1
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @example Get first n elements
|
|
435
|
+
* ```typescript
|
|
436
|
+
* first([1, 2, 3, 4, 5], 3); // [1, 2, 3]
|
|
437
|
+
* ```
|
|
438
|
+
*
|
|
439
|
+
* @example Edge cases
|
|
440
|
+
* ```typescript
|
|
441
|
+
* first([]); // undefined
|
|
442
|
+
* first([1], 5); // [1]
|
|
443
|
+
* ```
|
|
444
|
+
*
|
|
445
|
+
* @see {@link last} for getting last elements
|
|
446
|
+
*/
|
|
447
|
+
declare function first<T>(arr: T[], n?: number): T | T[] | undefined;
|
|
448
|
+
/**
|
|
449
|
+
* Get last n elements from array.
|
|
450
|
+
*
|
|
451
|
+
* @param arr - The source array
|
|
452
|
+
* @param n - Number of elements to get (default: 1)
|
|
453
|
+
* @returns Last n elements, or single element if n=1
|
|
454
|
+
*
|
|
455
|
+
* @example Get last element
|
|
456
|
+
* ```typescript
|
|
457
|
+
* last([1, 2, 3]); // 3
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @example Get last n elements
|
|
461
|
+
* ```typescript
|
|
462
|
+
* last([1, 2, 3, 4, 5], 3); // [3, 4, 5]
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* @example Edge cases
|
|
466
|
+
* ```typescript
|
|
467
|
+
* last([]); // undefined
|
|
468
|
+
* last([1], 5); // [1]
|
|
469
|
+
* ```
|
|
470
|
+
*
|
|
471
|
+
* @see {@link first} for getting first elements
|
|
472
|
+
*/
|
|
473
|
+
declare function last<T>(arr: T[], n?: number): T | T[] | undefined;
|
|
474
|
+
/**
|
|
475
|
+
* Get a random sample from array.
|
|
476
|
+
*
|
|
477
|
+
* @param arr - The source array
|
|
478
|
+
* @param n - Number of items to sample (default: 1)
|
|
479
|
+
* @returns Random sample(s)
|
|
480
|
+
*
|
|
481
|
+
* @example Get one random element
|
|
482
|
+
* ```typescript
|
|
483
|
+
* const arr = [1, 2, 3, 4, 5];
|
|
484
|
+
* sample(arr); // Random element (e.g., 3)
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
487
|
+
* @example Get multiple random elements
|
|
488
|
+
* ```typescript
|
|
489
|
+
* const arr = [1, 2, 3, 4, 5];
|
|
490
|
+
* sample(arr, 2); // Two random elements (e.g., [3, 1])
|
|
491
|
+
* ```
|
|
492
|
+
*
|
|
493
|
+
* @example Edge cases
|
|
494
|
+
* ```typescript
|
|
495
|
+
* sample([]); // []
|
|
496
|
+
* sample([1], 5); // [1]
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
declare function sample<T>(arr: T[], n?: number): T[];
|
|
500
|
+
|
|
501
|
+
declare const array_chunk: typeof chunk;
|
|
502
|
+
declare const array_compact: typeof compact;
|
|
503
|
+
declare const array_first: typeof first;
|
|
504
|
+
declare const array_flatten: typeof flatten;
|
|
505
|
+
declare const array_groupBy: typeof groupBy;
|
|
506
|
+
declare const array_keyBy: typeof keyBy;
|
|
507
|
+
declare const array_last: typeof last;
|
|
508
|
+
declare const array_sample: typeof sample;
|
|
509
|
+
declare const array_uniq: typeof uniq;
|
|
510
|
+
declare const array_uniqBy: typeof uniqBy;
|
|
511
|
+
declare namespace array {
|
|
512
|
+
export { array_chunk as chunk, array_compact as compact, array_first as first, array_flatten as flatten, array_groupBy as groupBy, array_keyBy as keyBy, array_last as last, array_sample as sample, array_uniq as uniq, array_uniqBy as uniqBy };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Convert string to camelCase.
|
|
517
|
+
*
|
|
518
|
+
* @param str - String to convert
|
|
519
|
+
* @returns camelCase string
|
|
520
|
+
*
|
|
521
|
+
* @example Basic usage
|
|
522
|
+
* ```typescript
|
|
523
|
+
* camelCase('hello-world'); // 'helloWorld'
|
|
524
|
+
* camelCase('hello_world'); // 'helloWorld'
|
|
525
|
+
* camelCase('hello world'); // 'helloWorld'
|
|
526
|
+
* camelCase('Hello World'); // 'helloWorld'
|
|
527
|
+
* camelCase('HelloWorld'); // 'helloWorld'
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @see {@link kebabCase} for kebab-case conversion
|
|
531
|
+
* @see {@link snakeCase} for snake_case conversion
|
|
532
|
+
* @see {@link pascalCase} for PascalCase conversion
|
|
533
|
+
*/
|
|
534
|
+
declare function camelCase(str: string): string;
|
|
535
|
+
/**
|
|
536
|
+
* Convert string to kebab-case.
|
|
537
|
+
*
|
|
538
|
+
* @param str - String to convert
|
|
539
|
+
* @returns kebab-case string
|
|
540
|
+
*
|
|
541
|
+
* @example Basic usage
|
|
542
|
+
* ```typescript
|
|
543
|
+
* kebabCase('helloWorld'); // 'hello-world'
|
|
544
|
+
* kebabCase('hello_world'); // 'hello-world'
|
|
545
|
+
* kebabCase('hello world'); // 'hello-world'
|
|
546
|
+
* kebabCase('HelloWorld'); // 'hello-world'
|
|
547
|
+
* ```
|
|
548
|
+
*
|
|
549
|
+
* @see {@link camelCase} for camelCase conversion
|
|
550
|
+
* @see {@link snakeCase} for snake_case conversion
|
|
551
|
+
* @see {@link pascalCase} for PascalCase conversion
|
|
552
|
+
*/
|
|
553
|
+
declare function kebabCase(str: string): string;
|
|
554
|
+
/**
|
|
555
|
+
* Convert string to snake_case.
|
|
556
|
+
*
|
|
557
|
+
* @param str - String to convert
|
|
558
|
+
* @returns snake_case string
|
|
559
|
+
*
|
|
560
|
+
* @example Basic usage
|
|
561
|
+
* ```typescript
|
|
562
|
+
* snakeCase('helloWorld'); // 'hello_world'
|
|
563
|
+
* snakeCase('hello-world'); // 'hello_world'
|
|
564
|
+
* snakeCase('hello world'); // 'hello_world'
|
|
565
|
+
* snakeCase('HelloWorld'); // 'hello_world'
|
|
566
|
+
* ```
|
|
567
|
+
*
|
|
568
|
+
* @see {@link camelCase} for camelCase conversion
|
|
569
|
+
* @see {@link kebabCase} for kebab-case conversion
|
|
570
|
+
* @see {@link pascalCase} for PascalCase conversion
|
|
571
|
+
*/
|
|
572
|
+
declare function snakeCase(str: string): string;
|
|
573
|
+
/**
|
|
574
|
+
* Convert string to PascalCase.
|
|
575
|
+
*
|
|
576
|
+
* @param str - String to convert
|
|
577
|
+
* @returns PascalCase string
|
|
578
|
+
*
|
|
579
|
+
* @example Basic usage
|
|
580
|
+
* ```typescript
|
|
581
|
+
* pascalCase('hello-world'); // 'HelloWorld'
|
|
582
|
+
* pascalCase('hello_world'); // 'HelloWorld'
|
|
583
|
+
* pascalCase('hello world'); // 'HelloWorld'
|
|
584
|
+
* pascalCase('helloWorld'); // 'HelloWorld'
|
|
585
|
+
* ```
|
|
586
|
+
*
|
|
587
|
+
* @see {@link camelCase} for camelCase conversion
|
|
588
|
+
* @see {@link kebabCase} for kebab-case conversion
|
|
589
|
+
* @see {@link snakeCase} for snake_case conversion
|
|
590
|
+
*/
|
|
591
|
+
declare function pascalCase(str: string): string;
|
|
592
|
+
/**
|
|
593
|
+
* Capitalize first letter of string.
|
|
594
|
+
*
|
|
595
|
+
* @param str - String to capitalize
|
|
596
|
+
* @returns Capitalized string
|
|
597
|
+
*
|
|
598
|
+
* @example Basic usage
|
|
599
|
+
* ```typescript
|
|
600
|
+
* capitalize('hello'); // 'Hello'
|
|
601
|
+
* capitalize('hello world'); // 'Hello world'
|
|
602
|
+
* capitalize('HELLO'); // 'HELLO'
|
|
603
|
+
* capitalize(''); // ''
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
declare function capitalize(str: string): string;
|
|
607
|
+
/**
|
|
608
|
+
* Truncate string to specified length with optional suffix.
|
|
609
|
+
*
|
|
610
|
+
* @param str - String to truncate
|
|
611
|
+
* @param length - Number of characters to keep before adding suffix
|
|
612
|
+
* @param suffix - Suffix to append when truncated (default: '...')
|
|
613
|
+
* @returns Truncated string
|
|
614
|
+
*
|
|
615
|
+
* @example Basic usage
|
|
616
|
+
* ```typescript
|
|
617
|
+
* truncate('Hello World', 5); // 'Hello...'
|
|
618
|
+
* truncate('Hello World', 8); // 'Hello Wo...'
|
|
619
|
+
* truncate('Hello', 10); // 'Hello'
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* @example With custom suffix
|
|
623
|
+
* ```typescript
|
|
624
|
+
* truncate('Hello World', 5, '---'); // 'Hello---'
|
|
625
|
+
* truncate('Hello World', 8, ' [more]'); // 'Hello Wo [more]'
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
declare function truncate(str: string, length: number, suffix?: string): string;
|
|
629
|
+
/**
|
|
630
|
+
* Convert string to URL-safe slug with Turkish/Unicode support.
|
|
631
|
+
*
|
|
632
|
+
* @param str - String to slugify
|
|
633
|
+
* @returns URL-safe slug
|
|
634
|
+
*
|
|
635
|
+
* @example Basic usage
|
|
636
|
+
* ```typescript
|
|
637
|
+
* slugify('Hello World'); // 'hello-world'
|
|
638
|
+
* slugify('Hello World!'); // 'hello-world'
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* @example Turkish characters
|
|
642
|
+
* ```typescript
|
|
643
|
+
* slugify('Türkçe Başlık'); // 'turkce-baslik'
|
|
644
|
+
* slugify('Çorum'); // 'corum'
|
|
645
|
+
* slugify('İstanbul'); // 'istanbul'
|
|
646
|
+
* ```
|
|
647
|
+
*
|
|
648
|
+
* @example Unicode support
|
|
649
|
+
* ```typescript
|
|
650
|
+
* slugify('Привет мир'); // 'privet-mir'
|
|
651
|
+
* slugify('Café au lait'); // 'cafe-au-lait'
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
declare function slugify(str: string): string;
|
|
655
|
+
/**
|
|
656
|
+
* Simple string interpolation with template variables.
|
|
657
|
+
*
|
|
658
|
+
* @param str - Template string with {{variable}} placeholders
|
|
659
|
+
* @param data - Object with variable values
|
|
660
|
+
* @returns Interpolated string
|
|
661
|
+
*
|
|
662
|
+
* @example Basic usage
|
|
663
|
+
* ```typescript
|
|
664
|
+
* template('Hello {{name}}!', { name: 'World' }); // 'Hello World!'
|
|
665
|
+
* template('{{greeting}}, {{name}}!', { greeting: 'Hello', name: 'Alice' }); // 'Hello, Alice!'
|
|
666
|
+
* ```
|
|
667
|
+
*
|
|
668
|
+
* @example With nested objects
|
|
669
|
+
* ```typescript
|
|
670
|
+
* template('Hello {{user.name}}!', { user: { name: 'Alice' } }); // 'Hello Alice!'
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* @example Missing variables
|
|
674
|
+
* ```typescript
|
|
675
|
+
* template('Hello {{name}}!', {}); // 'Hello !'
|
|
676
|
+
* template('Hello {{user.name}}!', { user: {} }); // 'Hello !'
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
declare function template(str: string, data: Record<string, any>): string;
|
|
680
|
+
|
|
681
|
+
declare const string_camelCase: typeof camelCase;
|
|
682
|
+
declare const string_capitalize: typeof capitalize;
|
|
683
|
+
declare const string_kebabCase: typeof kebabCase;
|
|
684
|
+
declare const string_pascalCase: typeof pascalCase;
|
|
685
|
+
declare const string_slugify: typeof slugify;
|
|
686
|
+
declare const string_snakeCase: typeof snakeCase;
|
|
687
|
+
declare const string_template: typeof template;
|
|
688
|
+
declare const string_truncate: typeof truncate;
|
|
689
|
+
declare namespace string {
|
|
690
|
+
export { string_camelCase as camelCase, string_capitalize as capitalize, string_kebabCase as kebabCase, string_pascalCase as pascalCase, string_slugify as slugify, string_snakeCase as snakeCase, string_template as template, string_truncate as truncate };
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Micro-kernel for plugin system.
|
|
695
|
+
*
|
|
696
|
+
* Manages plugin registration, initialization, and lifecycle.
|
|
697
|
+
* Provides event bus for inter-plugin communication.
|
|
698
|
+
*/
|
|
699
|
+
declare class Kernel<TContext = unknown> {
|
|
700
|
+
private plugins;
|
|
701
|
+
private context;
|
|
702
|
+
private eventBus;
|
|
703
|
+
/**
|
|
704
|
+
* Register a plugin with the kernel.
|
|
705
|
+
*
|
|
706
|
+
* @param plugin - Plugin to register
|
|
707
|
+
* @throws {PluginAlreadyRegisteredError} If plugin name already exists
|
|
708
|
+
* @throws {PluginDependencyMissingError} If plugin dependencies are not met
|
|
709
|
+
*/
|
|
710
|
+
register(plugin: Plugin<TContext>): void;
|
|
711
|
+
/**
|
|
712
|
+
* Initialize all registered plugins.
|
|
713
|
+
*
|
|
714
|
+
* Calls onInit() for each plugin that has it.
|
|
715
|
+
* Plugins are initialized in the order they were registered.
|
|
716
|
+
*/
|
|
717
|
+
init(): Promise<void>;
|
|
718
|
+
/**
|
|
719
|
+
* Unregister a plugin.
|
|
720
|
+
*
|
|
721
|
+
* @param name - Plugin name to unregister
|
|
722
|
+
* @throws {PluginNotFoundError} If plugin doesn't exist
|
|
723
|
+
*/
|
|
724
|
+
unregister(name: string): void;
|
|
725
|
+
/**
|
|
726
|
+
* Get the shared context object.
|
|
727
|
+
*
|
|
728
|
+
* @returns Shared context
|
|
729
|
+
*/
|
|
730
|
+
getContext(): TContext;
|
|
731
|
+
/**
|
|
732
|
+
* Get a registered plugin by name.
|
|
733
|
+
*
|
|
734
|
+
* @param name - Plugin name
|
|
735
|
+
* @returns Plugin instance or undefined
|
|
736
|
+
*/
|
|
737
|
+
getPlugin(name: string): Plugin<TContext> | undefined;
|
|
738
|
+
/**
|
|
739
|
+
* Check if a plugin is registered.
|
|
740
|
+
*
|
|
741
|
+
* @param name - Plugin name
|
|
742
|
+
* @returns True if plugin exists
|
|
743
|
+
*/
|
|
744
|
+
hasPlugin(name: string): boolean;
|
|
745
|
+
/**
|
|
746
|
+
* Get list of all registered plugin names.
|
|
747
|
+
*
|
|
748
|
+
* @returns Array of plugin names
|
|
749
|
+
*/
|
|
750
|
+
listPlugins(): string[];
|
|
751
|
+
/**
|
|
752
|
+
* Register an event listener.
|
|
753
|
+
*
|
|
754
|
+
* @param event - Event name
|
|
755
|
+
* @param handler - Event handler function
|
|
756
|
+
*/
|
|
757
|
+
on(event: string, handler: (...args: any[]) => void): void;
|
|
758
|
+
/**
|
|
759
|
+
* Unregister an event listener.
|
|
760
|
+
*
|
|
761
|
+
* @param event - Event name
|
|
762
|
+
* @param handler - Event handler function
|
|
763
|
+
*/
|
|
764
|
+
off(event: string, handler: (...args: any[]) => void): void;
|
|
765
|
+
/**
|
|
766
|
+
* Emit an event.
|
|
767
|
+
*
|
|
768
|
+
* @param event - Event name
|
|
769
|
+
* @param args - Event data
|
|
770
|
+
*/
|
|
771
|
+
emit(event: string, ...args: any[]): void;
|
|
772
|
+
/**
|
|
773
|
+
* Destroy the kernel and all plugins.
|
|
774
|
+
*
|
|
775
|
+
* Unregisters all plugins and cleans up resources.
|
|
776
|
+
*/
|
|
777
|
+
destroy(): Promise<void>;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export { Kernel, Plugin, array, camelCase, capitalize, chunk, compact, entries, first, flatten, fromEntries, get, groupBy, has, kebabCase, keyBy, keys, last, merge, object, omit, pascalCase, pick, sample, set, setMut, slugify, snakeCase, string, template, truncate, uniq, uniqBy, values };
|