https://github.com/123inkt/jbdiff
A multi-line diff calculation library based on Jetbrains' powerful IDE diff implementation.
https://github.com/123inkt/jbdiff
diff inline php unified word-boundary
Last synced: 7 months ago
JSON representation
A multi-line diff calculation library based on Jetbrains' powerful IDE diff implementation.
- Host: GitHub
- URL: https://github.com/123inkt/jbdiff
- Owner: 123inkt
- License: apache-2.0
- Created: 2023-03-28T16:07:50.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-14T19:07:23.000Z (over 1 year ago)
- Last Synced: 2024-11-28T03:46:59.630Z (over 1 year ago)
- Topics: diff, inline, php, unified, word-boundary
- Language: PHP
- Homepage:
- Size: 230 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://php.net/)
[](https://www.phpstan.com/)
[](https://app.codecov.io/gh/123inkt/jbdiff)
[](https://github.com/123inkt/jbdiff/actions)
# JBDiff
A multi-line diff calculation library based on Jetbrains' powerful IDE diff implementation.
https://github.com/JetBrains/intellij-community/tree/master/platform/util/diff/src/com/intellij/diff
## Installation
```bash
composer require digitalrevolution/jbdiff
```
## Usage
`$textBefore`:
```php
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`:
```php
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:
```php
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:

with `ComparisonPolicy::IGNORE_WHITESPACES`

### 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
To run the example page, start
```shell
composer run example
```
The page will be available at `http://localhost:8000/`

## 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).