Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/diff

Package Overview
Dependencies
Maintainers
26
Versions
938
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/diff

Generates diffs between documents and primitive types

  • 2.20.1-canary.117
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
143K
increased by14.26%
Maintainers
26
Weekly downloads
 
Created

What is @sanity/diff?

@sanity/diff is a JavaScript library designed to compute and represent differences between two JSON documents. It is particularly useful for applications that need to track changes in data structures, such as content management systems or collaborative editing tools.

What are @sanity/diff's main functionalities?

Compute Differences

This feature allows you to compute the differences between two JSON documents. The `diff` function takes two objects and returns an object representing the changes.

const { diff } = require('@sanity/diff');

const oldDoc = { name: 'Alice', age: 30 };
const newDoc = { name: 'Alice', age: 31 };

const differences = diff(oldDoc, newDoc);
console.log(differences);

Patch Application

This feature allows you to apply a patch to a JSON document. The `applyPatch` function takes an original object and a patch object, and returns the updated object.

const { applyPatch } = require('@sanity/diff');

const oldDoc = { name: 'Alice', age: 30 };
const patch = { age: 31 };

const newDoc = applyPatch(oldDoc, patch);
console.log(newDoc);

Visual Representation

This feature allows you to get a visual representation of the differences between two JSON documents. The `formatDiff` function takes the differences object and returns a human-readable string.

const { diff, formatDiff } = require('@sanity/diff');

const oldDoc = { name: 'Alice', age: 30 };
const newDoc = { name: 'Alice', age: 31 };

const differences = diff(oldDoc, newDoc);
const formattedDiff = formatDiff(differences);
console.log(formattedDiff);

Other packages similar to @sanity/diff

Keywords

FAQs

Package last updated on 22 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc