feat: upgrade prettier to v3

This commit is contained in:
Thea Schöbl
2023-12-05 10:36:04 +00:00
parent 991ed1cb1f
commit 31a6ebfd3f
50 changed files with 455 additions and 362 deletions

View File

@@ -20,8 +20,11 @@
* iteratee is invoked with one argument: (value).
*/
export function keyBy<T>(collection: T[], key: (item: T) => string | number): Record<string, T> {
return collection.reduce((accumulator, item) => {
accumulator[key(item)] = item;
return accumulator;
}, {} as Record<string | number, T>);
return collection.reduce(
(accumulator, item) => {
accumulator[key(item)] = item;
return accumulator;
},
{} as Record<string | number, T>,
);
}

View File

@@ -17,12 +17,15 @@
* Pick a set of properties from an object
*/
export function pick<T extends object, U extends keyof T>(object: T, keys: U[]): Pick<T, U> {
return keys.reduce((accumulator, key) => {
if (object.hasOwnProperty(key)) {
accumulator[key] = object[key];
}
return accumulator;
}, {} as Pick<T, U>);
return keys.reduce(
(accumulator, key) => {
if (object.hasOwnProperty(key)) {
accumulator[key] = object[key];
}
return accumulator;
},
{} as Pick<T, U>,
);
}
/**
@@ -32,10 +35,13 @@ export function pickBy<T extends object, U extends keyof T>(
object: T,
predicate: (value: T[U], key: U) => boolean,
): Pick<T, U> {
return (Object.keys(object) as U[]).reduce((accumulator, key) => {
if (predicate(object[key], key)) {
accumulator[key] = object[key];
}
return accumulator;
}, {} as Pick<T, U>);
return (Object.keys(object) as U[]).reduce(
(accumulator, key) => {
if (predicate(object[key], key)) {
accumulator[key] = object[key];
}
return accumulator;
},
{} as Pick<T, U>,
);
}

View File

@@ -18,9 +18,12 @@
*/
export function uniqBy<T>(array: T[], transform: (item: T) => string | number): T[] {
return Object.values(
array.reduce((accumulator, current) => {
accumulator[transform(current)] = current;
return accumulator;
}, {} as Record<string | number, T>),
array.reduce(
(accumulator, current) => {
accumulator[transform(current)] = current;
return accumulator;
},
{} as Record<string | number, T>,
),
);
}