|
function compareObjectVals (toCompareVals: [Object[], Object[]], key: string) : |
currently - the matching of object is based on a "key" property.
this has a limitation for object with complex keys (multiple properties) - or where any other logic should be applied to find the match.
I suggest to extend the "key" parameter, so it allow passing a Matcher function. (but also allow passing a simple string - so you don't create breaking changes)
key: string | (left: any, right: any)=>bool
the library will check if the given key is a string or a function.
if its a string - the library will continue just like always - look for a property with the name of the key.
but if a function is given - the library will apply the function on 2 items to conclude if they "match".
lets say we have a Person object, and the key is based on firstName + lastName - we could write something like:
interface Person
{
firstName: string;
lastName: firstName;
birthDate: Date;
...
}
compareObjectVals([arrBefore, arrAfter], (a, b) => a.firstName === b.firstName && a.lastName === b.lastName);
if it's fine by you - I can work on that a create a pull request.