How to use jsondiffpatch - 10 common examples

To help you get started, we’ve selected a few jsondiffpatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metaspace2020 / metaspace / metaspace / graphql / src / modules / dataset / controller / Mutation.ts View on Github external
export function processingSettingsChanged(ds: EngineDataset, update: DatasetUpdateInput & { metadata: MetadataRoot }) {
  let newDB = false, procSettingsUpd = false, metaDiff = null;
  if (update.databaseIds) {
    newDB = true;
  }

  if (update.adducts || update.neutralLosses || update.chemMods
    || update.ppm || update.numPeaks || update.decoySampleSize
    || update.analysisVersion) {
    procSettingsUpd = true;
  }

  if (update.metadata) {
    const metaDelta = jsondiffpatch.diff(ds.metadata, update.metadata),
      metaDiff = (jsondiffpatch.formatters as any).jsonpatch.format(metaDelta);

    for (let diffObj of metaDiff) {
      if (diffObj.op !== 'move') {  // ignore permutations in arrays
        const procSettingsPaths = [
          '/MS_Analysis/Polarity',
          '/MS_Analysis/Detector_Resolving_Power',
        ];
        for (let path of procSettingsPaths) {
          if (diffObj.path.startsWith(path))
            procSettingsUpd = true;
        }
      }
    }
  }
github open-source-labs / reactime / src / app / components / Diff.jsx View on Github external
function Diff({ snapshot, show }) {
  const [mainState] = useStoreContext();
  const { currentTab, tabs } = mainState;
  const { snapshots, viewIndex, sliderIndex } = tabs[currentTab];
  let previous;

  // previous follows viewIndex or sliderIndex
  if (viewIndex !== -1) {
    previous = snapshots[viewIndex - 1];
  } else {
    previous = snapshots[sliderIndex - 1];
  }

  const delta = diff(previous, snapshot);
  // returns html in string
  const html = formatters.html.format(delta, previous);
  if (show) formatters.html.showUnchanged();
  else formatters.html.hideUnchanged();

  if (previous === undefined || delta === undefined) return <div> states are equal </div>;
  return (
    <div>
      { ReactHtmlParser(html) }
    </div>
  );
}
github SolidZORO / leaa / packages / leaa-api / src / utils / logger.util.ts View on Github external
prevItem,
    nextItem,
    constructorName,
  }: {
    id: number | string;
    prevItem: any;
    nextItem: any;
    constructorName: string;
  }) => {
    const diffObject = diff(prevItem, nextItem);

    // TIPS: if update no change, no write log.
    if (diffObject) {
      // log('info', `update item #${id} successful PREV-ITEM: \n${JSON.stringify(prevItem)}\n\n`, constructorName);
      // log('info', `update item #${id} successful NEXT-ITEM: \n${JSON.stringify(nextItem)}\n\n`, constructorName);
      log('info', `↔️ update item #${id} DIFF: ${JSON.stringify(diff(prevItem, nextItem))}`, constructorName);
    }
  },
};
github SolidZORO / leaa / packages / leaa-api / src / utils / logger.util.ts View on Github external
updateLog: ({
    id,
    prevItem,
    nextItem,
    constructorName,
  }: {
    id: number | string;
    prevItem: any;
    nextItem: any;
    constructorName: string;
  }) => {
    const diffObject = diff(prevItem, nextItem);

    // TIPS: if update no change, no write log.
    if (diffObject) {
      // log('info', `update item #${id} successful PREV-ITEM: \n${JSON.stringify(prevItem)}\n\n`, constructorName);
      // log('info', `update item #${id} successful NEXT-ITEM: \n${JSON.stringify(nextItem)}\n\n`, constructorName);
      log('info', `↔️ update item #${id} DIFF: ${JSON.stringify(diff(prevItem, nextItem))}`, constructorName);
    }
  },
};
github dtjohnson / xlsx-populate / test / helpers / matchers.js View on Github external
compare(actual, expected) {
                    const result = {};
                    actual = JSON.parse(JSON.stringify(actual));
                    expected = JSON.parse(JSON.stringify(expected));
                    result.pass = util.equals(actual, expected, customEqualityTesters);

                    if (!result.pass) {
                        result.name = "JSON objects don't match";
                        result.message = jsondiffpatch.formatters.console.format(jsondiffpatch.diff(expected, actual));
                    }

                    return result;
                }
            };
github w3c / webidl2.js / test / util / collect.js View on Github external
diff(target = this.readJSON()) {
    return jdp.diff(target, this.ast);
  }
}
github AEB-labs / cruddl / spec / helpers / equal-json.ts View on Github external
compare: function(actual: any, expected: any): CustomMatcherResult {
                actual = JSON.parse(JSON.stringify(actual));
                expected = JSON.parse(JSON.stringify(expected));
                const pass = util.equals(actual, expected, customEqualityTesters);
                return {
                    pass,
                    message: pass ? 'ok' : 'JSON objects not equal. \r\nDIFF:\r\n' + jsondiffpatch.formatters.console.format(jsondiffpatch.diff(expected, actual))
                };
            },
        };
github AEB-labs / graphql-weaver / spec / helpers / equal-json.ts View on Github external
compare: function(actual: any, expected: any): CustomMatcherResult {
                actual = normalizeJSON(actual);
                expected = normalizeJSON(expected);
                const pass = util.equals(actual, expected, customEqualityTesters);
                return {
                    pass,
                    message: pass ? 'ok' : 'JSON objects not equal. \r\nACTUAL:\r\n'+ JSON.stringify(actual, null, "\t") +'\r\nEXPECTED:\r\n:' + JSON.stringify(expected, null, "\t") + '\r\nDIFF:\r\n' + jsondiffpatch.formatters.console.format(jsondiffpatch.diff(expected, actual))
                };
            },
        };
github frodare / addon-redux / src / withRedux.js View on Github external
const onDispatchListener = (action, prev, next) => {
    const diff = differ(prev, next)
    const date = new Date()
    channel.emit(events.ON_DISPATCH, {id: nextId++, date, action, diff, prev, next})
  }
github ipfs / js-ipfs / src / cli / commands / config / profile / apply.js View on Github external
argv.resolve((async () => {
      const ipfs = await argv.getIpfs()
      const diff = await ipfs.config.profiles.apply(argv.profile, { dryRun: argv.dryRun })
      const delta = JSONDiff.diff(diff.original, diff.updated)
      const res = JSONDiff.formatters.console.format(delta, diff.original)

      if (res) {
        argv.print(res)

        if (argv.isDaemonOn()) {
          argv.print('\nThe IPFS daemon is running in the background, you may need to restart it for changes to take effect.')
        }
      } else {
        argv.print(`IPFS config already contains the settings from the '${argv.profile}' profile`)
      }
    })())
  }

jsondiffpatch

Diff & Patch for Javascript objects

MIT
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis

Popular jsondiffpatch functions