CRUD Compare - JS State Comparison Helper
This is a very
-
Provides Created, Updated, and Deleted values (via separate arrays) from comparing two arrays of objects given a related key, using the compareObjectVals function.
-
Provides Created and Deleted values between two arrays of primitives (strings, numbers, etc.) using the compareArrayVals function.
-
Lastly, has a deep Object and Array comparing helper functions for quick equivalence checks using the isEqualObject or isEqualArray function. *Note: Object.is() is used for primative data type comparison checks.
Install
npm install crud-compare
Usage
const compare = require("crud-compare");
const { createdVals, updatedVals, deletedVals } = compare.compareObjectVals(
[
originalArrayOfObjects,
newArrayOfObjects
],
relatedObjectKey
);
// perform crud operations...
const { createdVals, deletedVals } = compare.compareArrayVals(
[
originalArrayItem,
updatedArrayItem
]
);
// perform further operations...
const areObjectsEquivalent = compare.isEqualObject(
obj1,
obj2
);
The values of the returned created, updated, or deleted values for compareObjectVals / compareArrayVals will be null if they do not exist. A shallow compare is performed on objects within the compareObjectVals function.
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT