1.1.2 • Published 11 months ago

@armantang/html-diff v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Html Diff

Compare HTML and generate the differences in either a unified view or a side-by-side comparison. See online demo...

home

Install

pnpm add @armantang/html-diff

Usage

import '@armantang/html-diff/dist/index.css'
import HtmlDiff from '@armantang/html-diff'

const oldHtml = `<div>hello</div>`
const newHtml = `<div>hello world</div>`

const diff = new HtmlDiff(oldHtml, newHtml)
const unifiedContent = diff.getUnifiedContent()
const sideBySideContents = diff.getSideBySideContents()

Options

const diff = new HtmlDiff(oldHtml, newHtml, {
  // options
})

interface HtmlDiffOptions {
  /**
   * Determine the minimum threshold for calculating common sub-tokens.
   * You may adjust it to a value larger than 2, but not lower, due to the potential inclusion of HTML tags in the count.
   * @defaultValue 2
   */
  minMatchedSize?: number
  /**
   * When greedyMatch is enabled, if the length of the sub-tokens exceeds greedyBoundary,
   * we will use the matched sub-tokens that are sufficiently good, even if they are not optimal, to enhance performance.
   * @defaultValue true
   */
  greedyMatch?: boolean
  /**
   * @defaultValue 1000
   */
  greedyBoundary?: number
  /**
   * The classNames for wrapper DOM.
   * Use this to configure your own styles without importing the built-in CSS file
   */
  classNames?: Partial<{
    createText?: string
    deleteText?: string
    createInline?: string
    deleteInline?: string
    createBlock?: string
    deleteBlock?: string
  }>
}

Synchronized scrolling

In the sideBySideContents, some elements have the data-seq attribute. We can use this to implement synchronized scrolling. Click to see the demo.

1.1.1

11 months ago

1.0.2

11 months ago

1.1.0

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

1.1.2

11 months ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago