concordancejs / concordance

Compare, format, diff and serialize any JavaScript value
ISC License
207 stars 15 forks source link

concordance

Compare, format, diff and serialize any JavaScript value. Built for Node.js 10 and above.

Behavior

Concordance recursively describes JavaScript values, whether they're booleans or complex object structures. It recurses through all enumerable properties, list items (e.g. arrays) and iterator entries.

The same algorithm is used when comparing, formatting or diffing values. This means Concordance's behavior is consistent, no matter how you use it.

Comparison details

Formatting details

Concordance strives to format every aspect of a value that is used for comparisons. Formatting is optimized for human legibility.

Strings enjoy special formatting:

Similarly, line breaks in symbol descriptions are escaped.

Diffing details

Concordance tries to minimize diff lines. This is difficult with object values, which may have similar properties but a different constructor. Multi-line strings are compared line-by-line.

Serialization details

Concordance can serialize any value for later use. Deserialized values can be compared to each other or to regular JavaScript values. The deserialized value should be passed as the actual value to the comparison and diffing methods. Certain value comparisons behave differently when the actual value is deserialized: