JSPM

object-diff-gen

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q25303F
  • License MIT

A utility function to compare two objects based on missing properties, types and values

Package Exports

  • object-diff-gen

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-diff-gen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JavaScriptObjectComparator v1.0.2

This utility method conpares two Javascript objects and provides the following information as a javascript object:

  1. Missing properties
  2. Properties having Mismatch types
  3. Properties having Mismatch values

Installation

npm i --save @arijit.sil/object-diff-gen

Example Usage


let incomingStructure = {
    deviceName: "A",
    device: { 
      id: 1,
      value: "3",  // type mistmatch
      prop1: "new type", // value mismatch
            // missing key
      signals: {
        rawType: "digital", // value mismatch
        rawValue: 3  // value mismatch
      }
    }
  };
  
  let baseStructure = {
    deviceName: "A",
    device: {
      id: 1,
      value: 3,
      prop1: "old type",
      prop2: "some value",
      signals: {
        rawType: "digitals",
        rawValue: 2
      }
    }
  };

  console.log(objectComparator([baseStructure, incomingStructure]));

Example Output

{
missingkeys: [ 'device.prop2' ],
mismatchValue: [
  'device',
  'device.value',
  'device.prop1',
  'device.prop2',
  'device.signals',
  'device.signals.rawType',
  'device.signals.rawValue'
],
mismatchType: [ 'device.value', 'device.prop2' ]
}

Reference Object

Reference Object can be changed using the "ref" parameter to the function. By default 0th Object is considered for reference.

  objectComparator([baseStructure, incomingStructure], ref = 0 or 1)