auxilium 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.
Files changed (62) hide show
  1. package/README.md +374 -0
  2. package/dist/http.d.ts +91 -0
  3. package/dist/http.js +105 -0
  4. package/dist/http.js.map +1 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +20 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/interfaces/common.d.ts +5 -0
  9. package/dist/interfaces/common.js +3 -0
  10. package/dist/interfaces/common.js.map +1 -0
  11. package/dist/interfaces/index.d.ts +2 -0
  12. package/dist/interfaces/index.js +19 -0
  13. package/dist/interfaces/index.js.map +1 -0
  14. package/dist/interfaces/logger.d.ts +11 -0
  15. package/dist/interfaces/logger.js +3 -0
  16. package/dist/interfaces/logger.js.map +1 -0
  17. package/dist/priorityQueue.d.ts +43 -0
  18. package/dist/priorityQueue.js +99 -0
  19. package/dist/priorityQueue.js.map +1 -0
  20. package/dist/queue.d.ts +39 -0
  21. package/dist/queue.js +69 -0
  22. package/dist/queue.js.map +1 -0
  23. package/dist/stack.d.ts +38 -0
  24. package/dist/stack.js +57 -0
  25. package/dist/stack.js.map +1 -0
  26. package/dist/utils/array.d.ts +104 -0
  27. package/dist/utils/array.js +203 -0
  28. package/dist/utils/array.js.map +1 -0
  29. package/dist/utils/async.d.ts +52 -0
  30. package/dist/utils/async.js +127 -0
  31. package/dist/utils/async.js.map +1 -0
  32. package/dist/utils/compare.d.ts +91 -0
  33. package/dist/utils/compare.js +180 -0
  34. package/dist/utils/compare.js.map +1 -0
  35. package/dist/utils/csv.d.ts +31 -0
  36. package/dist/utils/csv.js +57 -0
  37. package/dist/utils/csv.js.map +1 -0
  38. package/dist/utils/date.d.ts +83 -0
  39. package/dist/utils/date.js +179 -0
  40. package/dist/utils/date.js.map +1 -0
  41. package/dist/utils/id.d.ts +5 -0
  42. package/dist/utils/id.js +27 -0
  43. package/dist/utils/id.js.map +1 -0
  44. package/dist/utils/index.d.ts +11 -0
  45. package/dist/utils/index.js +28 -0
  46. package/dist/utils/index.js.map +1 -0
  47. package/dist/utils/json.d.ts +10 -0
  48. package/dist/utils/json.js +29 -0
  49. package/dist/utils/json.js.map +1 -0
  50. package/dist/utils/logger.d.ts +71 -0
  51. package/dist/utils/logger.js +160 -0
  52. package/dist/utils/logger.js.map +1 -0
  53. package/dist/utils/number.d.ts +38 -0
  54. package/dist/utils/number.js +90 -0
  55. package/dist/utils/number.js.map +1 -0
  56. package/dist/utils/object.d.ts +57 -0
  57. package/dist/utils/object.js +107 -0
  58. package/dist/utils/object.js.map +1 -0
  59. package/dist/utils/string.d.ts +45 -0
  60. package/dist/utils/string.js +90 -0
  61. package/dist/utils/string.js.map +1 -0
  62. package/package.json +94 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Generic priority queue implemented as a binary heap.
