GithubHelp home page GithubHelp logo

cwohlman / concordance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from concordancejs/concordance

0.0 0.0 0.0 835 KB

Compare, format, diff and serialize any JavaScript value

License: ISC License

JavaScript 100.00%

concordance's Introduction

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

  • Object wrappers are compared both as objects and unwrapped values. Thus Concordance always treats Object(1) as different from 1.
  • -0 is distinct from 0.
  • NaN equals NaN.
  • The Argument values can be compared to a regular array.
  • Error names and messages are always compared, even if these are not enumerable properties.
  • Function values are compared by identity only. Names are always formatted and serialized.
  • Global objects are considered equal.
  • Map keys and Set items are compared in-order.
  • Object string properties are compared according to the traversal order. Symbol properties are compared by identity.
  • Promise values are compared by identity only.
  • Symbol values are compared by identity only.
  • Recursion stops whenever a circular reference is encountered. If the same cycle is present in the actual and expected values they're considered equal, but they're unequal otherwise.

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:

  • When used as keys, line break characters are escaped
  • Otherwise, multi-line strings are formatted using backticks, and line break characters are replaced by control pictures.

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:

  • Argument values can only be compared to other Argument values.
  • Function values are compared by name.
  • Promise values are compared by their constructor and additional enumerable properties, but not by identity.
  • Symbol values are compared by their string serialization. Registered and well-known symbols will never equal symbols with similar descriptions.

concordance's People

Contributors

bitjson avatar bunysae avatar exogen avatar greenkeeper[bot] avatar ninevra avatar novemberborn avatar papb avatar sindresorhus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.