@tyravel/collection 0.6.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.
@@ -0,0 +1,139 @@
1
+ import type { CollectionCallback, CollectionPredicate, KeySelector, SortSelector } from './types.js';
2
+ /**
3
+ * Fluent, type-safe, chainable collection — inspired by Laravel's Collection.
4
+ * Every method returns a new instance (immutable) unless noted.
5
+ */
6
+ export declare class Collection<T> {
7
+ private items;
8
+ constructor(items: T[]);
9
+ /** All items as a plain array. */
10
+ toArray(): T[];
11
+ /** JSON serialization returns the plain array. */
12
+ toJSON(): T[];
13
+ /** Number of items. */
14
+ count(): number;
15
+ /** True when the collection is empty. */
16
+ isEmpty(): boolean;
17
+ /** True when the collection has items. */
18
+ isNotEmpty(): boolean;
19
+ /** First item, or undefined if empty. Optionally filtered by predicate. */
20
+ first(predicate?: CollectionPredicate<T>): T | undefined;
21
+ /** Last item, or undefined if empty. */
22
+ last(predicate?: CollectionPredicate<T>): T | undefined;
23
+ /** Item at the given index (supports negative). */
24
+ nth(index: number): T | undefined;
25
+ /** Map each item through a callback. */
26
+ map<U>(callback: CollectionCallback<T, U>): Collection<U>;
27
+ /** Reduce the collection to a single value. */
28
+ reduce<U>(callback: (acc: U, item: T, index: number) => U, initial: U): U;
29
+ /** Apply a side-effect to each item, return the same collection (chainable). */
30
+ each(callback: CollectionCallback<T, void>): this;
31
+ /** Tap into a chain — pass the collection to a callback for side-effects. */
32
+ tap(callback: (collection: this) => void): this;
33
+ /** Pipe the collection through a transform and return the result. */
34
+ pipe<U>(callback: (collection: this) => U): U;
35
+ /** Keep items matching the predicate. */
36
+ filter(predicate: CollectionPredicate<T>): Collection<T>;
37
+ /** Alias for filter. */
38
+ where(predicate: CollectionPredicate<T>): Collection<T>;
39
+ /** Items where the given key strictly equals the given value. */
40
+ whereEq<K extends keyof T>(key: K, value: T[K]): Collection<T>;
41
+ /** Items where key in array of values. */
42
+ whereIn<K extends keyof T>(key: K, values: T[K][]): Collection<T>;
43
+ /** Items where key NOT in array of values. */
44
+ whereNotIn<K extends keyof T>(key: K, values: T[K][]): Collection<T>;
45
+ /** Items where key is not null/undefined. */
46
+ whereNotNull<K extends keyof T>(key: K): Collection<T>;
47
+ /** Items where the given key is strictly null or undefined. */
48
+ whereNull<K extends keyof T>(key: K): Collection<T>;
49
+ /** Remove duplicate items. Uses strict equality by default. */
50
+ unique(keySelector?: KeySelector<T>): Collection<T>;
51
+ /** Skip the first N items. */
52
+ skip(count: number): Collection<T>;
53
+ /** Take the first N items (or last if negative). */
54
+ take(count: number): Collection<T>;
55
+ /** Items for a given page (1-indexed). */
56
+ forPage(page: number, perPage: number): Collection<T>;
57
+ /** Slice the collection. */
58
+ slice(offset: number, length?: number): Collection<T>;
59
+ /** Split the collection into chunks of the given size. */
60
+ chunk(size: number): Collection<T[]>;
61
+ /** Split into N roughly equal groups. */
62
+ split(count: number): Collection<T[]>;
63
+ /** Sort ascending by the given key or comparator. */
64
+ sortBy(selector: SortSelector<T>): Collection<T>;
65
+ /** Sort descending by the given key or comparator. */
66
+ sortByDesc(selector: SortSelector<T>): Collection<T>;
67
+ /** Sort with a custom comparator function. */
68
+ sort(comparator: (a: T, b: T) => number): Collection<T>;
69
+ /** Reverse the order of items. */
70
+ reverse(): Collection<T>;
71
+ /** Randomly shuffle the items. */
72
+ shuffle(): Collection<T>;
73
+ /** Group items by the given key. Returns a collection of `[key, items]` pairs. */
74
+ groupBy(selector: KeySelector<T>): Collection<[string, T[]]>;
75
+ /** Key the collection by the given selector (last wins on duplicates). */
76
+ keyBy(selector: KeySelector<T>): Collection<[string, T]>;
77
+ /** Partition into two collections: [matching, non-matching]. */
78
+ partition(predicate: CollectionPredicate<T>): [Collection<T>, Collection<T>];
79
+ /** Extract a single key's values from each item. */
80
+ pluck<K extends keyof T>(key: K): Collection<T[K]>;
81
+ /** Return the values of the collection (identity). */
82
+ values(): Collection<T>;
83
+ /** Return the keys of the first item, or an empty collection. */
84
+ keys(): Collection<string>;
85
+ /** Sum of values for a key, or sum of items (if numeric). */
86
+ sum(key?: keyof T): number;
87
+ /** Average of values for a key, or average of items (if numeric). */
88
+ avg(key?: keyof T): number;
89
+ /** Numeric minimum. */
90
+ min(key?: keyof T): number;
91
+ /** Numeric maximum. */
92
+ max(key?: keyof T): number;
93
+ /** True if the collection contains the value (strict equality). */
94
+ contains(value: T): boolean;
95
+ /** True if the collection contains any item matching the predicate. */
96
+ containsWhere(predicate: CollectionPredicate<T>): boolean;
97
+ /** True if every item matches the predicate. */
98
+ every(predicate: CollectionPredicate<T>): boolean;
99
+ /** Join items with a glue string. */
100
+ implode(glue: string): string;
101
+ /** Join items, with an optional last separator (like in English lists). */
102
+ join(glue: string, lastGlue?: string): string;
103
+ /** Add item(s) to the end. */
104
+ push(...values: T[]): Collection<T>;
105
+ /** Prepend item(s) to the start. */
106
+ prepend(...values: T[]): Collection<T>;
107
+ /** Pop the last item off. */
108
+ pop(): Collection<T>;
109
+ /** Shift the first item off. */
110
+ shift(): Collection<T>;
111
+ /** Replace items at the given offset. */
112
+ splice(offset: number, deleteCount?: number, ...replacements: T[]): Collection<T>;
113
+ /** Concatenate one or more collections/arrays. */
114
+ concat(...sources: (Collection<T> | T[])[]): Collection<T>;
115
+ /** Merge an array or collection into this one, overwriting by key (objects). */
116
+ merge(source: Collection<Partial<T>> | Partial<T>[]): Collection<T>;
117
+ /** Items in this collection that are not in the other. */
118
+ diff(other: Collection<T> | T[]): Collection<T>;
119
+ /** Items present in both collections. */
120
+ intersect(other: Collection<T> | T[]): Collection<T>;
121
+ /** Union — items from both collections, deduplicated. */
122
+ union(other: Collection<T> | T[]): Collection<T>;
123
+ /** Flatten a collection of arrays/collections one level deep. */
124
+ flatten<U>(depth?: number): Collection<U>;
125
+ /** Collapse a collection of arrays into a flat collection. */
126
+ collapse<U>(): Collection<U>;
127
+ /** Apply callback when the condition is truthy. */
128
+ when(condition: boolean | ((collection: this) => boolean), callback: (collection: this) => this, fallback?: (collection: this) => this): this;
129
+ /** Apply callback when the condition is falsy. */
130
+ unless(condition: boolean | ((collection: this) => boolean), callback: (collection: this) => this, fallback?: (collection: this) => this): this;
131
+ /** Return a single random item, or N random items. */
132
+ random(count?: number): T | T[] | undefined;
133
+ /** Return a collection with only the given keys (for objects). */
134
+ only<K extends keyof T>(keys: K[]): Collection<Pick<T, K>>;
135
+ /** Return a collection without the given keys. */
136
+ except<K extends keyof T>(keys: K[]): Collection<Omit<T, K>>;
137
+ [Symbol.iterator](): Iterator<T>;
138
+ }
139
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,UAAU,CAAC,CAAC;IACX,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,CAAC,EAAE;IAI9B,kCAAkC;IAClC,OAAO,IAAI,CAAC,EAAE;IAId,kDAAkD;IAClD,MAAM,IAAI,CAAC,EAAE;IAIb,uBAAuB;IACvB,KAAK,IAAI,MAAM;IAIf,yCAAyC;IACzC,OAAO,IAAI,OAAO;IAIlB,0CAA0C;IAC1C,UAAU,IAAI,OAAO;IAIrB,2EAA2E;IAC3E,KAAK,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAKxD,wCAAwC;IACxC,IAAI,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAQvD,mDAAmD;IACnD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAOjC,wCAAwC;IACxC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC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) unless noted.
4
+ */
5
+ export class Collection {
6
+ items;
7
+ constructor(items) {
8
+ this.items = items;
9
+ }
10
+ /* ──── Access ─────────────────────────────────────────────────────────── */
11
+ /** All items as a plain array. */
12
+ toArray() {
13
+ return [...this.items];
14
+ }
15
+ /** JSON serialization returns the plain array. */
16
+ toJSON() {
17
+ return this.toArray();
18
+ }
19
+ /** Number of items. */
20
+ count() {
21
+ return this.items.length;
22
+ }
23
+ /** True when the collection is empty. */
24
+ isEmpty() {
25
+ return this.items.length === 0;
26
+ }
27
+ /** True when the collection has items. */
28
+ isNotEmpty() {
29
+ return this.items.length > 0;
30
+ }
31
+ /** First item, or undefined if empty. Optionally filtered by predicate. */
32
+ first(predicate) {
33
+ if (!predicate)
34
+ return this.items[0];
35
+ return this.items.find(predicate);
36
+ }
37
+ /** Last item, or undefined if empty. */
38
+ last(predicate) {
39
+ if (!predicate)
40
+ return this.items[this.items.length - 1];
41
+ for (let i = this.items.length - 1; i >= 0; i--) {
42
+ if (predicate(this.items[i], i))
43
+ return this.items[i];
44
+ }
45
+ return undefined;
46
+ }
47
+ /** Item at the given index (supports negative). */
48
+ nth(index) {
49
+ if (index < 0)
50
+ index = this.items.length + index;
51
+ return this.items[index];
52
+ }
53
+ /* ──── Mapping / Reducing ────────────────────────────────────────────── */
54
+ /** Map each item through a callback. */
55
+ map(callback) {
56
+ return new Collection(this.items.map(callback));
57
+ }
58
+ /** Reduce the collection to a single value. */
59
+ reduce(callback, initial) {
60
+ return this.items.reduce(callback, initial);
61
+ }
62
+ /** Apply a side-effect to each item, return the same collection (chainable). */
63
+ each(callback) {
64
+ this.items.forEach(callback);
65
+ return this;
66
+ }
67
+ /** Tap into a chain — pass the collection to a callback for side-effects. */
68
+ tap(callback) {
69
+ callback(this);
70
+ return this;
71
+ }
72
+ /** Pipe the collection through a transform and return the result. */
73
+ pipe(callback) {
74
+ return callback(this);
75
+ }
76
+ /* ──── Filtering ──────────────────────────────────────────────────────── */
77
+ /** Keep items matching the predicate. */
78
+ filter(predicate) {
79
+ return new Collection(this.items.filter(predicate));
80
+ }
81
+ /** Alias for filter. */
82
+ where(predicate) {
83
+ return this.filter(predicate);
84
+ }
85
+ /** Items where the given key strictly equals the given value. */
86
+ whereEq(key, value) {
87
+ return this.filter((item) => item[key] === value);
88
+ }
89
+ /** Items where key in array of values. */
90
+ whereIn(key, values) {
91
+ const set = new Set(values);
92
+ return this.filter((item) => set.has(item[key]));
93
+ }
94
+ /** Items where key NOT in array of values. */
95
+ whereNotIn(key, values) {
96
+ const set = new Set(values);
97
+ return this.filter((item) => !set.has(item[key]));
98
+ }
99
+ /** Items where key is not null/undefined. */
100
+ whereNotNull(key) {
101
+ return this.filter((item) => item[key] != null);
102
+ }
103
+ /** Items where the given key is strictly null or undefined. */
104
+ whereNull(key) {
105
+ return this.filter((item) => item[key] == null);
106
+ }
107
+ /** Remove duplicate items. Uses strict equality by default. */
108
+ unique(keySelector) {
109
+ if (!keySelector)
110
+ return new Collection([...new Set(this.items)]);
111
+ const seen = new Set();
112
+ return this.filter((item) => {
113
+ const key = typeof keySelector === 'function'
114
+ ? keySelector(item)
115
+ : String(item[keySelector]);
116
+ if (seen.has(key))
117
+ return false;
118
+ seen.add(key);
119
+ return true;
120
+ });
121
+ }
122
+ /** Skip the first N items. */
123
+ skip(count) {
124
+ return new Collection(this.items.slice(count));
125
+ }
126
+ /** Take the first N items (or last if negative). */
127
+ take(count) {
128
+ if (count < 0)
129
+ return new Collection(this.items.slice(count));
130
+ return new Collection(this.items.slice(0, count));
131
+ }
132
+ /** Items for a given page (1-indexed). */
133
+ forPage(page, perPage) {
134
+ return this.slice((page - 1) * perPage, perPage);
135
+ }
136
+ /** Slice the collection. */
137
+ slice(offset, length) {
138
+ return new Collection(this.items.slice(offset, length ? offset + length : undefined));
139
+ }
140
+ /** Split the collection into chunks of the given size. */
141
+ chunk(size) {
142
+ const chunks = [];
143
+ for (let i = 0; i < this.items.length; i += size) {
144
+ chunks.push(this.items.slice(i, i + size));
145
+ }
146
+ return new Collection(chunks);
147
+ }
148
+ /** Split into N roughly equal groups. */
149
+ split(count) {
150
+ const size = Math.ceil(this.items.length / count);
151
+ return this.chunk(size);
152
+ }
153
+ /* ──── Sorting ────────────────────────────────────────────────────────── */
154
+ /** Sort ascending by the given key or comparator. */
155
+ sortBy(selector) {
156
+ const sorted = [...this.items].sort((a, b) => {
157
+ const aVal = typeof selector === 'function' ? selector(a) : a[selector];
158
+ const bVal = typeof selector === 'function' ? selector(b) : b[selector];
159
+ if (aVal < bVal)
160
+ return -1;
161
+ if (aVal > bVal)
162
+ return 1;
163
+ return 0;
164
+ });
165
+ return new Collection(sorted);
166
+ }
167
+ /** Sort descending by the given key or comparator. */
168
+ sortByDesc(selector) {
169
+ return this.sortBy(selector).reverse();
170
+ }
171
+ /** Sort with a custom comparator function. */
172
+ sort(comparator) {
173
+ return new Collection([...this.items].sort(comparator));
174
+ }
175
+ /** Reverse the order of items. */
176
+ reverse() {
177
+ return new Collection([...this.items].reverse());
178
+ }
179
+ /** Randomly shuffle the items. */
180
+ shuffle() {
181
+ const shuffled = [...this.items];
182
+ for (let i = shuffled.length - 1; i > 0; i--) {
183
+ const j = Math.floor(Math.random() * (i + 1));
184
+ [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
185
+ }
186
+ return new Collection(shuffled);
187
+ }
188
+ /* ──── Grouping / Keying ──────────────────────────────────────────────── */
189
+ /** Group items by the given key. Returns a collection of `[key, items]` pairs. */
190
+ groupBy(selector) {
191
+ const map = new Map();
192
+ for (const item of this.items) {
193
+ const key = typeof selector === 'function'
194
+ ? selector(item)
195
+ : String(item[selector]);
196
+ const group = map.get(key);
197
+ if (group) {
198
+ group.push(item);
199
+ }
200
+ else {
201
+ map.set(key, [item]);
202
+ }
203
+ }
204
+ return new Collection([...map.entries()]);
205
+ }
206
+ /** Key the collection by the given selector (last wins on duplicates). */
207
+ keyBy(selector) {
208
+ const map = new Map();
209
+ for (const item of this.items) {
210
+ const key = typeof selector === 'function'
211
+ ? selector(item)
212
+ : String(item[selector]);
213
+ map.set(key, item);
214
+ }
215
+ return new Collection([...map.entries()]);
216
+ }
217
+ /** Partition into two collections: [matching, non-matching]. */
218
+ partition(predicate) {
219
+ const pass = [];
220
+ const fail = [];
221
+ for (let i = 0; i < this.items.length; i++) {
222
+ if (predicate(this.items[i], i)) {
223
+ pass.push(this.items[i]);
224
+ }
225
+ else {
226
+ fail.push(this.items[i]);
227
+ }
228
+ }
229
+ return [new Collection(pass), new Collection(fail)];
230
+ }
231
+ /* ──── Plucking ───────────────────────────────────────────────────────── */
232
+ /** Extract a single key's values from each item. */
233
+ pluck(key) {
234
+ return new Collection(this.items.map((item) => item[key]));
235
+ }
236
+ /** Return the values of the collection (identity). */
237
+ values() {
238
+ return new Collection([...this.items]);
239
+ }
240
+ /** Return the keys of the first item, or an empty collection. */
241
+ keys() {
242
+ if (this.items.length === 0)
243
+ return new Collection([]);
244
+ return new Collection(Object.keys(this.items[0]));
245
+ }
246
+ /* ──── Aggregation ────────────────────────────────────────────────────── */
247
+ /** Sum of values for a key, or sum of items (if numeric). */
248
+ sum(key) {
249
+ return this.items.reduce((acc, item) => {
250
+ const val = key ? item[key] : item;
251
+ return acc + (typeof val === 'number' ? val : Number(val) || 0);
252
+ }, 0);
253
+ }
254
+ /** Average of values for a key, or average of items (if numeric). */
255
+ avg(key) {
256
+ if (this.items.length === 0)
257
+ return 0;
258
+ return this.sum(key) / this.items.length;
259
+ }
260
+ /** Numeric minimum. */
261
+ min(key) {
262
+ const vals = this.items.map((item) => key ? item[key] : item);
263
+ return Math.min(...vals);
264
+ }
265
+ /** Numeric maximum. */
266
+ max(key) {
267
+ const vals = this.items.map((item) => key ? item[key] : item);
268
+ return Math.max(...vals);
269
+ }
270
+ /* ──── Membership ─────────────────────────────────────────────────────── */
271
+ /** True if the collection contains the value (strict equality). */
272
+ contains(value) {
273
+ return this.items.includes(value);
274
+ }
275
+ /** True if the collection contains any item matching the predicate. */
276
+ containsWhere(predicate) {
277
+ return this.items.some(predicate);
278
+ }
279
+ /** True if every item matches the predicate. */
280
+ every(predicate) {
281
+ return this.items.every(predicate);
282
+ }
283
+ /* ──── String output ──────────────────────────────────────────────────── */
284
+ /** Join items with a glue string. */
285
+ implode(glue) {
286
+ return this.items.join(glue);
287
+ }
288
+ /** Join items, with an optional last separator (like in English lists). */
289
+ join(glue, lastGlue) {
290
+ const len = this.items.length;
291
+ if (len === 0)
292
+ return '';
293
+ if (len === 1)
294
+ return String(this.items[0]);
295
+ if (len === 2)
296
+ return `${this.items[0]}${lastGlue ?? glue}${this.items[1]}`;
297
+ const head = this.items.slice(0, -1).join(glue);
298
+ return `${head}${lastGlue ?? glue}${this.items[len - 1]}`;
299
+ }
300
+ /* ──── Mutation (returns new Collection) ──────────────────────────────── */
301
+ /** Add item(s) to the end. */
302
+ push(...values) {
303
+ return new Collection([...this.items, ...values]);
304
+ }
305
+ /** Prepend item(s) to the start. */
306
+ prepend(...values) {
307
+ return new Collection([...values, ...this.items]);
308
+ }
309
+ /** Pop the last item off. */
310
+ pop() {
311
+ return new Collection(this.items.slice(0, -1));
312
+ }
313
+ /** Shift the first item off. */
314
+ shift() {
315
+ return new Collection(this.items.slice(1));
316
+ }
317
+ /** Replace items at the given offset. */
318
+ splice(offset, deleteCount, ...replacements) {
319
+ const copy = [...this.items];
320
+ copy.splice(offset, deleteCount ?? copy.length - offset, ...replacements);
321
+ return new Collection(copy);
322
+ }
323
+ /* ──── Combining ──────────────────────────────────────────────────────── */
324
+ /** Concatenate one or more collections/arrays. */
325
+ concat(...sources) {
326
+ const all = [...this.items];
327
+ for (const src of sources) {
328
+ if (src instanceof Collection) {
329
+ all.push(...src.toArray());
330
+ }
331
+ else {
332
+ all.push(...src);
333
+ }
334
+ }
335
+ return new Collection(all);
336
+ }
337
+ /** Merge an array or collection into this one, overwriting by key (objects). */
338
+ merge(source) {
339
+ const entries = source instanceof Collection ? source.toArray() : source;
340
+ return new Collection([...this.items, ...entries]);
341
+ }
342
+ /** Items in this collection that are not in the other. */
343
+ diff(other) {
344
+ const set = new Set(other instanceof Collection ? other.toArray() : other);
345
+ return this.filter((item) => !set.has(item));
346
+ }
347
+ /** Items present in both collections. */
348
+ intersect(other) {
349
+ const set = new Set(other instanceof Collection ? other.toArray() : other);
350
+ return this.filter((item) => set.has(item));
351
+ }
352
+ /** Union — items from both collections, deduplicated. */
353
+ union(other) {
354
+ return this.push(...(other instanceof Collection ? other.toArray() : other)).unique();
355
+ }
356
+ /* ──── Collapsing ─────────────────────────────────────────────────────── */
357
+ /** Flatten a collection of arrays/collections one level deep. */
358
+ flatten(depth = 1) {
359
+ let result = this.items;
360
+ for (let d = 0; d < depth; d++) {
361
+ result = result.flat();
362
+ }
363
+ return new Collection(result);
364
+ }
365
+ /** Collapse a collection of arrays into a flat collection. */
366
+ collapse() {
367
+ const result = [];
368
+ for (const item of this.items) {
369
+ if (Array.isArray(item)) {
370
+ result.push(...item);
371
+ }
372
+ }
373
+ return new Collection(result);
374
+ }
375
+ /* ──── Conditionable ──────────────────────────────────────────────────── */
376
+ /** Apply callback when the condition is truthy. */
377
+ when(condition, callback, fallback) {
378
+ const isTruthy = typeof condition === 'function' ? condition(this) : condition;
379
+ if (isTruthy)
380
+ return callback(this);
381
+ if (fallback)
382
+ return fallback(this);
383
+ return this;
384
+ }
385
+ /** Apply callback when the condition is falsy. */
386
+ unless(condition, callback, fallback) {
387
+ return this.when(typeof condition === 'function'
388
+ ? (c) => !condition(c)
389
+ : !condition, callback, fallback);
390
+ }
391
+ /* ──── Random ─────────────────────────────────────────────────────────── */
392
+ /** Return a single random item, or N random items. */
393
+ random(count) {
394
+ if (count === undefined) {
395
+ if (this.items.length === 0)
396
+ return undefined;
397
+ return this.items[Math.floor(Math.random() * this.items.length)];
398
+ }
399
+ const shuffled = this.shuffle();
400
+ return shuffled.take(count).toArray();
401
+ }
402
+ /* ───── Utility ───────────────────────────────────────────────────────── */
403
+ /** Return a collection with only the given keys (for objects). */
404
+ only(keys) {
405
+ return new Collection(this.items.map((item) => {
406
+ const picked = {};
407
+ for (const key of keys) {
408
+ picked[key] = item[key];
409
+ }
410
+ return picked;
411
+ }));
412
+ }
413
+ /** Return a collection without the given keys. */
414
+ except(keys) {
415
+ const keySet = new Set(keys);
416
+ return new Collection(this.items.map((item) => {
417
+ const rest = { ...item };
418
+ for (const key of keySet) {
419
+ delete rest[key];
420
+ }
421
+ return rest;
422
+ }));
423
+ }
424
+ /* ──── Iteration ──────────────────────────────────────────────────────── */
425
+ *[Symbol.iterator]() {
426
+ for (const item of this.items) {
427
+ yield item;
428
+ }
429
+ }
430
+ }
431
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,OAAO,UAAU;IACD;IAApB,YAAoB,KAAU;QAAV,UAAK,GAAL,KAAK,CAAK;IAAG,CAAC;IAElC,6EAA6E;IAE7E,kCAAkC;IAClC,OAAO;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,kDAAkD;IAClD,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,uBAAuB;IACvB,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,yCAAyC;IACzC,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,0CAA0C;IAC1C,UAAU;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,2EAA2E;IAC3E,KAAK,CAAC,SAAkC;QACtC,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CA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;YACD,OAAO,IAAkB,CAAC;QAC5B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,6EAA6E;IAE7E,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { Collection } from './collection.js';
2
+ export { Collection } from './collection.js';
3
+ export type { CollectionCallback, CollectionPredicate, KeySelector, SortSelector } from './types.js';
4
+ /** Create a new Collection from an array of items. */
5
+ export declare function collect<T>(items?: T[]): Collection<T>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAErG,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,GAAE,CAAC,EAAO,GAAG,UAAU,CAAC,CAAC,CAAC,CAEzD"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { Collection } from './collection.js';
2
+ export { Collection } from './collection.js';
3
+ /** Create a new Collection from an array of items. */
4
+ export function collect(items = []) {
5
+ return new Collection(items);
6
+ }
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,sDAAsD;AACtD,MAAM,UAAU,OAAO,CAAI,QAAa,EAAE;IACxC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type CollectionCallback<T, U> = (item: T, index: number) => U;
2
+ export type CollectionPredicate<T> = (item: T, index: number) => boolean;
3
+ export type KeySelector<T> = keyof T | ((item: T) => string);
4
+ export type SortSelector<T> = keyof T | ((item: T) => number | string);
5
+ export interface CollectionLike<T> {
6
+ toArray(): T[];
7
+ }
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC;AACrE,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAEzE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC;AAIvE,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,EAAE,CAAC;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@tyravel/collection",
3
+ "version": "0.6.0",
4
+ "description": "Fluent, typed collection pipeline for Tyravel",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "typecheck": "tsc -p tsconfig.json --noEmit",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/thesimonharms/tyravel.git",
27
+ "directory": "packages/collection"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "engines": {
33
+ "node": ">=22"
34
+ },
35
+ "devDependencies": {
36
+ "typescript": "^5.7.0",
37
+ "vitest": "^3.0.0"
38
+ }
39
+ }