PHPackages                             digitalrevolution/jbdiff - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. digitalrevolution/jbdiff

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

digitalrevolution/jbdiff
========================

A diff library based on Jetbrains' implementation

1.2.2(2y ago)521.9k—7.1%[1 PRs](https://github.com/123inkt/jbdiff/pulls)Apache-2.0PHPPHP &gt;=8.1CI passing

Since Mar 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/123inkt/jbdiff)[ Packagist](https://packagist.org/packages/digitalrevolution/jbdiff)[ RSS](/packages/digitalrevolution-jbdiff/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (10)Versions (11)Used By (0)

[![Minimum PHP Version](https://camo.githubusercontent.com/230588f62e4b3ba29858fcfcf1bbfe253f82c4180088091d6c7d4c6c06d80145/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d383839324246)](https://php.net/)[![PHPStan](https://camo.githubusercontent.com/dc2617839dd90d57b375c6b66fb5c5041573155b77b20980a29ab4089b01ffa5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d656e61626c65642d344243353144)](https://www.phpstan.com/)[![codecov](https://camo.githubusercontent.com/88bdccc9f28b7d3d4ca0ef07b0270cb56548eb45e247a0e7065b924ca610ffc0/68747470733a2f2f636f6465636f762e696f2f67682f313233696e6b742f6a62646966662f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://app.codecov.io/gh/123inkt/jbdiff)[![Build Status](https://github.com/123inkt/jbdiff/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/123inkt/jbdiff/actions)

JBDiff
======

[](#jbdiff)

A multi-line diff calculation library based on Jetbrains' powerful IDE diff implementation.

Installation
------------

[](#installation)

```
composer require digitalrevolution/jbdiff
```

Usage
-----

[](#usage)

`$textBefore`:

```
switch ($strategy) {
    case RateLimiterConfig::FIXED_WINDOW:
        return new FixedWindow($this->redisService->getConnection(), $config);
    case RateLimiterConfig::SLIDING_WINDOW:
        return new SlidingWindow($this->redisService->getConnection(), $config);
    default:
        throw new RuntimeException('Invalid Strategy name.', RuntimeException::UNKNOWN);
}
```

`$textAfter`:

```
return match ($strategy) {
    RateLimiterConfig::FIXED_WINDOW   => new FixedWindow($this->redisService->getConnection(), $config),
    RateLimiterConfig::SLIDING_WINDOW => new SlidingWindow($this->redisService->getConnection(), $config),
    default                           => throw new RuntimeException('Invalid Strategy name.'),
};
```

To create the diff:

```
use DR\JBDiff\ComparisonPolicy;
use DR\JBDiff\JBDiff;

// line block will contain all the information to partition the strings in removed, unchanged and added parts.
$lineBlocks = (new JBDiff())->compare($textBefore, $textAfter, ComparisonPolicy::DEFAULT);

// to iterate over the string parts
$iterator = new LineBlockTextIterator($textBefore, $textAfter, $lineBlocks);
```

`$iterator` formatted to html: [![docs/example-default.png](docs/example-default.png)](docs/example-default.png)

with `ComparisonPolicy::IGNORE_WHITESPACES`[![docs/example-ignore-whitespace.png](docs/example-ignore-whitespace.png)](docs/example-ignore-whitespace.png)

### Comparison policies

[](#comparison-policies)

- `DEFAULT`: the standard diff strategy and will take whitespace differences into account.
- `TRIM_WHITESPACES`: will take leading and trailing whitespaces out of the diff.
- `IGNORE_WHITESPACES`: will take all whitespace differences out of the diff.

Example
-------

[](#example)

To run the example page, start

```
composer run example
```

The page will be available at `http://localhost:8000/`

[![docs/example-example.png](docs/example-example.png)](docs/example-example.png)

About us
--------

[](#about-us)

At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? [We are looking for developers](https://www.werkenbij123inkt.nl/zoek-op-afdeling/it).

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance59

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 57.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Recently: every ~21 days

Total

8

Last Release

1046d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe1034dcdc9935e9b7f7a733490a5095282445a8526e30e9097e0782c78e24c1?d=identicon)[bram123](/maintainers/bram123)

![](https://www.gravatar.com/avatar/d144b8d21d1631a75230f12330a9cb0ef6608581a5e6989c18677ac52295e271?d=identicon)[FrankDekker](/maintainers/FrankDekker)

![](https://www.gravatar.com/avatar/20e2ae81f6cffdb8c1b1a488b7f2f70270a5d1bf2a57aae09950697ac0ef3dad?d=identicon)[123Tim](/maintainers/123Tim)

---

Top Contributors

[![frankdekker](https://avatars.githubusercontent.com/u/2179983?v=4)](https://github.com/frankdekker "frankdekker (15 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (11 commits)")

---

Tags

diffinlinephpunifiedword-boundary

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/digitalrevolution-jbdiff/health.svg)

```
[![Health](https://phpackages.com/badges/digitalrevolution-jbdiff/health.svg)](https://phpackages.com/packages/digitalrevolution-jbdiff)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