3
+ * By default it behaves as a min-heap for numbers.
4
+ *
5
+ * @example
6
+ * const pq = new PriorityQueue<number>();
7
+ * pq.enqueue(3);
8
+ * pq.enqueue(1);
9
+ * pq.enqueue(2);
10
+ * pq.dequeue(); // 1
11
+ */
12
+ export declare class PriorityQueue<T> {
13
+ private heap;
14
+ private readonly compare;
15
+ constructor(compare?: (a: T, b: T) => number);
16
+ /**
17
+ * Number of items in the queue.
18
+ */
19
+ get length(): number;
20
+ /**
21
+ * Returns true when the queue has no items.
22
+ */
23
+ isEmpty(): boolean;
24
+ /**
25
+ * Adds an item to the queue.
26
+ */
27
+ enqueue(item: T): void;
28
+ /**
29
+ * Removes and returns the highest priority item from the queue.
30
+ * Returns undefined when the queue is empty.
31
+ */
32
+ dequeue(): T | undefined;
33
+ /**
34
+ * Returns the highest priority item without removing it.
35
+ */
36
+ peek(): T | undefined;
37
+ /**
38
+ * Removes all items from the queue.
39
+ */
40
+ clear(): void;
41
+ private bubbleUp;
42
+ private bubbleDown;
43
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PriorityQueue = void 0;
4
+ /**
5
+ * Generic priority queue implemented as a binary heap.
6
+ * By default it behaves as a min-heap for numbers.
7
+ *
8
+ * @example
9
+ * const pq = new PriorityQueue<number>();
10
+ * pq.enqueue(3);
11
+ * pq.enqueue(1);
12
+ * pq.enqueue(2);
13
+ * pq.dequeue(); // 1
14
+ */
15
+ class PriorityQueue {
16
+ constructor(compare) {
17
+ this.heap = [];
18
+ // Default: numeric ascending, otherwise fallback to 0 (no reordering)
19
+ this.compare =
20
+ compare ??
21
+ ((a, b) => typeof a === 'number' && typeof b === 'number' ? a - b : 0);
22
+ }
23
+ /**
24
+ * Number of items in the queue.
25
+ */
26
+ get length() {
27
+ return this.heap.length;
28
+ }
29
+ /**
30
+ * Returns true when the queue has no items.
31
+ */
32
+ isEmpty() {
33
+ return this.heap.length === 0;
34
+ }
35
+ /**
36
+ * Adds an item to the queue.
37
+ */
38
+ enqueue(item) {
39
+ this.heap.push(item);
40
+ this.bubbleUp(this.heap.length - 1);
41
+ }
42
+ /**
43
+ * Removes and returns the highest priority item from the queue.
44
+ * Returns undefined when the queue is empty.
45
+ */
46
+ dequeue() {
47
+ if (this.heap.length === 0)
48
+ return undefined;
49
+ const top = this.heap[0];
50
+ const last = this.heap.pop();
51
+ if (this.heap.length > 0) {
52
+ this.heap[0] = last;
53
+ this.bubbleDown(0);
54
+ }
55
+ return top;
56
+ }
57
+ /**
58
+ * Returns the highest priority item without removing it.
59
+ */
60
+ peek() {
61
+ return this.heap[0];
62
+ }
63
+ /**
64
+ * Removes all items from the queue.
65
+ */
66
+ clear() {
67
+ this.heap = [];
68
+ }
69
+ bubbleUp(index) {
70
+ while (index > 0) {
71
+ const parent = Math.floor((index - 1) / 2);
72
+ if (this.compare(this.heap[index], this.heap[parent]) >= 0) {
73
+ break;
74
+ }
75
+ [this.heap[index], this.heap[parent]] = [this.heap[parent], this.heap[index]];
76
+ index = parent;
77
+ }
78
+ }
79
+ bubbleDown(index) {
80
+ const length = this.heap.length;
81
+ while (true) {
82
+ const left = index * 2 + 1;
83
+ const right = index * 2 + 2;
84
+ let smallest = index;
85
+ if (left < length && this.compare(this.heap[left], this.heap[smallest]) < 0) {
86
+ smallest = left;
87
+ }
88
+ if (right < length && this.compare(this.heap[right], this.heap[smallest]) < 0) {
89
+ smallest = right;
90
+ }
91
+ if (smallest === index)
92
+ break;
93
+ [this.heap[index], this.heap[smallest]] = [this.heap[smallest], this.heap[index]];
94
+ index = smallest;
95
+ }
96
+ }
97
+ }
98
+ exports.PriorityQueue = PriorityQueue;
99
+ //# sourceMappingURL=priorityQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priorityQueue.js","sourceRoot":"","sources":["../src/priorityQueue.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,MAAa,aAAa;IAIxB,YAAY,OAAgC;QAHpC,SAAI,GAAQ,EAAE,CAAC;QAIrB,sEAAsE;QACtE,IAAI,CAAC,OAAO;YACV,OAAO;gBACP,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE,CACd,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,CAAY,GAAI,CAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAO;QACb,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,IAAI,CAA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M,CAAC;QAChC,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,QAAQ,GAAG,KAAK,CAAC;YAErB,IAAI,IAAI,GAAG,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAE,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9E,QAAQ,GAAG,IAAI,CAAC;YAClB,CAAC;YAED,IAAI,KAAK,GAAG,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChF,QAAQ,GAAG,KAAK,CAAC;YACnB,CAAC;YAED,IAAI,QAAQ,KAAK,KAAK;gBAAE,MAAM;YAE9B,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC;YACpF,KAAK,GAAG,QAAQ,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AA/FD,sCA+FC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Simple generic FIFO queue with amortized O(1) enqueue/dequeue.
3
+ *
4
+ * @example
5
+ * const q = new Queue<number>();
6
+ * q.enqueue(1);
7
+ * q.enqueue(2);
8
+ * q.dequeue(); // 1
9
+ * q.dequeue(); // 2
10
+ */
11
+ export declare class Queue<T> {
12
+ private items;
13
+ private head;
14
+ /**
15
+ * Adds an item to the back of the queue.
16
+ */
17
+ enqueue(item: T): void;
18
+ /**
19
+ * Removes and returns the item at the front of the queue.
20
+ * Returns undefined when the queue is empty.
21
+ */
22
+ dequeue(): T | undefined;
23
+ /**
24
+ * Returns the item at the front of the queue without removing it.
25
+ */
26
+ peek(): T | undefined;
27
+ /**
28
+ * Returns the number of items currently in the queue.
29
+ */
30
+ get length(): number;
31
+ /**
32
+ * Returns true when the queue has no items.
33
+ */
34
+ isEmpty(): boolean;
35
+ /**
36
+ * Removes all items from the queue.
37
+ */
38
+ clear(): void;
39
+ }
package/dist/queue.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Queue = void 0;
4
+ /**
5
+ * Simple generic FIFO queue with amortized O(1) enqueue/dequeue.
6
+ *
7
+ * @example
8
+ * const q = new Queue<number>();
9
+ * q.enqueue(1);
10
+ * q.enqueue(2);
11
+ * q.dequeue(); // 1
12
+ * q.dequeue(); // 2
13
+ */
14
+ class Queue {
15
+ constructor() {
16
+ this.items = [];
17
+ this.head = 0;
18
+ }
19
+ /**
20
+ * Adds an item to the back of the queue.
21
+ */
22
+ enqueue(item) {
23
+ this.items.push(item);
24
+ }
25
+ /**
26
+ * Removes and returns the item at the front of the queue.
27
+ * Returns undefined when the queue is empty.
28
+ */
29
+ dequeue() {
30
+ if (this.isEmpty()) {
31
+ return undefined;
32
+ }
33
+ const value = this.items[this.head];
34
+ this.head += 1;
35
+ // Occasionally compact the internal array to avoid unbounded growth.
36
+ if (this.head > 50 && this.head * 2 > this.items.length) {
37
+ this.items = this.items.slice(this.head);
38
+ this.head = 0;
39
+ }
40
+ return value;
41
+ }
42
+ /**
43
+ * Returns the item at the front of the queue without removing it.
44
+ */
45
+ peek() {
46
+ return this.isEmpty() ? undefined : this.items[this.head];
47
+ }
48
+ /**
49
+ * Returns the number of items currently in the queue.
50
+ */
51
+ get length() {
52
+ return this.items.length - this.head;
53
+ }
54
+ /**
55
+ * Returns true when the queue has no items.
56
+ */
57
+ isEmpty() {
58
+ return this.length === 0;
59
+ }
60
+ /**
61
+ * Removes all items from the queue.
62
+ */
63
+ clear() {
64
+ this.items = [];
65
+ this.head = 0;
66
+ }
67
+ }
68
+ exports.Queue = Queue;
69
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,KAAK;IAAlB;QACU,UAAK,GAAQ,EAAE,CAAC;QAChB,SAAI,GAAG,CAAC,CAAC;IA0DnB,CAAC;IAxDC;;OAEG;IACH,OAAO,CAAC,IAAO;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACnB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;QAEf,qEAAqE;QACrE,IAAI,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACxD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAChB,CAAC;CACF;AA5DD,sBA4DC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Simple generic LIFO stack.
3
+ *
4
+ * @example
5
+ * const s = new Stack<number>();
6
+ * s.push(1);
7
+ * s.push(2);
8
+ * s.pop(); // 2
9
+ * s.pop(); // 1
10
+ */
11
+ export declare class Stack<T> {
12
+ private items;
13
+ /**
14
+ * Pushes an item on top of the stack.
15
+ */
16
+ push(item: T): void;
17
+ /**
18
+ * Removes and returns the item from the top of the stack.
19
+ * Returns undefined when the stack is empty.
20
+ */
21
+ pop(): T | undefined;
22
+ /**
23
+ * Returns the item at the top of the stack without removing it.
24
+ */
25
+ peek(): T | undefined;
26
+ /**
27
+ * Returns the number of items currently in the stack.
28
+ */
29
+ get length(): number;
30
+ /**
31
+ * Returns true when the stack has no items.
32
+ */
33
+ isEmpty(): boolean;
34
+ /**
35
+ * Removes all items from the stack.
36
+ */
37
+ clear(): void;
38
+ }
package/dist/stack.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stack = void 0;
4
+ /**
5
+ * Simple generic LIFO stack.
6
+ *
7
+ * @example
8
+ * const s = new Stack<number>();
9
+ * s.push(1);
10
+ * s.push(2);
11
+ * s.pop(); // 2
12
+ * s.pop(); // 1
13
+ */
14
+ class Stack {
15
+ constructor() {
16
+ this.items = [];
17
+ }
18
+ /**
19
+ * Pushes an item on top of the stack.
20
+ */
21
+ push(item) {
22
+ this.items.push(item);
23
+ }
24
+ /**
25
+ * Removes and returns the item from the top of the stack.
26
+ * Returns undefined when the stack is empty.
27
+ */
28
+ pop() {
29
+ return this.items.pop();
30
+ }
31
+ /**
32
+ * Returns the item at the top of the stack without removing it.
33
+ */
34
+ peek() {
35
+ return this.items.length ? this.items[this.items.length - 1] : undefined;
36
+ }
37
+ /**
38
+ * Returns the number of items currently in the stack.
39
+ */
40
+ get length() {
41
+ return this.items.length;
42
+ }
43
+ /**
44
+ * Returns true when the stack has no items.
45
+ */
46
+ isEmpty() {
47
+ return this.items.length === 0;
48
+ }
49
+ /**
50
+ * Removes all items from the stack.
51
+ */
52
+ clear() {
53
+ this.items = [];
54
+ }
55
+ }
56
+ exports.Stack = Stack;
57
+ //# sourceMappingURL=stack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack.js","sourceRoot":"","sources":["../src/stack.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,KAAK;IAAlB;QACU,UAAK,GAAQ,EAAE,CAAC;IA4C1B,CAAC;IA1CC;;OAEG;IACH,IAAI,CAAC,IAAO;QACV,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AA7CD,sBA6CC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Returns a new array with duplicate items removed.
3
+ * Keeps the first occurrence of each item and preserves order.
4
+ *
5
+ * @example
6
+ * uniq([1, 2, 2, 3]); // [1, 2, 3]
7
+ */
8
+ export declare function uniq<T>(items: readonly T[]): T[];
9
+ /**
10
+ * Splits an array into chunks of a given size.
11
+ * If size is <= 0, returns the whole array as a single chunk.
12
+ *
13
+ * @example
14
+ * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
15
+ */
16
+ export declare function chunk<T>(items: readonly T[], size: number): T[][];
17
+ /**
18
+ * Removes falsy-like values (null, undefined, false) from an array.
19
+ *
20
+ * @example
21
+ * compact([0, 1, null, 2, undefined, 3, false]); // [0, 1, 2, 3]
22
+ */
23
+ export declare function compact<T>(items: readonly (T | null | undefined | false)[]): T[];
24
+ /**
25
+ * Flattens an array one level deep.
26
+ *
27
+ * @example
28
+ * flat([1, [2, 3], 4]); // [1, 2, 3, 4]
29
+ */
30
+ export declare function flat<T>(items: readonly (T | T[])[]): T[];
31
+ /**
32
+ * Returns the first item of an array, or undefined when empty.
33
+ *
34
+ * @example
35
+ * first([1, 2, 3]); // 1
36
+ */
37
+ export declare function first<T>(items: readonly T[]): T | undefined;
38
+ /**
39
+ * Returns the last item of an array, or undefined when empty.
40
+ *
41
+ * @example
42
+ * last([1, 2, 3]); // 3
43
+ */
44
+ export declare function last<T>(items: readonly T[]): T | undefined;
45
+ /**
46
+ * Groups an array of objects by a specific key.
47
+ *
48
+ * @example
49
+ * const users = [
50
+ * { id: 1, role: 'admin' },
51
+ * { id: 2, role: 'user' },
52
+ * { id: 3, role: 'admin' }
53
+ * ];
54
+ *
55
+ * groupBy(users, 'role');
56
+ * // {
57
+ * // admin: [{ id: 1, role: 'admin' }, { id: 3, role: 'admin' }],
58
+ * // user: [{ id: 2, role: 'user' }]
59
+ * // }
60
+ */
61
+ export declare function groupBy<T extends Record<string, any>, K extends keyof T>(items: readonly T[], key: K): Record<T[K] & PropertyKey, T[]>;
62
+ /**
63
+ * Splits items into two arrays based on a predicate.
64
+ * The first array contains items where predicate(item) is true,
65
+ * the second where it is false.
66
+ *
67
+ * @example
68
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0);
69
+ * // [[2, 4], [1, 3]]
70
+ */
71
+ export declare function partition<T>(items: readonly T[], predicate: (item: T, index: number) => boolean): [T[], T[]];
72
+ /**
73
+ * Returns the intersection of two arrays (items present in both).
74
+ *
75
+ * @example
76
+ * intersect([1, 2, 3], [2, 3, 4]); // [2, 3]
77
+ */
78
+ export declare function intersect<T>(a: readonly T[], b: readonly T[]): T[];
79
+ /**
80
+ * Returns the difference of two arrays (items in a that are not in b).
81
+ *
82
+ * @example
83
+ * difference([1, 2, 3], [2]); // [1, 3]
84
+ */
85
+ export declare function difference<T>(a: readonly T[], b: readonly T[]): T[];
86
+ /**
87
+ * Returns a new array with unique items based on a key selector.
88
+ *
89
+ * @example
90
+ * uniqueBy(
91
+ * [{ id: 1 }, { id: 1 }, { id: 2 }],
92
+ * (item) => item.id
93
+ * ); // [{ id: 1 }, { id: 2 }]
94
+ */
95
+ export declare function uniqueBy<T, K extends PropertyKey>(items: readonly T[], keyFn: (item: T) => K): T[];
96
+ /**
97
+ * Returns a new array sorted by a user-provided selector.
98
+ * Does not mutate the original array.
99
+ *
100
+ * @example
101
+ * sortBy(users, u => u.age);
102
+ * sortBy(users, u => u.name.toLowerCase());
103
+ */
104
+ export declare function sortBy<T, K extends string | number>(items: readonly T[], selector: (item: T) => K, direction?: 'asc' | 'desc'): T[];
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uniq = uniq;
4
+ exports.chunk = chunk;
5
+ exports.compact = compact;
6
+ exports.flat = flat;
7
+ exports.first = first;
8
+ exports.last = last;
9
+ exports.groupBy = groupBy;
10
+ exports.partition = partition;
11
+ exports.intersect = intersect;
12
+ exports.difference = difference;
13
+ exports.uniqueBy = uniqueBy;
14
+ exports.sortBy = sortBy;
15
+ /**
16
+ * Returns a new array with duplicate items removed.
17
+ * Keeps the first occurrence of each item and preserves order.
18
+ *
19
+ * @example
20
+ * uniq([1, 2, 2, 3]); // [1, 2, 3]
21
+ */
22
+ function uniq(items) {
23
+ return Array.from(new Set(items));
24
+ }
25
+ /**
26
+ * Splits an array into chunks of a given size.
27
+ * If size is <= 0, returns the whole array as a single chunk.
28
+ *
29
+ * @example
30
+ * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
31
+ */
32
+ function chunk(items, size) {
33
+ if (size <= 0)
34
+ return [items.slice()];
35
+ const result = [];
36
+ for (let i = 0; i < items.length; i += size) {
37
+ result.push(items.slice(i, i + size));
38
+ }
39
+ return result;
40
+ }
41
+ /**
42
+ * Removes falsy-like values (null, undefined, false) from an array.
43
+ *
44
+ * @example
45
+ * compact([0, 1, null, 2, undefined, 3, false]); // [0, 1, 2, 3]
46
+ */
47
+ function compact(items) {
48
+ return items.filter(Boolean);
49
+ }
50
+ /**
51
+ * Flattens an array one level deep.
52
+ *
53
+ * @example
54
+ * flat([1, [2, 3], 4]); // [1, 2, 3, 4]
55
+ */
56
+ function flat(items) {
57
+ const result = [];
58
+ for (const item of items) {
59
+ if (Array.isArray(item)) {
60
+ result.push(...item);
61
+ }
62
+ else {
63
+ result.push(item);
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+ /**
69
+ * Returns the first item of an array, or undefined when empty.
70
+ *
71
+ * @example
72
+ * first([1, 2, 3]); // 1
73
+ */
74
+ function first(items) {
75
+ return items[0];
76
+ }
77
+ /**
78
+ * Returns the last item of an array, or undefined when empty.
79
+ *
80
+ * @example
81
+ * last([1, 2, 3]); // 3
82
+ */
83
+ function last(items) {
84
+ return items.length ? items[items.length - 1] : undefined;
85
+ }
86
+ /**
87
+ * Groups an array of objects by a specific key.
88
+ *
89
+ * @example
90
+ * const users = [
91
+ * { id: 1, role: 'admin' },
92
+ * { id: 2, role: 'user' },
93
+ * { id: 3, role: 'admin' }
94
+ * ];
95
+ *
96
+ * groupBy(users, 'role');
97
+ * // {
98
+ * // admin: [{ id: 1, role: 'admin' }, { id: 3, role: 'admin' }],
99
+ * // user: [{ id: 2, role: 'user' }]
100
+ * // }
101
+ */
102
+ function groupBy(items, key) {
103
+ const result = {};
104
+ for (const item of items) {
105
+ const groupKey = item[key];
106
+ if (!result[groupKey]) {
107
+ result[groupKey] = [];
108
+ }
109
+ result[groupKey].push(item);
110
+ }
111
+ return result;
112
+ }
113
+ /**
114
+ * Splits items into two arrays based on a predicate.
115
+ * The first array contains items where predicate(item) is true,
116
+ * the second where it is false.
117
+ *
118
+ * @example
119
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0);
120
+ * // [[2, 4], [1, 3]]
121
+ */
122
+ function partition(items, predicate) {
123
+ const truthy = [];
124
+ const falsy = [];
125
+ items.forEach((item, index) => {
126
+ if (predicate(item, index)) {
127
+ truthy.push(item);
128
+ }
129
+ else {
130
+ falsy.push(item);
131
+ }
132
+ });
133
+ return [truthy, falsy];
134
+ }
135
+ /**
136
+ * Returns the intersection of two arrays (items present in both).
137
+ *
138
+ * @example
139
+ * intersect([1, 2, 3], [2, 3, 4]); // [2, 3]
140
+ */
141
+ function intersect(a, b) {
142
+ const setB = new Set(b);
143
+ return a.filter((item) => setB.has(item));
144
+ }
145
+ /**
146
+ * Returns the difference of two arrays (items in a that are not in b).
147
+ *
148
+ * @example
149
+ * difference([1, 2, 3], [2]); // [1, 3]
150
+ */
151
+ function difference(a, b) {
152
+ const setB = new Set(b);
153
+ return a.filter((item) => !setB.has(item));
154
+ }
155
+ /**
156
+ * Returns a new array with unique items based on a key selector.
157
+ *
158
+ * @example
159
+ * uniqueBy(
160
+ * [{ id: 1 }, { id: 1 }, { id: 2 }],
161
+ * (item) => item.id
162
+ * ); // [{ id: 1 }, { id: 2 }]
163
+ */
164
+ function uniqueBy(items, keyFn) {
165
+ const seen = new Set();
166
+ const result = [];
167
+ for (const item of items) {
168
+ const key = keyFn(item);
169
+ if (!seen.has(key)) {
170
+ seen.add(key);
171
+ result.push(item);
172
+ }
173
+ }
174
+ return result;
175
+ }
176
+ /**
177
+ * Returns a new array sorted by a user-provided selector.
178
+ * Does not mutate the original array.
179
+ *
180
+ * @example
181
+ * sortBy(users, u => u.age);
182
+ * sortBy(users, u => u.name.toLowerCase());
183
+ */
184
+ function sortBy(items, selector, direction = 'asc') {
185
+ const result = items.slice();
186
+ result.sort((a, b) => {
187
+ const av = selector(a);
188
+ const bv = selector(b);
189
+ if (av === bv)
190
+ return 0;
191
+ if (av == null)
192
+ return direction === 'asc' ? 1 : -1;
193
+ if (bv == null)
194
+ return direction === 'asc' ? -1 : 1;
195
+ if (av < bv)
196
+ return direction === 'asc' ? -1 : 1;
197
+ if (av > bv)
198
+ return direction === 'asc' ? 1 : -1;
199
+ return 0;
200
+ });
201
+ return result;
202
+ }
203
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/utils/array.ts"],"names":[],"mappings":";;AAOA,oBAEC;AASD,sBAQC;AAQD,0BAEC;AAQD,oBAUC;AAQD,sBAEC;AAQD,oBAEC;AAkBD,0BAeC;AAWD,8BAgBC;AAQD,8BAGC;AAQD,gCAGC;AAWD,4BAgBC;AAUD,wBAqBC;AAtND;;;;;;GAMG;AACH,SAAgB,IAAI,CAAI,KAAmB;IACzC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,KAAK,CAAI,KAAmB,EAAE,IAAY;IACxD,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,CAAC,KAAK,CAAC,KAAK,EAAS,CAAC,CAAC;IAE7C,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG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