Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Apr 19, 2024 via pnpm

diff 5.0.0

A javascript text diff implementation.
Package summary
Share
0
issues
1
license
1
BSD-3-Clause
Package created
29 Mar 2011
Version published
8 Nov 2020
Maintainers
1
Total deps
1
Direct deps
0
License
BSD-3-Clause

Issues

0
This package has no issues

Licenses

BSD 3-Clause "New" or "Revised" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
use-trademark
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
diff@5.0.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of diff 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does diff do?

The diff package, otherwise known as jsdiff, is a JavaScript implementation for text differencing. It is based on the algorithm proposed in "An O(ND) Difference Algorithm and its Variations". It is used to compare two blocks of text and highlights the differences between them. This comparison can be made character by character, word by word, line by line, and even sentence by sentence. It can also compare CSS tokens, JSON objects, and arrays. Additionally, it provides functionality for creating a unified diff patch, applying a patch, and parsing a patch into structured data.

How do you use diff?

To use the diff package, you first need to install it via npm using the command npm install diff --save. Once it is installed, you can require it in your JavaScript file and start using its methods. Here are a few examples:

const Diff = require('diff');

const one = 'good morning';
const other = 'good afternoon';

const diff = Diff.diffWords(one, other);

diff.forEach((part) => {
  if(part.added) {
    console.log('Added: ' + part.value);
  } else if(part.removed) {
    console.log('Removed: ' + part.value);
  } else {
    console.log('Common: ' + part.value);
  }
});

This code will output the words added, removed, and in common between the two strings.

Here's another example which illustrates how to compare two JSON objects:

const Diff = require('diff');

const oldObj = {name: "John", age: 30, city: "New York"};
const newObj = {name: "John", age: 31, city: "London"};

const diff = Diff.diffJson(oldObj, newObj);

diff.forEach((part) => {
  if(part.added) {
    console.log('Added: ' + JSON.stringify(part.value));
  } else if(part.removed) {
    console.log('Removed: ' + JSON.stringify(part.value));
  } 
});

This code will output the fields added and removed from the old JSON object to the new JSON object.

Where are the diff docs?

The documentation for the diff package can be found in the README file present in its GitHub repository. It details how to install the package, lists all its API methods, explains what each method does, and provides examples of how to use them.