indusagi-coding-agent 0.1.22 → 0.1.24
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 +72 -11
- package/README.md +2 -36
- package/dist/cli/args.d.ts +117 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +231 -64
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +58 -2
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +130 -12
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts +70 -2
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +240 -15
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/list-models.d.ts +63 -3
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +202 -27
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/login-handler.d.ts +82 -8
- package/dist/cli/login-handler.d.ts.map +1 -1
- package/dist/cli/login-handler.js +410 -77
- package/dist/cli/login-handler.js.map +1 -1
- package/dist/cli/session-picker.d.ts +74 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +236 -12
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/core/agent-session.d.ts +214 -9
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +214 -9
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +302 -12
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +302 -12
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/diagnostics.d.ts +191 -0
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js +142 -0
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/event-bus.d.ts +146 -0
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js +93 -0
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts +4 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +4 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts +128 -0
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +128 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +4 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +4 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/keybindings.d.ts +142 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +142 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +98 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +98 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +99 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +99 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +0 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +127 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +125 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/subagents.js.map +1 -1
- package/dist/core/tools/bash.d.ts +391 -11
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +269 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +284 -6
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +238 -0
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +169 -5
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +136 -0
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +285 -5
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +247 -0
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +0 -18
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -23
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +6 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +6 -0
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +308 -7
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +231 -0
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/webfetch.d.ts +118 -3
- package/dist/core/tools/webfetch.d.ts.map +1 -1
- package/dist/core/tools/webfetch.js +118 -3
- package/dist/core/tools/webfetch.js.map +1 -1
- package/dist/core/tools/websearch.d.ts +130 -3
- package/dist/core/tools/websearch.d.ts.map +1 -1
- package/dist/core/tools/websearch.js +130 -3
- package/dist/core/tools/websearch.js.map +1 -1
- package/dist/core/tools/write.d.ts +251 -5
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +210 -0
- package/dist/core/tools/write.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +164 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +164 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +297 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +297 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +251 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +186 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +186 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1567 -13
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1567 -13
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +422 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +422 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +538 -5
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +538 -5
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +921 -8
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +921 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +802 -9
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +802 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +356 -3
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +356 -3
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/shared.d.ts +386 -0
- package/dist/modes/shared.d.ts.map +1 -0
- package/dist/modes/shared.js +543 -0
- package/dist/modes/shared.js.map +1 -0
- package/dist/utils/array.d.ts +389 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/array.js +585 -0
- package/dist/utils/array.js.map +1 -0
- package/dist/utils/color-formatter.d.ts +318 -0
- package/dist/utils/color-formatter.d.ts.map +1 -0
- package/dist/utils/color-formatter.js +442 -0
- package/dist/utils/color-formatter.js.map +1 -0
- package/dist/utils/data-transformer.d.ts +326 -0
- package/dist/utils/data-transformer.d.ts.map +1 -0
- package/dist/utils/data-transformer.js +512 -0
- package/dist/utils/data-transformer.js.map +1 -0
- package/dist/utils/date-formatter.d.ts +281 -0
- package/dist/utils/date-formatter.d.ts.map +1 -0
- package/dist/utils/date-formatter.js +503 -0
- package/dist/utils/date-formatter.js.map +1 -0
- package/dist/utils/error-handler.d.ts +541 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +726 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/file-operations.d.ts +297 -0
- package/dist/utils/file-operations.d.ts.map +1 -0
- package/dist/utils/file-operations.js +505 -0
- package/dist/utils/file-operations.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +268 -6
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +500 -21
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/json-formatter.d.ts +259 -0
- package/dist/utils/json-formatter.d.ts.map +1 -0
- package/dist/utils/json-formatter.js +517 -0
- package/dist/utils/json-formatter.js.map +1 -0
- package/dist/utils/logger.d.ts +176 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +346 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown-formatter.d.ts +211 -0
- package/dist/utils/markdown-formatter.d.ts.map +1 -0
- package/dist/utils/markdown-formatter.js +482 -0
- package/dist/utils/markdown-formatter.js.map +1 -0
- package/dist/utils/path-validator.d.ts +603 -0
- package/dist/utils/path-validator.d.ts.map +1 -0
- package/dist/utils/path-validator.js +870 -0
- package/dist/utils/path-validator.js.map +1 -0
- package/dist/utils/string-formatter.d.ts +609 -0
- package/dist/utils/string-formatter.d.ts.map +1 -0
- package/dist/utils/string-formatter.js +806 -0
- package/dist/utils/string-formatter.js.map +1 -0
- package/dist/utils/type-guards.d.ts +629 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +662 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/docs/COMPLETE-GUIDE.md +300 -0
- package/docs/MODES-ARCHITECTURE.md +565 -0
- package/docs/PRINT-MODE-GUIDE.md +456 -0
- package/docs/README.md +1 -2
- package/docs/RPC-GUIDE.md +705 -0
- package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +647 -0
- package/docs/UTILS-MODULE-OVERVIEW.md +1480 -0
- package/docs/UTILS-QA-CHECKLIST.md +1061 -0
- package/docs/UTILS-USAGE-GUIDE.md +1419 -0
- package/package.json +3 -3
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Advanced array manipulation utilities with functional programming patterns
|
|
3
|
+
*
|
|
4
|
+
* This module provides:
|
|
5
|
+
* - Array grouping and partitioning
|
|
6
|
+
* - Unique value extraction
|
|
7
|
+
* - Flattening and chunking
|
|
8
|
+
* - Sorting and searching
|
|
9
|
+
* - Array zipping and pairing
|
|
10
|
+
* - Filtering and transforming
|
|
11
|
+
* - Set operations (union, intersection, difference)
|
|
12
|
+
* - Performance optimized with O(n) complexity notes
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { groupBy, unique, flatten, chunk, sortBy } from './array';
|
|
16
|
+
*
|
|
17
|
+
* const items = [{ id: 1, type: 'A' }, { id: 2, type: 'B' }];
|
|
18
|
+
* const grouped = groupBy(items, item => item.type);
|
|
19
|
+
* const flattened = flatten([1, [2, [3, [4]]]]);
|
|
20
|
+
*
|
|
21
|
+
* @author indusagi
|
|
22
|
+
* @version 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Group array items by key function
|
|
26
|
+
* @param items - Array to group
|
|
27
|
+
* @param keyFn - Function to determine grouping key
|
|
28
|
+
* @returns Object with grouped arrays
|
|
29
|
+
*
|
|
30
|
+
* Performance: O(n) where n = array length
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const users = [
|
|
34
|
+
* { name: 'John', role: 'admin' },
|
|
35
|
+
* { name: 'Jane', role: 'user' },
|
|
36
|
+
* { name: 'Bob', role: 'admin' }
|
|
37
|
+
* ];
|
|
38
|
+
* const byRole = groupBy(users, u => u.role);
|
|
39
|
+
* // {
|
|
40
|
+
* // admin: [{ name: 'John', role: 'admin' }, { name: 'Bob', role: 'admin' }],
|
|
41
|
+
* // user: [{ name: 'Jane', role: 'user' }]
|
|
42
|
+
* // }
|
|
43
|
+
*/
|
|
44
|
+
export declare function groupBy<T, K extends string | number | symbol>(items: T[], keyFn: (item: T, index: number) => K): Record<K, T[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Get unique items from array
|
|
47
|
+
* @param items - Array with potential duplicates
|
|
48
|
+
* @param keyFn - Optional function to determine uniqueness
|
|
49
|
+
* @returns Array with unique items (preserves order of first occurrence)
|
|
50
|
+
*
|
|
51
|
+
* Performance: O(n) with Set, very efficient
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* unique([1, 2, 2, 3, 3, 3, 4]);
|
|
55
|
+
* // [1, 2, 3, 4]
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const users = [
|
|
59
|
+
* { id: 1, name: 'John' },
|
|
60
|
+
* { id: 2, name: 'Jane' },
|
|
61
|
+
* { id: 1, name: 'John' }
|
|
62
|
+
* ];
|
|
63
|
+
* const unique_ = unique(users, u => u.id);
|
|
64
|
+
* // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
|
|
65
|
+
*/
|
|
66
|
+
export declare function unique<T, K = T>(items: T[], keyFn?: (item: T) => K): T[];
|
|
67
|
+
/**
|
|
68
|
+
* Flatten nested array to specified depth
|
|
69
|
+
* @param items - Nested array
|
|
70
|
+
* @param depth - Flattening depth (default: Infinity)
|
|
71
|
+
* @returns Flattened array
|
|
72
|
+
*
|
|
73
|
+
* Performance: O(n) where n = total items at all levels
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* flatten([1, [2, [3, [4]]]]);
|
|
77
|
+
* // [1, 2, 3, 4]
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* flatten([1, [2, [3, [4]]]], 1);
|
|
81
|
+
* // [1, 2, [3, [4]]]
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* flatten([1, [2, 3], [4, [5, 6]]]);
|
|
85
|
+
* // [1, 2, 3, 4, 5, 6]
|
|
86
|
+
*/
|
|
87
|
+
export declare function flatten<T>(items: any[], depth?: number): T[];
|
|
88
|
+
/**
|
|
89
|
+
* Split array into chunks of specified size
|
|
90
|
+
* @param items - Array to chunk
|
|
91
|
+
* @param size - Chunk size
|
|
92
|
+
* @returns Array of chunks
|
|
93
|
+
*
|
|
94
|
+
* Performance: O(n) where n = array length
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* chunk([1, 2, 3, 4, 5], 2);
|
|
98
|
+
* // [[1, 2], [3, 4], [5]]
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* chunk(['a', 'b', 'c', 'd', 'e', 'f'], 3);
|
|
102
|
+
* // [['a', 'b', 'c'], ['d', 'e', 'f']]
|
|
103
|
+
*/
|
|
104
|
+
export declare function chunk<T>(items: T[], size: number): T[][];
|
|
105
|
+
/**
|
|
106
|
+
* Sort array by criteria
|
|
107
|
+
* @param items - Array to sort
|
|
108
|
+
* @param compareFn - Comparison function
|
|
109
|
+
* @returns Sorted array (creates new array)
|
|
110
|
+
*
|
|
111
|
+
* Performance: O(n log n)
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const users = [
|
|
115
|
+
* { name: 'Charlie', age: 30 },
|
|
116
|
+
* { name: 'Alice', age: 25 },
|
|
117
|
+
* { name: 'Bob', age: 25 }
|
|
118
|
+
* ];
|
|
119
|
+
* const sorted = sortBy(users, (a, b) => {
|
|
120
|
+
* if (a.age !== b.age) return a.age - b.age;
|
|
121
|
+
* return a.name.localeCompare(b.name);
|
|
122
|
+
* });
|
|
123
|
+
*/
|
|
124
|
+
export declare function sortBy<T>(items: T[], compareFn: (a: T, b: T) => number): T[];
|
|
125
|
+
/**
|
|
126
|
+
* Find index of item matching predicate
|
|
127
|
+
* @param items - Array to search
|
|
128
|
+
* @param predicate - Test function
|
|
129
|
+
* @returns Index of first match or -1
|
|
130
|
+
*
|
|
131
|
+
* Performance: O(n) worst case
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* const items = [10, 20, 30, 40];
|
|
135
|
+
* findIndex(items, x => x > 25); // 2
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
139
|
+
* findIndex(users, u => u.id === 2); // 1
|
|
140
|
+
*/
|
|
141
|
+
export declare function findIndex<T>(items: T[], predicate: (item: T, index: number) => boolean): number;
|
|
142
|
+
/**
|
|
143
|
+
* Find last index of item matching predicate
|
|
144
|
+
* @param items - Array to search
|
|
145
|
+
* @param predicate - Test function
|
|
146
|
+
* @returns Index of last match or -1
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const items = [10, 20, 30, 20, 40];
|
|
150
|
+
* findLastIndex(items, x => x === 20); // 3
|
|
151
|
+
*/
|
|
152
|
+
export declare function findLastIndex<T>(items: T[], predicate: (item: T, index: number) => boolean): number;
|
|
153
|
+
/**
|
|
154
|
+
* Partition array into two arrays based on predicate
|
|
155
|
+
* @param items - Array to partition
|
|
156
|
+
* @param predicate - Test function
|
|
157
|
+
* @returns Tuple of [passing, failing]
|
|
158
|
+
*
|
|
159
|
+
* Performance: O(n)
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const numbers = [1, 2, 3, 4, 5, 6];
|
|
163
|
+
* const [even, odd] = partition(numbers, x => x % 2 === 0);
|
|
164
|
+
* // even: [2, 4, 6]
|
|
165
|
+
* // odd: [1, 3, 5]
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* const users = [
|
|
169
|
+
* { name: 'John', active: true },
|
|
170
|
+
* { name: 'Jane', active: false },
|
|
171
|
+
* { name: 'Bob', active: true }
|
|
172
|
+
* ];
|
|
173
|
+
* const [active, inactive] = partition(users, u => u.active);
|
|
174
|
+
*/
|
|
175
|
+
export declare function partition<T>(items: T[], predicate: (item: T) => boolean): [T[], T[]];
|
|
176
|
+
/**
|
|
177
|
+
* Zip arrays together
|
|
178
|
+
* @param arrays - Arrays to zip
|
|
179
|
+
* @returns Array of tuples
|
|
180
|
+
*
|
|
181
|
+
* Performance: O(n) where n = length of shortest array
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const names = ['John', 'Jane', 'Bob'];
|
|
185
|
+
* const ages = [30, 28, 25];
|
|
186
|
+
* const zipped = zip(names, ages);
|
|
187
|
+
* // [['John', 30], ['Jane', 28], ['Bob', 25]]
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* const a = [1, 2, 3];
|
|
191
|
+
* const b = ['a', 'b', 'c'];
|
|
192
|
+
* const c = [true, false, true];
|
|
193
|
+
* const result = zip(a, b, c);
|
|
194
|
+
* // [[1, 'a', true], [2, 'b', false], [3, 'c', true]]
|
|
195
|
+
*/
|
|
196
|
+
export declare function zip<T extends any[][]>(...arrays: T): Array<any[]>;
|
|
197
|
+
/**
|
|
198
|
+
* Unzip array of tuples
|
|
199
|
+
* @param items - Array of tuples
|
|
200
|
+
* @returns Array of arrays
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* const zipped = [['John', 30], ['Jane', 28], ['Bob', 25]];
|
|
204
|
+
* const [names, ages] = unzip(zipped);
|
|
205
|
+
* // names: ['John', 'Jane', 'Bob']
|
|
206
|
+
* // ages: [30, 28, 25]
|
|
207
|
+
*/
|
|
208
|
+
export declare function unzip<T extends any[]>(items: T[]): Array<any[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Get first n items from array
|
|
211
|
+
* @param items - Array
|
|
212
|
+
* @param n - Number of items
|
|
213
|
+
* @returns First n items
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* take([1, 2, 3, 4, 5], 3); // [1, 2, 3]
|
|
217
|
+
*/
|
|
218
|
+
export declare function take<T>(items: T[], n: number): T[];
|
|
219
|
+
/**
|
|
220
|
+
* Remove first n items from array
|
|
221
|
+
* @param items - Array
|
|
222
|
+
* @param n - Number of items to skip
|
|
223
|
+
* @returns Items after first n
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* drop([1, 2, 3, 4, 5], 2); // [3, 4, 5]
|
|
227
|
+
*/
|
|
228
|
+
export declare function drop<T>(items: T[], n: number): T[];
|
|
229
|
+
/**
|
|
230
|
+
* Get last n items from array
|
|
231
|
+
* @param items - Array
|
|
232
|
+
* @param n - Number of items
|
|
233
|
+
* @returns Last n items
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* takeLast([1, 2, 3, 4, 5], 2); // [4, 5]
|
|
237
|
+
*/
|
|
238
|
+
export declare function takeLast<T>(items: T[], n: number): T[];
|
|
239
|
+
/**
|
|
240
|
+
* Remove last n items from array
|
|
241
|
+
* @param items - Array
|
|
242
|
+
* @param n - Number of items to remove
|
|
243
|
+
* @returns Items excluding last n
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* dropLast([1, 2, 3, 4, 5], 2); // [1, 2, 3]
|
|
247
|
+
*/
|
|
248
|
+
export declare function dropLast<T>(items: T[], n: number): T[];
|
|
249
|
+
/**
|
|
250
|
+
* Find union of arrays (all unique items from all arrays)
|
|
251
|
+
* @param arrays - Arrays to union
|
|
252
|
+
* @returns Array of unique items from all arrays
|
|
253
|
+
*
|
|
254
|
+
* Performance: O(n) where n = total items
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* union([1, 2, 3], [2, 3, 4], [3, 4, 5]);
|
|
258
|
+
* // [1, 2, 3, 4, 5]
|
|
259
|
+
*/
|
|
260
|
+
export declare function union<T>(...arrays: T[][]): T[];
|
|
261
|
+
/**
|
|
262
|
+
* Find intersection of arrays (items present in all arrays)
|
|
263
|
+
* @param arrays - Arrays to intersect
|
|
264
|
+
* @returns Array of items present in all arrays
|
|
265
|
+
*
|
|
266
|
+
* Performance: O(n*m) where n = first array, m = other arrays
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* intersection([1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]);
|
|
270
|
+
* // [3, 4]
|
|
271
|
+
*/
|
|
272
|
+
export declare function intersection<T>(...arrays: T[][]): T[];
|
|
273
|
+
/**
|
|
274
|
+
* Find difference (items in first array not in others)
|
|
275
|
+
* @param first - First array
|
|
276
|
+
* @param rest - Other arrays to subtract
|
|
277
|
+
* @returns Items in first but not in others
|
|
278
|
+
*
|
|
279
|
+
* Performance: O(n+m) where n = first, m = total other items
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* difference([1, 2, 3, 4], [2, 3], [4]);
|
|
283
|
+
* // [1]
|
|
284
|
+
*/
|
|
285
|
+
export declare function difference<T>(first: T[], ...rest: T[][]): T[];
|
|
286
|
+
/**
|
|
287
|
+
* Remove duplicates while preserving order
|
|
288
|
+
* @param items - Array with potential duplicates
|
|
289
|
+
* @returns Array without duplicates
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* compact([1, 2, 2, 3, 3, 3, 4, null, undefined]);
|
|
293
|
+
* // [1, 2, 3, 4, null, undefined]
|
|
294
|
+
*/
|
|
295
|
+
export declare function compact<T>(items: (T | null | undefined)[]): T[];
|
|
296
|
+
/**
|
|
297
|
+
* Filter and map in one operation
|
|
298
|
+
* @param items - Array to transform
|
|
299
|
+
* @param fn - Function returning value or null/undefined to filter
|
|
300
|
+
* @returns Filtered and mapped array
|
|
301
|
+
*
|
|
302
|
+
* Performance: O(n)
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* const items = [1, 2, 3, 4, 5];
|
|
306
|
+
* const result = mapFilter(items, x => x > 2 ? x * 2 : null);
|
|
307
|
+
* // [6, 8, 10]
|
|
308
|
+
*/
|
|
309
|
+
export declare function mapFilter<T, R>(items: T[], fn: (item: T) => R | null | undefined): R[];
|
|
310
|
+
/**
|
|
311
|
+
* Shuffle array randomly
|
|
312
|
+
* @param items - Array to shuffle
|
|
313
|
+
* @returns Shuffled copy of array
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* shuffle([1, 2, 3, 4, 5]);
|
|
317
|
+
* // [3, 1, 4, 5, 2] (random order)
|
|
318
|
+
*/
|
|
319
|
+
export declare function shuffle<T>(items: T[]): T[];
|
|
320
|
+
/**
|
|
321
|
+
* Get random item from array
|
|
322
|
+
* @param items - Array to sample from
|
|
323
|
+
* @returns Random item or undefined if empty
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* const item = sample([1, 2, 3, 4, 5]);
|
|
327
|
+
* // One random item from the array
|
|
328
|
+
*/
|
|
329
|
+
export declare function sample<T>(items: T[]): T | undefined;
|
|
330
|
+
/**
|
|
331
|
+
* Get multiple random items from array
|
|
332
|
+
* @param items - Array to sample from
|
|
333
|
+
* @param n - Number of items to sample
|
|
334
|
+
* @returns Array of random items
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* sampleSize([1, 2, 3, 4, 5], 3);
|
|
338
|
+
* // [2, 4, 1] (3 random items)
|
|
339
|
+
*/
|
|
340
|
+
export declare function sampleSize<T>(items: T[], n: number): T[];
|
|
341
|
+
/**
|
|
342
|
+
* Find item with minimum value
|
|
343
|
+
* @param items - Array to search
|
|
344
|
+
* @param compareFn - Function to get comparable value
|
|
345
|
+
* @returns Item with minimum value or undefined
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* const items = [{ val: 10 }, { val: 5 }, { val: 20 }];
|
|
349
|
+
* const min = minBy(items, x => x.val);
|
|
350
|
+
* // { val: 5 }
|
|
351
|
+
*/
|
|
352
|
+
export declare function minBy<T>(items: T[], compareFn: (item: T) => number): T | undefined;
|
|
353
|
+
/**
|
|
354
|
+
* Find item with maximum value
|
|
355
|
+
* @param items - Array to search
|
|
356
|
+
* @param compareFn - Function to get comparable value
|
|
357
|
+
* @returns Item with maximum value or undefined
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* const items = [{ val: 10 }, { val: 5 }, { val: 20 }];
|
|
361
|
+
* const max = maxBy(items, x => x.val);
|
|
362
|
+
* // { val: 20 }
|
|
363
|
+
*/
|
|
364
|
+
export declare function maxBy<T>(items: T[], compareFn: (item: T) => number): T | undefined;
|
|
365
|
+
/**
|
|
366
|
+
* Sum array values
|
|
367
|
+
* @param items - Array to sum
|
|
368
|
+
* @param fn - Optional function to get numeric value
|
|
369
|
+
* @returns Sum of array
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* sum([1, 2, 3, 4]); // 10
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* const items = [{ val: 10 }, { val: 20 }];
|
|
376
|
+
* sum(items, x => x.val); // 30
|
|
377
|
+
*/
|
|
378
|
+
export declare function sum<T>(items: T[], fn?: (item: T) => number): number;
|
|
379
|
+
/**
|
|
380
|
+
* Average array values
|
|
381
|
+
* @param items - Array to average
|
|
382
|
+
* @param fn - Optional function to get numeric value
|
|
383
|
+
* @returns Average of array
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* average([1, 2, 3, 4]); // 2.5
|
|
387
|
+
*/
|
|
388
|
+
export declare function average<T>(items: T[], fn?: (item: T) => number): number;
|
|
389
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/utils/array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAs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