Socket
Socket
Sign inDemoInstall

@sanity/diff

Package Overview
Dependencies
1
Maintainers
48
Versions
771
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @sanity/diff

Generates diffs between documents and primitive types


Version published
Weekly downloads
102K
decreased by-1.86%
Maintainers
48
Install size
776 kB
Created
Weekly downloads
 

Readme

Source

@sanity/diff: Tools for diffing data structures

@sanity/diff is a library for calculating and presenting diffs of content.

Concepts and architecture

  • The main data structure is Diff which represents a difference between two versions. This is a nested data structure so if it's an ObjectDiff, then its children will have Diff as well.

    The Diff is built on top of the unchanged, added and removed primitives. This means that it will contain both versions at the same time and it's always trivial to recreate the old/new version (by ignoring the added/removed parts of the diff).

    Note that for arrays and objects, unchanged/added/removed only have a "shallow" meaning. An ObjectDiff will have a unchanged field if the field was present in both the old and new version - regardless of whether there's any internal changes.

  • Diff also supports annotations. These contain information about when a change was introduced and who was responsible for it.

  • To construct a Diff you need to represent the versions as Input types and use diffInput(from,to) to create the diff. The primary reason for a separate Input type is to support passing along annotations. In addition, this allows us to optimize based on the object equality of the inputs.

  • There are multiple ways of presenting a diff: Sometimes you want to only show the fields that has changed, and other times you want to show the full new (or old!) document interspersed with the changes.

    This library does not contain any UI components, but instead provides various presentation-related helper functions.

Keywords

FAQs

Last updated on 23 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc