Nighttime Peanut Migrations

    This package has been deprecated

    Author message:

    Migrated to new name w/ further updates: crud-object-diff

    crud-compare
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.0 • Public • Published

    CRUD Compare - JS State Comparison Helper

    npm npm bundle size Coverage GitHub PRs Welcome CircleCI

    This is a very lightweight and ⚡️ fast library for comparing objects and arrays (mostly before save) to get the created, updated, and deleted values for state comparisons.

    • 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

    1. Fork it and create your feature branch: git checkout -b my-new-feature
    2. Commit your changes: git commit -am "Add some feature"
    3. Push to the branch: git push origin my-new-feature
    4. Submit a pull request

    License

    MIT

    Install

    npm i crud-compare

    DownloadsWeekly Downloads

    0

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    40.9 kB

    Total Files

    12

    Last publish

    Collaborators

    • tjmoses