digitalrevolution / jbdiff
A diff library based on Jetbrains' implementation
Installs: 8 901
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 4
Requires
- php: >=8.1
Requires (Dev)
- digitalrevolution/accessorpair-constraint: ^2.1
- digitalrevolution/phpunit-file-coverage-inspection: ^2.0
- phpmd/phpmd: ^2.13
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-12-14 19:24:56 UTC
README
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
composer require digitalrevolution/jbdiff
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);
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
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.