Permalink
Browse files

Add README

  • Loading branch information...
1 parent 7aa0421 commit 10fd8beaf7ad5fc62e8f6f0458807c7bd04b2d97 @andreyvit committed Apr 17, 2012
Showing with 94 additions and 0 deletions.
  1. +94 −0 README.md
  2. BIN doc/screenshot.png
View
@@ -0,0 +1,94 @@
+JSON structural diff
+====================
+
+Does exactly what you think it does:
+
+![Screenshot](https://github.com/andreyvit/json-diff/raw/master/doc/screenshot.png)
+
+
+Installation
+------------
+
+ npm install json-diff
+
+
+Usage
+-----
+
+Simple:
+
+ json-diff a.json b.json
+
+Detailed:
+
+ % json-diff --help
+ Usage: json-diff [-vjC] first.json second.json
+
+ Arguments:
+ first.json Old file
+ second.json New file
+
+ General options:
+ -v, --verbose Output progress info
+ -C, --[no-]color Colored output
+ -j, --raw-json Display raw JSON encoding of the diff
+ -h, --help Display this usage information
+
+
+Features
+--------
+
+* colorized, diff-like output
+* fuzzy matching of modified array elements (when array elements are object hierarchies)
+* reasonable test coverage (far from 100%, though)
+
+
+Tests
+-----
+
+Run:
+
+ `npm test`
+
+Output:
+
+ colorize
+ ✓ should return ' <value>' for a scalar value
+ ✓ should return '-<old value>', '+<new value>' for a scalar diff
+ ✓ should return '-<removed key>: <removed value>' for an object diff with a removed key
+ ✓ should return '+<added key>: <added value>' for an object diff with an added key
+ ✓ should return '+<added key>: <added stringified value>' for an object diff with an added key and a non-scalar value
+ ✓ should return ' <modified key>: <colorized diff>' for an object diff with a modified key
+ ✓ should return '+<inserted item>' for an array diff
+ ✓ should return '-<deleted item>' for an array diff
+
+ diff
+ with simple scalar values
+ ✓ should return undefined for two identical numbers
+ ✓ should return undefined for two identical strings
+ ✓ should return { __old: <old value>, __new: <new value> } object for two different numbers
+ with objects
+ ✓ should return undefined for two objects with identical contents
+ ✓ should return undefined for two object hierarchies with identical contents
+ ✓ should return { <key>__deleted: <old value> } when the second object is missing a key
+ ✓ should return { <key>__added: <new value> } when the first object is missing a key
+ ✓ should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with diffent scalar values for a key
+ ✓ should return { <key>: <diff> } with a recursive diff for two objects with diffent values for a key
+ with arrays of scalars
+ ✓ should return undefined for two arrays with identical contents
+ ✓ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
+ ✓ should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value
+ ✓ should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
+ with arrays of objects
+ ✓ should return undefined for two arrays with identical contents
+ ✓ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
+ ✓ should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value
+ ✓ should return [..., ['~', <diff>], ...] for two arrays when an item has been modified (note: involves a crazy heuristic)
+
+ ✔ 25 tests complete (12ms)
+
+
+License
+-------
+
+© Andrey Tarantsov. Distributed under the MIT license.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 10fd8be

Please sign in to comment.