jsondiffprinter

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 8 Imported by: 7

README

jsondiffprinter

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparer

type Comparer func(before, after any) ([]byte, error)

A Comparer compares two JSON documents and returns a JSON patch that transforms the first document into the second document.

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter formats the diff if the given JSON patch is applied to the given JSON document.

func NewJSONFormatter

func NewJSONFormatter(w io.Writer, options ...Option) Formatter

NewJSONFormatter creates a new JSON formatter.

func NewTerraformFormatter

func NewTerraformFormatter(w io.Writer, options ...Option) Formatter

NewTerraformFormatter creates a new Terraform formatter.

func (Formatter) Format

func (f Formatter) Format(before any, jsonpatch any) error

Format formats the JSON patch.

type Option

type Option func(*Formatter)

Option is a function that sets an option on the formatter.

func WithColor

func WithColor(enabled bool) Option

WithColor provides an option for the formatter to enable or disable the color full output.

func WithCommas

func WithCommas(commas bool) Option

WithCommas provides an option for the formatter to enable or disable the commas at the end of the JSON items.

func WithHideUnchanged

func WithHideUnchanged(hideUnchanged bool) Option

WithHideUnchanged provides an option for the formatter to enable or disable the hiding of unchanged items. If enabled, unchanged items will not be printed. But instead a summary will be printed mentioning the number of unchanged items. If disabled, all items will be printed.

func WithIndentation

func WithIndentation(indentation string) Option

WithIndentation provides an option for the formatter to set the indentation string to use when formatting the output.

func WithIndentedDiffMarkers

func WithIndentedDiffMarkers(indentedDiffMarkers bool) Option

WithIndentedDiffMarkers provides an option for the formatter to enable or disable the indentation of the diff markers. If enabled, the diff markers will be indented to match the indentation of the JSON. If disabled, the diff markers will be aligned to the left.

func WithJSONinJSONCompare

func WithJSONinJSONCompare(jsonInJSONComparer Comparer) Option

WithJSONinJSONCompare provides an option for the formatter to set the comparer to use when comparing JSON in JSON. If not set, JSON in JSON diffing is disabled.

func WithPatchSeriesPostProcess added in v0.0.6

func WithPatchSeriesPostProcess(patchSeriesPostProcess PatchSeriesPostProcessor) Option

WithPatchSeriesPostProcess provides an option for the formatter to set the post processor to use when processing the patch series.

type PatchSeriesPostProcessor added in v0.0.6

type PatchSeriesPostProcessor func(diff jsonpatch.Patch) jsonpatch.Patch

A PatchSeriesPostProcessor processes the JSON patch series before the diff is printed. It can be used to modify the diff before it is printed.

Directories

Path Synopsis
cmd module
examples module
internal

Jump to

Keyboard shortcuts

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