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 🙏

© 2026 – Pkg Stats / Ryan Hefner

htmldiffpatch

v1.0.1

Published

HTML diffing and patching using the same interfaces as jsondiffpatch

Readme

HTMLDiffPatch

npm version npm downloads license build status bundle size

HTML diffing and patching using the same interfaces as jsondiffpatch.

Installation

npm install htmldiffpatch

Usage

Basic Usage

import htmlDiffPatch from 'htmldiffpatch';

const left = '<div>Hello World</div>';
const right = '<div>Hello Universe</div>';

// Create a diff
const delta = htmlDiffPatch.diff(left, right);

// Apply the diff
const patched = htmlDiffPatch.patch(left, delta);
// Result: '<div>Hello Universe</div>'

// Reverse a diff
const reversed = htmlDiffPatch.reverse(delta);
const original = htmlDiffPatch.patch(right, reversed);
// Result: '<div>Hello World</div>'

Named Exports

import { diff, patch, unpatch, reverse, clone } from 'htmldiffpatch';

const left = '<div class="old">Content</div>';
const right = '<div class="new">Content</div>';

const delta = diff(left, right);
const result = patch(left, delta);

Custom Configuration

import { create } from 'htmldiffpatch';

const customDiffPatch = create({
  objectHash: (obj, index) => {
    // Custom hash function for object comparison
    return obj.id || String(index);
  },
  arrays: {
    detectMove: true,
    includeValueOnMove: false
  }
});

const delta = customDiffPatch.diff(leftHtml, rightHtml);

Working with DOM Elements

import { diff, patch } from 'htmldiffpatch';

// Works with DOM elements too
const leftElement = document.getElementById('left');
const rightElement = document.getElementById('right');

const delta = diff(leftElement, rightElement);
const patchedElement = patch(leftElement, delta);

API

diff(left, right, options?)

Creates a diff between two HTML strings or DOM elements.

  • left: Source HTML string or DOM element
  • right: Target HTML string or DOM element
  • options: Optional configuration object

Returns a delta object representing the differences, or undefined if no changes.

patch(left, delta, options?)

Applies a delta to an HTML string or DOM element.

  • left: Source HTML string or DOM element
  • delta: Delta object from diff()
  • options: Optional configuration object

Returns the patched HTML string or DOM element.

unpatch(right, delta)

Reverses a patch operation.

  • right: The result of a patch operation
  • delta: The original delta used for patching

Returns the original HTML before patching.

reverse(delta)

Creates a reversed delta that undoes the original changes.

  • delta: Delta object to reverse

Returns a new delta object.

clone(value)

Deep clones a value.

  • value: Value to clone

Returns a deep copy of the value.

create(options?)

Creates a new HTMLDiffPatch instance with custom options.

  • options: Configuration object

Returns a new HTMLDiffPatch instance.

Options

DiffOptions

{
  objectHash: (obj, index) => string,  // Custom hash function
  arrays: {
    detectMove: boolean,               // Detect array element moves
    includeValueOnMove: boolean        // Include values when moving
  },
  textDiff: {
    minLength: number                  // Minimum length for text diffing
  },
  propertyFilter: (name, context) => boolean,  // Filter properties
  cloneDiffValues: boolean             // Clone values in diff
}

PatchOptions

{
  reverse: boolean  // Apply patch in reverse
}

Features

  • jsondiffpatch compatibility: Same API and interfaces
  • HTML-aware: Understands HTML structure, attributes, and text content
  • DOM support: Works with both strings and DOM elements
  • Move detection: Can detect when elements are moved rather than deleted/added
  • TypeScript: Full TypeScript support with type definitions
  • Extensible: Configurable with custom hash functions and options

Related Projects

License

MIT