npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fsoft/diff-patch

v0.1.9

Published

Deep compare two objects and produces a diffData to transform object1 to object2

Downloads

3

Readme

diff-patch

Introduction

diff-patch is a library that exposes two functions, diff and patch.

The library does not have any dependencies.

The diff function takes two objects (obj1 and obj2) and deep compares them, returning an object that represents the difference between the two (the diffData). diffData is an object that can be used to apply the diff to obj1 to get an object that is the same as obj2.

The patch function takes an obj and a diffData object and applies the diff to the object, returning a new object.

The diff and patch functions are implemented in the following languages:

  • TypeScript
  • Python3

The diffData object can be used interchangeably between the languages.
This makes this library very useful for networked applications, where the client and server are written in different languages.

diffData can be serialized to JSON and deserialized back to an object. It aims to be as small as possible, and is designed to be used in a networked environment.

More languages will be added in the future, contributions are welcome.

Usage

TypeScript

To install the TypeScript version of diff-patch, run:

npm install @fsoft/diff-patch

Then, in your TypeScript code:

import { diff, patch } from '@fsoft/diff-patch';

const obj1 = {
  a: 1,
  b: 2,
  c: {
    d: 3,
    e: 4,
  },
};

const obj2 = {
  a: 1,
  b: 2,
  c: {
    d: 3,
    e: 5,   // changed
  },
};

// create the diff data
const diffData = diff(obj1, obj2);

// show the diff data for debugging
console.log( "diffData: ", diffData);

// apply the diff data to obj1 to get an object that is the same as obj2
const obj3 = patch(obj1, diffData);

// show the result for debugging
console.log( "obj3: ", obj3);

Contributors

This library was created by Fabio Rotondo.

New language implementations are more than welcome.
Please open an issue or a pull request if you want to contribute.

Collaborators:

The official repository for this library is here.

License

This library is licensed under the MIT License.
See the LICENSE file for details.