https://github.com/unitvectory-labs/yamlequal
A lightweight Go library that verifies the semantic equality of YAML files.
https://github.com/unitvectory-labs/yamlequal
Last synced: 3 months ago
JSON representation
A lightweight Go library that verifies the semantic equality of YAML files.
- Host: GitHub
- URL: https://github.com/unitvectory-labs/yamlequal
- Owner: UnitVectorY-Labs
- License: mit
- Created: 2025-02-23T13:42:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-23T13:54:39.000Z (over 1 year ago)
- Last Synced: 2025-02-23T14:34:15.243Z (over 1 year ago)
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/UnitVectorY-Labs/yamlequal/releases/latest) [](https://opensource.org/licenses/MIT) [](https://guide.unitvectorylabs.com/bestpractices/status/#active) [](https://codecov.io/gh/UnitVectorY-Labs/yamlequal) [](https://goreportcard.com/report/github.com/UnitVectorY-Labs/yamlequal)
# yamlequal
A lightweight Go library that verifies the semantic equality of YAML files.
## Features
- Compare two YAML files for semantic equality, regardless of formatting or key order
- Compare two YAML content strings directly
## Usage
```go
import "github.com/UnitVectorY-Labs/yamlequal"
```
### Comparing YAML Files
```go
func main() {
// Compare two YAML files
equal, diff, err := yamlequal.CompareFiles("file1.yaml", "file2.yaml")
if err != nil {
// Handle error
fmt.Println("Error comparing files:", err)
return
}
if equal {
// Files are semantically equivalent
fmt.Println("Same:", diff)
} else {
// Files differ semantically
fmt.Println("Different: ", diff)
}
}
```
### Comparing YAML Content Directly
```go
func main() {
yamlContent1 := []byte(`
foo: bar
value: 42
`)
yamlContent2 := []byte(`
foo: bar
`)
// Compare two YAML content strings directly
equal, diff, err := yamlequal.CompareYAML(yamlContent1, yamlContent2)
if err != nil {
// Handle error
fmt.Println("Error comparing files:", err)
return
}
if equal {
// Files are semantically equivalent
fmt.Println("Same:", diff)
} else {
// Files differ semantically
fmt.Println("Different: ", diff)
}
}
```