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

diff-native

v0.1.0

Published

High-performance text diffing library built with Rust and WebAssembly

Readme

diff-native

High-performance text diffing library built with Rust and WebAssembly. This library is a drop-in replacement for the popular jsdiff library, offering identical API with dramatically improved performance and reduced memory usage.

npm version License: MIT

Features

  • Blazing Fast: 10-20x faster than JavaScript diffing libraries
  • 💾 Memory Efficient: Up to 80% less memory usage
  • 🔄 Drop-in Replacement: Identical API to the original jsdiff library
  • 📝 Text Diffing: Compare strings at character, word, line, and sentence levels
  • 🔍 Patching: Create, parse, and apply patches in unified diff format
  • 🌐 Universal: Works in Node.js, Bun, and modern browsers
  • 📦 Small Footprint: Optimized WASM binary for minimal bundle size
  • 🦀 Rust-Powered: Built with Rust for maximum performance and safety

Installation

# NPM
npm install diff-native

# Yarn
yarn add diff-native

# PNPM
pnpm add diff-native

# Bun
bun add diff-native

Usage

Node.js (CommonJS)

const { diffChars, diffWords, diffLines } = require('diff-native');

// Basic character-level diff
const charChanges = diffChars('old string', 'new string');

// Word-level diff
const wordChanges = diffWords('old string with words', 'new string with words');

// Line-level diff
const lineChanges = diffLines('line one\nline two', 'line one\nmodified line\nline two');

// Each change has properties:
// - value: The text content
// - added: true if this is an addition
// - removed: true if this is a removal
// - count: Number of tokens in the change

Bun or ESM

import { diffChars, diffWords, diffLines } from 'diff-native';

// Use the same API as in the CommonJS example
const changes = diffChars('old string', 'new string');

Browser via CDN

<script type="module">
  import * as diff from 'https://cdn.jsdelivr.net/npm/diff-native/dist/browser/index.js';
  
  const changes = diff.diffChars('old string', 'new string');
  console.log(changes);
</script>

API Overview

Diff Methods

All diff methods follow the same basic pattern:

diff(oldText, newText, options?)
  • diffChars: Character by character diff
  • diffWords: Word level diff
  • diffWordsWithSpace: Word level diff including whitespace
  • diffLines: Line level diff
  • diffTrimmedLines: Line level diff with whitespace trimming
  • diffSentences: Sentence level diff
  • diffCss: CSS specific diff
  • diffJson: JSON diff that handles objects

Options

// Example options
const options = {
  ignoreCase: true,        // Ignore case differences
  ignoreWhitespace: true,  // Ignore whitespace differences
  oneChangePerToken: false // Combine consecutive changes of the same type
};

Patch Methods

// Create a patch
const patch = createPatch('filename.txt', oldText, newText);

// Apply a patch
const patched = applyPatch(oldText, patch);

// Parse a patch
const parsed = parsePatch(patchString);

Line Ending Utilities

// Check line ending style
const isUnixEndings = isUnix(patchString);
const isWindowsEndings = isWin(patchString);

// Convert between line endings
const unixPatch = winToUnix(patchString);
const windowsPatch = unixToWin(patchString);

Performance

diff-native dramatically outperforms other JavaScript diffing libraries:

  • 10-20x faster for text comparisons across all diff operations
  • Up to 80% less memory usage compared to pure JavaScript implementations
  • Consistent performance gains across Node.js, Bun, and browser environments
  • Optimized for all diff operations - character, word, line, sentence, and JSON diffs all benefit

Performance benefits are most noticeable when processing larger documents or working with resource-constrained environments.

Browser Compatibility

diff-native works in all modern browsers that support WebAssembly:

  • Chrome 57+
  • Firefox 53+
  • Safari 11+
  • Edge 16+

Runtime Support

  • Node.js: 14.0.0+
  • Bun: All versions
  • Deno: With npm compatibility mode

Module Formats

This package provides multiple build formats:

  • CommonJS for Node.js (default)
  • ES Modules for bundlers and modern runtimes
  • Browser-ready bundle

Development

Prerequisites

Building

# Install dependencies
bun install

# Build all targets (node, browser, and esm)
bun run build

# Build specific targets
bun run build:wasm:node   # Only build Node.js target
bun run build:wasm:web    # Only build Web target

Testing

# Run all tests
bun test

# Run tests after building
bun run build && bun test

# Run tests in watch mode
bun test --watch

# Run Rust unit tests
bun run test:rust
# or
cargo test --lib

# Run WebAssembly integration tests
wasm-pack test --node

Build Outputs

The build process creates several distribution formats:

  • dist/node/ - CommonJS modules for Node.js
  • dist/browser/ - Browser-compatible modules
  • dist/esm/ - ES modules for modern bundlers

Code Quality

This project uses several tools to maintain code quality:

# Run ESLint to check code
bun run lint

# Fix ESLint issues automatically
bun run lint:fix

# Format code with Prettier
bun run format

# Check formatting without changing files
bun run format:check

# Run both linting and format checking
bun run check

# Fix all linting and formatting issues
bun run fix

Husky and lint-staged are configured to automatically check code quality before each commit.

Issues and Feature Requests

If you encounter any bugs or have feature requests, please file an issue on GitHub.

Pull Requests

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

Make sure to:

  1. Follow the code style guidelines
  2. Add or update tests as necessary
  3. Update documentation for any API changes
  4. Maintain API compatibility with the original jsdiff library

Versioning

This project follows Semantic Versioning. The version numbers follow the pattern: MAJOR.MINOR.PATCH.

License

MIT