diffz

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 4 Imported by: 1

README

gopherz

ezpkg.io/diffz

PkgGoDev GitHub License version

Package diffz provides functions for comparing and displaying differences between two strings. It's based on kylelemons/godebug and sergi/go-diff. It provides additional features of ignoring spaces and supporting placeholders.

Installation

go get -u ezpkg.io/diffz@v0.1.2

Examples

// diff by char
left, right := "onetwo thr33four five", "onetwothree fourfive"
diffs := diffz.IgnoreSpace().DiffByChar(left, right)
fmt.Println(diffz.Format(diffs))

// diff by line
left, right := "one\ntwo\nthree\nfour", "one\ntwo\nfour"
diffs := diffz.IgnoreSpace().DiffByLine(left, right)
fmt.Println(diffz.Format(diffs))

// placeholder is useful for comparing tests with uuid or random values
diffs := diffz.Placeholder().AndIgnoreSpace().DiffByLine(left, right)
left := "id: ████\ncode: AF███\nname: Alice\n"
right := "id: 1234\ncode: AF123\nname: Baby\n"
fmt.Println(diffz.Format(diffs))

Similar Packages

This package is based on these packages:

About ezpkg.io

As I work on various Go projects, I often find myself creating utility functions, extending existing packages, or developing packages to solve specific problems. Moving from one project to another, I usually have to copy or rewrite these solutions. So I created this repository to have all these utilities and packages in one place. Hopefully, you'll find them useful as well.

For more information, see the main repository.

Author

Oliver Nguyen  github

Documentation

Overview

Package diffz provides functions for comparing and displaying differences between two strings. It's based on kylelemons/godebug and sergi/go-diff.

Index

Constants

View Source
const (
	DiffDelete = diffmatchpatch.DiffDelete
	DiffInsert = diffmatchpatch.DiffInsert
	DiffEqual  = diffmatchpatch.DiffEqual
)
View Source
const DefaultPlaceholder = '█'

Variables

This section is empty.

Functions

func Format

func Format(diffs Diffs) string

Types

type Diff

type Diff = diffmatchpatch.Diff

type Diffs

type Diffs struct {
	Items []Diff
}

func ByChar

func ByChar(left, right string) Diffs

func ByCharX

func ByCharX(left, right string, opt Option) (out Diffs)

func ByCharZ

func ByCharZ(left, right string) Diffs

func ByLine

func ByLine(left, right string) (out Diffs)

func ByLineX

func ByLineX(left, right string, opt Option) (out Diffs)

func ByLineZ

func ByLineZ(left, right string) (out Diffs)

func (Diffs) IsDiff

func (ds Diffs) IsDiff() bool

func (Diffs) String added in v0.0.8

func (ds Diffs) String() string

type Operation

type Operation = diffmatchpatch.Operation

type Option

type Option struct {
	IgnoreSpace bool
	Placeholder rune
}

func Default

func Default() Option

func IgnoreSpace

func IgnoreSpace() Option

func Placeholder

func Placeholder() Option

func PlaceholderX

func PlaceholderX(placeholder rune) Option

func PlaceholderZ

func PlaceholderZ() Option

func (Option) AndIgnoreSpace

func (opt Option) AndIgnoreSpace() Option

func (Option) AndPlaceholder

func (opt Option) AndPlaceholder() Option

func (Option) AndPlaceholderX

func (opt Option) AndPlaceholderX(placeholder rune) Option

func (Option) DiffByChar

func (opt Option) DiffByChar(left, right string) (out Diffs)

func (Option) DiffByLine

func (opt Option) DiffByLine(left, right string) (out Diffs)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL