You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@sanity/diff

Package Overview
Maintainers
93
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Source code not available
We could not scan this package. Some page functionalities have been disabled

@sanity/diff

Generates diffs between documents and primitive types

3.99.1-bitter-lemon.5
bitter-lemon
Source
npmnpm
Version published
Weekly downloads
198K
4.28%
Maintainers
93
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

sanity

FAQs

Package last updated on 18 Jul 2025

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