Git Product home page Git Product logo

log-diff's Introduction

log-diff

A function that logs the difference between two objects. The differences are printed in a Github-looking style. If you have 2 objects - left and right:

const left = {
    name: 'first object',
    nested: {
        cool: false,
        old: 'fashion',
        list: ['one', 'two'],
    },
    you: {
        cant: {
            touch: 'this',
        },
    },
};

const right = {
    name: 'second object',
    nested: {
        cool: true,
        list: ['one', 'two', 'three'],
    },
}

logDiff(left, right);

logDiff would print the following:

log-diff image

Keep in mind the order of the arguments for the diff - from the Left Hand Side (lhs) to the Right Hand Side (rhs) - logDiff(lhs, rhs)

Getting Started

logDiff is exported in the dist folder as:

  • CommonJS module (cjs)
  • ES module (esm)
  • UMD build (umd)

One fast way to use logDiff straight in the browser is to import the ES module version with dynamic module imports. This is supported by newer versions of Chrome, Firefox, Safari and Edge - see caniuse.com.

This way logDiff can be loaded like so:

(async () => {
  try {
    // Specify where logdiff.esm.js is located
    const scriptUrl = 'https://logdfiff.firebaseapp.com/logdiff.esm.js';
    const { default: logDiff } = await import(scriptUrl);
    window.logDiff = logDiff;
    console.log('logDiff loaded!');
  } catch (err) {
    console.log(err);
  }
})();

Check examples/index.html for example usage.

Run / Development

For developing logDiff the dependencies can be installed with yarn or npm:

yarn
# or 
npm install

To transpile and bundle run the following:

yarn build
# or 
npm run build

To watch for file changes and trigger a new build:

yarn dev
# or 
npm run dev

Built With

  • deep-diff - Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
  • rollup.js - ES6 module bundler
  • eslint.js - a pluggable tool for identifying and reporting on patterns in JavaScript

License

MIT.

log-diff's People

Contributors

karlhedins avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.