Giter Site home page Giter Site logo

123inkt / jbdiff Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 234 KB

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

License: Apache License 2.0

PHP 99.71% HTML 0.29%
diff inline unified word-boundary php

jbdiff's Introduction

Minimum PHP Version PHPStan codecov Build Status

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);

$iterator formatted to html: docs/example-default.png

with ComparisonPolicy::IGNORE_WHITESPACES docs/example-ignore-whitespace.png

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/

docs/example-example.png

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.

jbdiff's People

Contributors

frankdekker avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jbdiff's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

composer
composer.json
  • php >=8.1
  • digitalrevolution/accessorpair-constraint ^2.1.18
  • digitalrevolution/phpunit-file-coverage-inspection ^2.1
  • squizlabs/php_codesniffer ^3.8
  • phpmd/phpmd ^2.15
  • phpunit/phpunit ^10.5
  • phpstan/phpstan ^1.10
  • phpstan/phpstan-phpunit ^1.3
  • phpstan/phpstan-strict-rules ^1.5
  • phpstan/extension-installer ^1.3
github-actions
.github/workflows/test.yml
  • actions/checkout v4
  • shivammathur/setup-php v2
  • actions/checkout v4
  • shivammathur/setup-php v2
  • codecov/codecov-action v4
  • actions/checkout v4
  • shivammathur/setup-php v2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.