Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

variable-diff

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

variable-diff - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.idea/jsLibraryMappings.xml

6

index.js

@@ -54,7 +54,7 @@ 'use strict';

function keyRemoved(key, variable) {
return indent + options.wrap('removed', key + ': ' + printVar(variable)) + options.newLineChar;
return options.wrap('removed', '- ' + key + ': ' + printVar(variable)) + options.newLineChar;
}
function keyAdded(key, variable) {
return indent + options.wrap('added', key + ': ' + printVar(variable)) + options.newLineChar;
return options.wrap('added', '+ ' + key + ': ' + printVar(variable)) + options.newLineChar;
}

@@ -122,3 +122,3 @@

} else if (left !== right) {
text = options.wrap('modified', printVar(left) + ' != ' + printVar(right));
text = options.wrap('modified', printVar(left) + ' => ' + printVar(right));
changed = true;

@@ -125,0 +125,0 @@ }

{
"name": "variable-diff",
"version": "1.0.0",
"version": "1.1.0",
"description": "Visual diff between javascript variables",

@@ -14,3 +14,3 @@ "main": "index.js",

"scripts": {
"test": "./test"
"test": "tap test.js"
},

@@ -17,0 +17,0 @@ "repository": {

# variable-diff
Visual diff between 2 javascript variables
Visual diff between 2 javascript variables. Shows only the difference and ignores keys that are the same. Diff is formatted in an easy to read format.
[![Build Status](https://travis-ci.org/taylorhakes/variable-diff.svg?branch=master)](https://travis-ci.org/taylorhakes/variable-diff)
## Use
```
npm install variable-diff
```
```js
var diff = require('variable-diff');
var result = diff({ a: 1, b: 2, d: 'hello' }, { a: 8, b: 2, c: 4});
console.log(result.text);
```
![output](http://i.imgur.com/3cOu6Wr.png?1)
### Test
```
npm test
```

@@ -16,3 +16,3 @@ var tap = require('tap');

changed: true,
text: 'null != {"a":1}'
text: 'null => {"a":1}'
});

@@ -25,3 +25,3 @@ t.end();

changed: true,
text: 'null != "b"'
text: 'null => "b"'
});

@@ -42,3 +42,3 @@ t.end();

changed: true,
text: 'undefined != 21'
text: 'undefined => 21'
});

@@ -59,3 +59,3 @@ t.end();

changed: true,
text: '"hello" != "hellos"'
text: '"hello" => "hellos"'
});

@@ -68,3 +68,3 @@ t.end();

changed: true,
text: '"fun" != 9'
text: '"fun" => 9'
});

@@ -77,3 +77,3 @@ t.end();

changed: true,
text: '"fun" != function hello() {}'
text: '"fun" => function hello() {}'
});

@@ -86,3 +86,3 @@ t.end();

changed: true,
text: '"fun" != /search/'
text: '"fun" => /search/'
});

@@ -102,3 +102,3 @@ t.end();

changed: true,
text: '1 != "hellos"'
text: '1 => "hellos"'
});

@@ -111,3 +111,3 @@ t.end();

changed: true,
text: '9 != {"test":1}'
text: '9 => {"test":1}'
});

@@ -127,5 +127,5 @@ t.end();

test('function same code different function', function(t) {
t.same(diff(function () { console.log('1'); } , function () { console.log('1'); }), {
t.same(diff(function test() { console.log('1'); } , function test() { console.log('1'); }), {
changed: true,
text: 'function () {} != function () {}'
text: 'function test() {} => function test() {}'
});

@@ -138,3 +138,3 @@ t.end();

changed: true,
text: 'function () {} != 2'
text: 'function () {} => 2'
});

@@ -147,3 +147,3 @@ t.end();

changed: true,
text: '[\n 0: 9 != 8\n 1: 8 != 9\n]'
text: '[\n 0: 9 => 8\n 1: 8 => 9\n]'
});

@@ -156,3 +156,3 @@ t.end();

changed: true,
text: '[\n 3: 4\n 4: 3\n]'
text: '[\n+ 3: 4\n+ 4: 3\n]'
});

@@ -165,3 +165,3 @@ t.end();

changed: true,
text: '[\n 1: 8\n 2: 7\n]'
text: '[\n- 1: 8\n- 2: 7\n]'
});

@@ -182,3 +182,3 @@ t.end();

changed: true,
text: '[1,2] != {"key":1}'
text: '[1,2] => {"key":1}'
});

@@ -191,3 +191,3 @@ t.end();

changed: true,
text: '[2] != null'
text: '[2] => null'
});

@@ -216,3 +216,3 @@ t.end();

changed: true,
text: '{\n test: {\n a: {\n c: 5 != "test"\n }\n }\n}'
text: '{\n test: {\n a: {\n c: 5 => "test"\n }\n }\n}'
});

@@ -225,3 +225,3 @@ t.end();

changed: true,
text: '{\n b: 2\n c: 3\n}'
text: '{\n- b: 2\n- c: 3\n}'
});

@@ -234,3 +234,3 @@ t.end();

changed: true,
text: '{\n b: 9\n c: 2\n}'
text: '{\n+ b: 9\n+ c: 2\n}'
});

@@ -243,3 +243,3 @@ t.end();

changed: true,
text: '{\n test: {\n a: [\n 0: 5 != 9\n 1: 6 != 8\n 2: 7 != 2\n 3: 4\n ]\n }\n}'
text: '{\n test: {\n a: [\n 0: 5 => 9\n 1: 6 => 8\n 2: 7 => 2\n + 3: 4\n ]\n }\n}'
});

@@ -249,16 +249,8 @@ t.end();

test('object with nested array', function(t) {
t.same(diff({ test: { a: [5,6,7]}, and: 'fun'}, { test: { a: [9,8,2,4]}, and: 'fun'}), {
changed: true,
text: '{\n test: {\n a: [\n 0: 5 != 9\n 1: 6 != 8\n 2: 7 != 2\n 3: 4\n ]\n }\n}'
});
t.end();
});
test('complex nested object difference', function(t) {
t.same(diff({ test: { a: [5,6,7]}, b: { c: 1 }, and: 'fun'}, { test: { a: [9,8,2,4]}, b: {d: 2 }, and: [1,2]}), {
changed: true,
text: '{\n and: "fun" != [1,2]\n b: {\n c: 1\n d: 2\n }\n test: {\n a: [\n 0: 5 != 9\n 1: 6 != 8\n 2: 7 != 2\n 3: 4\n ]\n }\n}'
text: '{\n and: "fun" => [1,2]\n b: {\n - c: 1\n + d: 2\n }\n test: {\n a: [\n 0: 5 => 9\n 1: 6 => 8\n 2: 7 => 2\n + 3: 4\n ]\n }\n}'
});
t.end();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc