Skip to content

Commit

Permalink
clean unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jul 25, 2024
1 parent 39af62e commit e0b41ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 120 deletions.
95 changes: 0 additions & 95 deletions src/utils/composition.js

This file was deleted.

14 changes: 11 additions & 3 deletions src/utils/functions.js → src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@

import { pick } from 'lodash';

type GetMatcher<T> = (target: T) => Parameters<Array<T>['find']>[0];
type PickProps<T extends object, U extends keyof T> = Array<U | readonly U[]>;

/**
* Copy properties from corresponding objects in a source array to objects in a target array.
* It returns the target array that contain modified objects
* It returns the target array that contains modified objects
*
* @param targetArray the target array to copy to inside objects
* @param sourceArray the source array from which to copy properties of objects
* @param matcher predicate to find the corresponding between a target element and a source element
* @param props properties names to copy, specified individually or in array
* @return the target array
*/
export const assignArray = (targetArray, sourceArray, matcher, ...props) => {
export function assignArray<T extends object, U extends keyof T>(
targetArray: T[],
sourceArray: T[],
matcher: GetMatcher<T>,
...props: PickProps<T, U>
) {
targetArray?.forEach((targetObj) => {
const matcherOfTarget = matcher(targetObj);
const sourceObj = sourceArray?.find(matcherOfTarget);
Expand All @@ -26,4 +34,4 @@ export const assignArray = (targetArray, sourceArray, matcher, ...props) => {
});

return targetArray;
};
}
22 changes: 0 additions & 22 deletions src/utils/properties.js

This file was deleted.

0 comments on commit e0b41ac

Please sign in to comment.