Entity diff
A simple entity diff generator.
generates a list of changes made to the entity.
All you need are two objects, one with the entity before the changes and the other with it after the changes.
how to Install
npm:
npm install entity-diff
yarn:
yarn add entity-diff
How to use:
;;;;;// result:// [// {// key: "name",// from: "Mason",// to: "Mason Floyd"// }// ]
Audit Options:
It is possible to change some information in the final result of the diffs using parameters.
Ignoring properties
It is possible to ignore some keys of the objects audited through a list.
; ; ; ; ; ; // result: // [ // { // key: "age", // from: 20, // to: 25 // } // ]
Different name in the keys
Changing the name that appears in the key in the result
; ; ; ; ; ; // result: // [ // { // key: "Person name", // title defined in options // from: "Mason", // to: "Mason Floyd" // } // ]
formatting the values displayed in "from" and "to"
It can be done through a function defined in options
; ; ; ; ; ; // result: // [ // { // key: "updatedAt", // from: null, // to: "09/08/2020" // } // ]
array
diffs
Working with when working with arrays, diffs are generated only when there is some value in "arrayOptions"
.
The "key"
property represents the key used to find the entities within the other array. it is optional, but by default entity-diff looks for the "id"
key.
; ; ; ; ; ; // resut: // [ // { // "key": "roles", // "type": "ARRAY", // "details": [ // { // "key": "ADM", // "type": "MODIFIED", // "details": [ // { // "key": "name", // "from": "ADM", // "to": "SUPER_USER" // } // ] // }, // { // "key": "TEC", // "type": "NEW", // "details": [ // { // "key": "id", // "from": null, // "to": 3 // }, // { // "key": "name", // "from": null, // "to": "TEC" // } // ] // }, // { // "key": "USER", // "type": "REMOVED", // "details": [ // { // "key": "id", // "from": 2, // "to": null // }, // { // "key": "name", // "from": "USER", // "to": null // } // ] // } // ] // } // ]