Skip to content

Commit d882e9f

Browse files
lint
1 parent 445be47 commit d882e9f

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export * from './valuesOf';
1313
export * from './findAllWithRegex';
1414
export * from './flattenObject';
1515
export * from './aggregateObjects';
16-
export * from './partitionObjectArray';
16+
export * from './partitionObjectArray';

src/partitionObjectArray.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33

44
/**
5-
* Type that represents the partitioned properties from an object type T.
5+
* Type that represents the partitioned properties from an object type T.
66
* For each selected property K from T, creates an array of that property's type.
77
* Also includes a 'rest' property containing an array of objects with all non-selected properties.
8-
*
98
* @template T - The source object type
109
* @template K - The keys to partition from T
1110
* @example
@@ -34,11 +33,10 @@ type PartitionedArrayProperties<T, K extends keyof T> = {
3433
/** The array of remaining properties not selected for partitioning */
3534
rest: Array<Omit<T, K>>;
3635
};
37-
36+
3837
/**
3938
* Partitions an array of objects by separating specified properties into their own arrays
4039
* while keeping the remaining properties grouped in a 'rest' array.
41-
*
4240
* @template T - The type of objects in the input array
4341
* @template K - The keys of properties to partition
4442
* @param items - Array of objects to partition
@@ -50,10 +48,10 @@ type PartitionedArrayProperties<T, K extends keyof T> = {
5048
* { id: 2, name: 'Jane', age: 30, city: 'LA' }
5149
* ]
5250
* const result = partitionObjectArray(items, ['id', 'name']);
53-
* // Returns: {
54-
* // id: [1, 2],
55-
* // name: ['John', 'Jane'],
56-
* // rest: [{age: 25, city: 'NY'}, {age: 30, city: 'LA'}]
51+
* // Returns: {
52+
* // id: [1, 2],
53+
* // name: ['John', 'Jane'],
54+
* // rest: [{age: 25, city: 'NY'}, {age: 30, city: 'LA'}]
5755
* // }
5856
*/
5957
export const partitionObjectArray = <T extends object, K extends keyof T>(
@@ -62,22 +60,20 @@ type PartitionedArrayProperties<T, K extends keyof T> = {
6260
): PartitionedArrayProperties<T, K> =>
6361
items.reduce((acc, item) => {
6462
const result = { ...acc } as PartitionedArrayProperties<T, K>;
65-
63+
6664
properties.forEach((prop) => {
6765
const currentArray = (acc[prop] || []) as T[K][];
6866
result[prop] = [...currentArray, item[prop]] as any;
6967
});
70-
68+
7169
const restObject = {} as Omit<T, K>;
7270
Object.entries(item).forEach(([key, value]) => {
7371
if (!properties.includes(key as K)) {
7472
(restObject as any)[key] = value;
7573
}
7674
});
77-
75+
7876
result.rest = [...(acc.rest || []), restObject];
79-
77+
8078
return result;
8179
}, {} as PartitionedArrayProperties<T, K>);
82-
83-

src/tests/flattenObject.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ describe('flattenObject', () => {
118118
user_grandParents: '',
119119
});
120120
});
121-
});
121+
});

src/tests/partitionObjectArray.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect } from 'chai';
22
import { partitionObjectArray } from '../partitionObjectArray';
33

4-
54
describe('partitionObjectArray', () => {
65
it('should handle empty array', () => {
76
const result = partitionObjectArray([], ['id', 'name']);
@@ -132,4 +131,4 @@ describe('partitionObjectArray', () => {
132131
]
133132
});
134133
});
135-
});
134+
});

0 commit comments

Comments
 (0)