Module

Data.Text.Diff

Package
purescript-diff-compare
Repository
shamansir/purescript-diff-compare

A module for comparing and displaying differences between text and other data structures. Provides various comparison strategies and formatting options for visualizing diffs.

#Diffable Source

class (Eq a) <= Diffable a  where

A type class for values that can be converted to a string representation suitable for displaying in diff output.

Members

Instances

#DiffSide Source

data DiffSide a

Represents the state of a single item in a comparison, indicating whether it's new, changed, equal, or absent in the compared data.

Constructors

Instances

#DiffLine Source

data DiffLine a

Represents a line-by-line comparison result, showing the relationship between corresponding lines from two sources.

Constructors

Instances

#Limit Source

data Limit

Specifies a limit on the number of lines to display in comparison output.

Constructors

#Comparator Source

data Comparator

Defines different comparison and formatting strategies

Constructors

#Whitespace Source

data Whitespace

Renders whitespace in output with special highlighting.

Constructors

#ComparisonResult Source

data ComparisonResult

Represents the result of a comparison operation, indicating whether the compared items are equal or mismatched, along with the diff output if they are indeed not equal.

Constructors

Instances

#lineByLineComparison Source

lineByLineComparison :: Limit -> String -> String -> String

Performs a line-by-line comparison of two strings, displaying all lines with prefixes indicating their status (equal, added, removed, or changed).

Example:

lineByLineComparison (Limit 10) "hello\nworld" "hello\nthere"

Renders:

.. hello
>> world
<< there

#onlyDiffsComparison Source

onlyDiffsComparison :: Limit -> String -> String -> String

Compares two strings line-by-line but displays only the lines that differ, showing them in two separate sections divided by a separator line.

Example:

onlyDiffsComparison (Limit 10) "hello\nworld" "hello\nthere"

Renders:

>> world
---------------------------------------------------------------
<< there

#twoStacksComparison Source

twoStacksComparison :: Limit -> String -> String -> String

Compares two strings and displays them as two parallel stacks, showing all lines (equal, added, removed, or changed) in both sections divided by a separator line.

Example:

twoStacksComparison (Limit 10) "hello\nworld" "hello\nthere"

Renders:

.. hello
>> world
---------------------------------------------------------------
.. hello
<< there

#lineByLineComparisonWP Source

lineByLineComparisonWP :: Limit -> String -> String -> String

Same as lineByLineComparison, but with whitespace characters highlighted.

#onlyDiffsComparisonWP Source

onlyDiffsComparisonWP :: Limit -> String -> String -> String

Same as onlyDiffsComparison, but with whitespace characters highlighted.

#twoStacksComparisonWP Source

twoStacksComparisonWP :: Limit -> String -> String -> String

Same as twoStacksComparison, but with whitespace characters highlighted.

#compareMany Source

compareMany :: forall f a. Eq a => Align f => f a -> f a -> f (DiffLine a)

Compares two alignable structures element-by-element, producing a structure of DiffLine results that indicate the relationship between corresponding elements.

Example:

compareMany [1, 2, 3] [1, 2, 4]
-- Returns array showing which elements are equal and which differ

#compareByLines Source

compareByLines :: String -> String -> Array (DiffLine String)

Splits two strings by newlines and compares them line-by-line, returning an array of DiffLine results.

Example:

compareByLines "hello\nworld" "hello\nthere"
-- Returns [BothEqual "hello", Different "world" "there"]

#compareBy Source

compareBy :: forall t. Diffable t => Comparator -> (t -> t -> ComparisonResult)

Compares two Diffable values using the specified Comparator, returning a ComparisonResult that indicates whether they are equal or not, along with the appropriate diff output if they differ.

#compareByWP Source

compareByWP :: forall t. Diffable t => Comparator -> (t -> t -> ComparisonResult)

Compares two Diffable values using the specified Comparator, returning a ComparisonResult that indicates whether they are equal or not, along with the appropriate diff output, including whitespace characters, if they differ.

#compareBy_ Source

compareBy_ :: forall t. Diffable t => Whitespace -> Comparator -> (t -> t -> ComparisonResult)

Compares two Diffable values using the specified Comparator and Whitespace configuration,, returning a ComparisonResult that indicates whether they are equal or not, along with the appropriate diff output, including whitespace characters, if they differ.