-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
customComparator #5
Comments
I liked the idea I think it is very easy to implement, I started an implementation in a new branch The idea is to do something very close to what you suggested: import { Audit } from "entity-diff";
const before = {
name: "Mason",
age: 20,
updatedAt: "2021-03-02T20:08:13.000Z"
};
const after = {
name: "Mason",
age: 20,
updatedAt: "2021-03-02T21:08:13+01:00"
};
const options = [
{
key: "updatedAt",
customFormatter: date => new Date(date).toISOString(),
customComparator: (from, to) => new Date(from).toISOString() !== new Date(to).toISOString()
}
];
const audit = new Audit({ options });
const result = audit.diff(before, after);
// result:
// [] the only difference is that I'm going to pass a function that receives both values and the person is free to compare the way they want :D forgive my english from google translator... :C |
Hello @Throyer :) |
Unfortunately I'm not having time because of work :C |
What do you think about adding a new parameter to an options called "customComparator"? Could work like customFormatter, but be used not to display differences but to compare values?
I think it can be very useful, e.g. when comparing dates, e.g. stored in db (UTC timezone) vs from request (in local time zone) ...
it could also be used in comparing objects or arrays, e.g. someone wants to check just the number of elements in an array
Extended example from readme:
In this case result will be empty because
2021-03-02T20:08:13.000Z === 2021-03-02T21:08:13+01:00
The text was updated successfully, but these errors were encountered: