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

@thi.ng/hdiff

Package Overview
Dependencies
Maintainers
1
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/hdiff

String diffing w/ hiccup output for further processing, e.g. with @thi.ng/hdom, @thi.ng/hiccup. Includes CLI util to generate HTML, with theme support and code folding

1.2.16
latest
Source
npmnpm
Version published
Weekly downloads
179
94.57%
Maintainers
1
Weekly downloads
 
Created
Source

@thi.ng/hdiff

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 210 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

String diffing w/ hiccup output for further processing, e.g. with @thi.ng/hdom, @thi.ng/hiccup. Includes CLI util to generate HTML, with theme support and code folding.

screenshot of example output

Live example

Status

ALPHA - bleeding edge / work-in-progress

Search or submit any issues for this package

Installation

yarn add @thi.ng/hdiff

ESM import:

import * as hdiff from "@thi.ng/hdiff";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/hdiff"></script>

JSDelivr documentation

For Node.js REPL:

const hdiff = await import("@thi.ng/hdiff");

Package sizes (brotli'd, pre-treeshake): ESM: 1.42 KB

CLI installation & usage

Current limitations:

  • output always written to stdout only
  • only single theme available for now (easy to add new ones, PRs welcome!)
npx @thi.ng/hdiff

# any text files
npx hdiff file-a.txt file-b.txt > diff.html

# git revisions for given file (in local repo)
# rev can be any commit-ish ID understood by git (sha1, tag, etc.)
npx hdiff rel-file-path rev1 rev2 > diff.html

# example
npx hdiff packages/webgl/src/shader.ts develop~500 HEAD > diff.html

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

Usage examples

One project in this repo's /examples directory is using this package:

ScreenshotDescriptionLive demoSource
Applying thi.ng/hdiff to generate static HTML diff outputDemoSource

API

Generated API docs

computeDiff()

Signature: computeDiff(a: string, b: string) => any[]

Takes two strings and performs line-based diff, then formats result as tree of HTML elements in @thi.ng/hiccup format.

The generated format only uses the following data attributes:

  • data-diff: diff status for each code line ("+", "-" or " ")
  • data-lnum: formatted line number for each code line
  • data-fold: indicates folded pre-block
  • data-fold-range: line number range string

generateHtml()

Signature: generateHtml(header: any[], body: any[], theme: Theme) => string

Takes two hiccup trees for header and body and an optional theme. Compiles theme into CSS, serializes hiccup trees and returns complete HTML document as string.

compileTheme()

Signature: compileTheme(theme: Theme) => string

Compiles a theme config into a complete CSS stylesheet string (using @thi.ng/hiccup-css).

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-hdiff,
  title = "@thi.ng/hdiff",
  author = "Karsten Schmidt",
  note = "https://thi.ng/hdiff",
  year = 2018
}

License

© 2018 - 2025 Karsten Schmidt // Apache License 2.0

Keywords

cli

FAQs

Package last updated on 07 Aug 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.