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 🙏

© 2024 – Pkg Stats / Ryan Hefner

diffblazer

v1.0.1

Published

A super fast diffing utility for HTML and Plaintext

Downloads

1,626

Readme

This work is based on htmldiff.net. Originally, I forked htmldiff-javascript (which is a fork of htmldiff-js), but now the code has almost completely deviated. A summary of the changes:

  1. New faster tokenizer based on htmlparser2
  2. Support for "atomic" tags (i.e. tags that should be considered as 1 token) in the tokenizer
  3. Support for diffing nodes based on attributes
  4. No such thing as "word" anymore. Everything is a token
  5. More efficient match finder (no more unnecessary stripping of attributes from tags)
  6. Extensive test suite (thanks to htmldiff.net and htmldiff.js)
  7. Removed support for block expressions
  8. Tags & class names are now fully configurable
  9. ~100x faster (no kidding!)

Installation

npm install diffblazer

Usage

import { diff } from 'diffblazer'

const oldHtml = '<p>hello world</p>'
const newHtml = '<p>hello world!</p>'

diff(oldHtml, newHtml)

// Output: <p>hello world<ins class='diffins'>!</ins></p>

Custom markers

Aside from marking differences using HTML tags, you can also specify your own markers. This can be anything:

import { diff } from 'diffblazer'

const oldText = 'hello world'
const newText = 'hello beautiful world'

diff(oldText, newText, {
	markers: {
		insert: {
			start: '**',
			end: '**',
		},
	},
})

// Output: hello **beautiful** world

Benchmarks

 ✓ benches/html-diff.bench.ts (2) 1212ms
   ✓ benchmark (2) 1210ms
     name                 hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · diffblazer     5,980.63  0.1440  2.2266  0.1672  0.1657  0.3724  0.4760  0.9363  ±1.30%     2991   fastest
   · node-htmldiff    615.75  1.3015  3.3126  1.6240  1.6930  3.0620  3.2030  3.3126  ±2.60%      308


 BENCH  Summary

  diffblazer - benches/html-diff.bench.ts > benchmark
    9.71x faster than node-htmldiff

To run these benchmarks yourself:

npm run bench

Contributing

If you'd like to contribute to this project, you can do so in the following ways:

  1. Report an issue
  2. Implement a feature
  3. Fix a bug

Before you open a PR, make sure to run the tests, like so:

npm run test

License

Copyright © 2024 Abdullah Atta under MIT. Read full text here.