Comparing version 1.0.7 to 2.0.0
'use strict' | ||
module.exports = Object.seal({ | ||
color: true, // fake real | ||
color: false, // fake real | ||
flags: null, // real | ||
@@ -6,0 +6,0 @@ forceFake: false, // git-diff |
@@ -33,2 +33,3 @@ 'use strict' | ||
it('color is a boolean', function() { | ||
expected.color = true | ||
actual = normaliseOptions({color: true}) | ||
@@ -39,3 +40,2 @@ imp.expect(actual).to.eql(expected) | ||
it('color is not a boolean', function() { | ||
expected.color = false | ||
actual = normaliseOptions({color: 'false'}) | ||
@@ -42,0 +42,0 @@ imp.expect(actual).to.eql(expected) |
{ | ||
"name": "git-diff", | ||
"version": "1.0.7", | ||
"version": "2.0.0", | ||
"description": "Returns the git diff of two strings", | ||
@@ -69,3 +69,3 @@ "author": "Daniel Lewis BSc (Hons)", | ||
"readfile-go": "^1.0.4", | ||
"sinon": "^4.0.0", | ||
"sinon": "^4.0.1", | ||
"sinon-chai": "^2.14.0" | ||
@@ -72,0 +72,0 @@ }, |
@@ -35,3 +35,3 @@ # git-diff | ||
An example to demonstrate usage: | ||
String diff example: | ||
@@ -42,8 +42,18 @@ ```javascript 1.5 | ||
var newStr = 'paul\nis\nfunny\n' | ||
var actual = gitDiff(oldStr, newStr, {color: false}) | ||
expect(actual).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
var diff = gitDiff(oldStr, newStr) | ||
expect(diff).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
``` | ||
File diff example: | ||
```javascript 1.5 | ||
var gitDiff = require('git-diff') | ||
var readFileGo = require('readfile-go') // or your preferred file reader | ||
var oldStr = readFileGo(__dirname + '/oldStr.txt') | ||
var newStr = readFileGo(__dirname + '/newStr.txt') | ||
var diff = gitDiff(oldStr, newStr) | ||
``` | ||
<br> | ||
@@ -61,3 +71,3 @@ | ||
var options = { | ||
color: true, // Add color to the git diff returned? | ||
color: false, // Add color to the git diff returned? | ||
flags: null, // A space separated string of git diff flags from https://git-scm.com/docs/git-diff#_options | ||
@@ -89,4 +99,4 @@ forceFake: false, // Do not try and get a real git diff, just get me a fake? Faster but may not be 100% accurate | ||
var newStr = 'paul\nis\n funny \n' | ||
var actual = gitDiff(oldStr, newStr, {color: false, flags: '--diff-algorithm=minimal --ignore-all-space'}) | ||
expect(actual).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny \n') | ||
var diff = gitDiff(oldStr, newStr, {flags: '--diff-algorithm=minimal --ignore-all-space'}) | ||
expect(diff).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny \n') | ||
``` | ||
@@ -116,4 +126,4 @@ | ||
var newStr = 'paul\nis\nfunny\n' | ||
var actual = gitDiff(oldStr, newStr, {color: false, forceFake: true}) | ||
expect(actual).to.equal('-fred\n+paul\n is\n funny\n') | ||
var diff = gitDiff(oldStr, newStr, {forceFake: true}) | ||
expect(diff).to.equal('-fred\n+paul\n is\n funny\n') | ||
``` | ||
@@ -137,8 +147,8 @@ | ||
var newStr = 'paul\nis\nfunny\n' | ||
var actual | ||
var diff | ||
actual = gitDiff(oldStr, newStr, {color: false, save: true, wordDiff: true}) | ||
expect(actual).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
actual = gitDiff(oldStr, newStr) | ||
expect(actual).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
diff = gitDiff(oldStr, newStr, {save: true, wordDiff: true}) | ||
expect(diff).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
diff = gitDiff(oldStr, newStr) | ||
expect(diff).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
``` | ||
@@ -194,8 +204,8 @@ | ||
```javascript 1.5 | ||
var gitDiff = require('git-diff/async') | ||
var oldStr = 'fred\nis\nfunny\n' | ||
var newStr = 'paul\nis\nfunny\n' | ||
gitDiff(oldStr, newStr, {color: false}).then(function(actual) { | ||
expect(actual).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
}) | ||
var gitDiff = require('git-diff/async') | ||
var oldStr = 'fred\nis\nfunny\n' | ||
var newStr = 'paul\nis\nfunny\n' | ||
gitDiff(oldStr, newStr).then(function(diff) { | ||
expect(diff).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
}) | ||
``` | ||
@@ -202,0 +212,0 @@ |
@@ -24,8 +24,8 @@ 'use strict' | ||
it('usage', function() { | ||
it('usage - string diff', function() { | ||
var gitDiff = require('../../sync') | ||
var oldStr = 'fred\nis\nfunny\n' | ||
var newStr = 'paul\nis\nfunny\n' | ||
var actual = gitDiff(oldStr, newStr, {color: false}) | ||
imp.expect(actual).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
var diff = gitDiff(oldStr, newStr) | ||
imp.expect(diff).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
@@ -35,2 +35,13 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
it('usage - file diff', function() { | ||
var gitDiff = require('../../sync') | ||
var readFileGo = require('readfile-go') // or your preferred file reader | ||
var oldStr = readFileGo(__dirname + '/oldStr.txt') | ||
var newStr = readFileGo(__dirname + '/newStr.txt') | ||
var diff = gitDiff(oldStr, newStr) | ||
imp.expect(diff).to.equal(imp.data.lineDiffReal) | ||
imp.expect(imp.color.add).to.have.not.been.called | ||
}) | ||
it('flags', function() { | ||
@@ -40,4 +51,4 @@ var gitDiff = require('../../sync') | ||
var newStr = 'paul\nis\n funny \n' | ||
var actual = gitDiff(oldStr, newStr, {color: false, flags: '--diff-algorithm=minimal --ignore-all-space'}) | ||
imp.expect(actual).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny \n') | ||
var diff = gitDiff(oldStr, newStr, {flags: '--diff-algorithm=minimal --ignore-all-space'}) | ||
imp.expect(diff).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny \n') | ||
@@ -51,4 +62,4 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
var newStr = 'paul\nis\nfunny\n' | ||
var actual = gitDiff(oldStr, newStr, {color: false, forceFake: true}) | ||
imp.expect(actual).to.equal('-fred\n+paul\n is\n funny\n') | ||
var diff = gitDiff(oldStr, newStr, {forceFake: true}) | ||
imp.expect(diff).to.equal('-fred\n+paul\n is\n funny\n') | ||
@@ -62,8 +73,8 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
var newStr = 'paul\nis\nfunny\n' | ||
var actual | ||
var diff | ||
actual = gitDiff(oldStr, newStr, {color: false, save: true, wordDiff: true}) | ||
imp.expect(actual).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
actual = gitDiff(oldStr, newStr) | ||
imp.expect(actual).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
diff = gitDiff(oldStr, newStr, {save: true, wordDiff: true}) | ||
imp.expect(diff).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
diff = gitDiff(oldStr, newStr) | ||
imp.expect(diff).to.equal('@@ -1,3 +1,3 @@\n[-fred-]{+paul+}\nis\nfunny\n') | ||
@@ -77,4 +88,5 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
var newStr = 'paul\nis\nfunny\n' | ||
gitDiff(oldStr, newStr, {color: false}).then(function(actual) { | ||
imp.expect(actual).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
gitDiff(oldStr, newStr).then(function(diff) { | ||
imp.expect(diff).to.equal('@@ -1,3 +1,3 @@\n-fred\n+paul\n is\n funny\n') | ||
imp.expect(imp.color.add).to.have.not.been.called | ||
@@ -81,0 +93,0 @@ done() |
@@ -30,3 +30,3 @@ 'use strict' | ||
it('force fake - color', function(done) { | ||
gitDiffAsync(str1, str2, {forceFake: true}).then(function(actual) { | ||
gitDiffAsync(str1, str2, {color: true, forceFake: true}).then(function(actual) { | ||
imp.expect(actual).to.equal(imp.data.lineDiffFake) | ||
@@ -33,0 +33,0 @@ imp.expect(imp.color.add).to.have.been.calledWith(imp.sinon.match.any, 'green') |
@@ -45,3 +45,3 @@ 'use strict' | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, testObj.options) | ||
var actual = gitDiffSync(str1, str2, Object.assign({color: true}, testObj.options)) | ||
imp.expect(actual).to.equal(imp.data.lineDiffFake) | ||
@@ -54,3 +54,3 @@ imp.expect(imp.color.add).to.have.been.calledWith(imp.sinon.match.any, 'green') | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, Object.assign({color: false}, testObj.options)) | ||
var actual = gitDiffSync(str1, str2, testObj.options) | ||
imp.expect(actual).to.equal(imp.data.lineDiffFake) | ||
@@ -62,3 +62,3 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync('my first string', 'my second string', Object.assign({color: false}, testObj.options)) | ||
var actual = gitDiffSync('my first string', 'my second string', testObj.options) | ||
imp.expect(actual).to.equal(imp.data.oneLinerLineDiffFake) | ||
@@ -69,3 +69,3 @@ }) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync('', '', testObj.options) | ||
var actual = gitDiffSync('', '', Object.assign({color: true}, testObj.options)) | ||
imp.expect(actual).to.be.undefined | ||
@@ -79,6 +79,6 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
actual = gitDiffSync('my first\nstring', 'my second\nstring', Object.assign({color: false}, testObj.options)) | ||
actual = gitDiffSync('my first\nstring', 'my second\nstring', testObj.options) | ||
imp.expect(actual).to.equal(imp.data.endingsLinuxLineDiff) | ||
actual = gitDiffSync('my first\r\nstring', 'my second\r\nstring', Object.assign({color: false}, testObj.options)) | ||
actual = gitDiffSync('my first\r\nstring', 'my second\r\nstring', testObj.options) | ||
imp.expect(actual).to.equal(imp.data.endingsWindowsLineDiff) | ||
@@ -92,3 +92,3 @@ }) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, Object.assign({wordDiff: true}, testObj.options)) | ||
var actual = gitDiffSync(str1, str2, Object.assign({color: true, wordDiff: true}, testObj.options)) | ||
imp.expect(actual).to.equal(imp.data.wordDiffFake) | ||
@@ -101,3 +101,3 @@ imp.expect(imp.color.add).to.have.been.calledWith(imp.sinon.match.any, 'green') | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, Object.assign({color: false, wordDiff: true}, testObj.options)) | ||
var actual = gitDiffSync(str1, str2, Object.assign({wordDiff: true}, testObj.options)) | ||
imp.expect(actual).to.equal(imp.data.wordDiffFake) | ||
@@ -109,6 +109,3 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync('my first string', 'my second string', Object.assign({ | ||
color: false, | ||
wordDiff: true | ||
}, testObj.options)) | ||
var actual = gitDiffSync('my first string', 'my second string', Object.assign({wordDiff: true}, testObj.options)) | ||
imp.expect(actual).to.equal(imp.data.oneLinerWordDiffFake) | ||
@@ -119,3 +116,3 @@ }) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync('', '', Object.assign({wordDiff: true}, testObj.options)) | ||
var actual = gitDiffSync('', '', Object.assign({color: true, wordDiff: true}, testObj.options)) | ||
imp.expect(actual).to.be.undefined | ||
@@ -129,12 +126,6 @@ imp.expect(imp.color.add).to.have.not.been.called | ||
actual = gitDiffSync('my first\nstring', 'my second\nstring', Object.assign({ | ||
color: false, | ||
wordDiff: true | ||
}, testObj.options)) | ||
actual = gitDiffSync('my first\nstring', 'my second\nstring', Object.assign({wordDiff: true}, testObj.options)) | ||
imp.expect(actual).to.equal(imp.data.endingsLinuxWordDiff) | ||
actual = gitDiffSync('my first\r\nstring', 'my second\r\nstring', Object.assign({ | ||
color: false, | ||
wordDiff: true | ||
}, testObj.options)) | ||
actual = gitDiffSync('my first\r\nstring', 'my second\r\nstring', Object.assign({wordDiff: true}, testObj.options)) | ||
imp.expect(actual).to.equal(imp.data.endingsWindowsWordDiff) | ||
@@ -141,0 +132,0 @@ }) |
@@ -60,3 +60,3 @@ 'use strict' | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, 'not an object') | ||
var actual = gitDiffSync(str1, str2, {color: true}) | ||
imp.expect(actual).to.include(GREEN) | ||
@@ -68,3 +68,3 @@ imp.expect(actual).to.include(RED) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false}) | ||
var actual = gitDiffSync(str1, str2, 'not an object') | ||
imp.expect(actual).to.equal(imp.data.lineDiffReal) | ||
@@ -77,3 +77,3 @@ imp.expect(actual).to.not.include(GREEN) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync('my first string', 'my second string', {color: false}) | ||
var actual = gitDiffSync('my first string', 'my second string') | ||
imp.expect(actual).to.equal(imp.data.oneLinerLineDiffReal) | ||
@@ -101,3 +101,3 @@ }) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {wordDiff: true}) | ||
var actual = gitDiffSync(str1, str2, {color: true, wordDiff: true}) | ||
imp.expect(actual).to.include(GREEN) | ||
@@ -109,3 +109,3 @@ imp.expect(actual).to.include(RED) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false, wordDiff: true}) | ||
var actual = gitDiffSync(str1, str2, {wordDiff: true}) | ||
imp.expect(actual).to.equal(imp.data.wordDiffReal) | ||
@@ -118,3 +118,3 @@ imp.expect(actual).to.not.include(GREEN) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync('my first string', 'my second string', {color: false, wordDiff: true}) | ||
var actual = gitDiffSync('my first string', 'my second string', {wordDiff: true}) | ||
imp.expect(actual).to.equal(imp.data.oneLinerWordDiffReal) | ||
@@ -142,3 +142,3 @@ }) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false, flags: '--shortstat'}) | ||
var actual = gitDiffSync(str1, str2, {flags: '--shortstat'}) | ||
imp.expect(actual).to.equal(imp.data.shortstatReal) | ||
@@ -151,3 +151,3 @@ imp.expect(imp.loglevel.warn).to.have.not.been.called | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false, flags: 9}) | ||
var actual = gitDiffSync(str1, str2, {flags: 9}) | ||
imp.expect(actual).to.equal(imp.data.lineDiffReal) | ||
@@ -160,3 +160,3 @@ imp.expect(imp.loglevel.warn).to.have.not.been.called | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false, flags: '--oops'}) | ||
var actual = gitDiffSync(str1, str2, {flags: '--oops'}) | ||
imp.expect(actual).to.equal(imp.data.lineDiffReal) | ||
@@ -171,3 +171,3 @@ imp.expect(imp.loglevel.warn).to.have.been.calledWith('Ignoring invalid git diff options: --oops') | ||
DEFAULTS.flags = '--shortstat' | ||
var actual = gitDiffSync(str1, str2, {color: false, flags: '--oops'}) | ||
var actual = gitDiffSync(str1, str2, {flags: '--oops'}) | ||
imp.expect(actual).to.equal(imp.data.shortstatReal) | ||
@@ -183,3 +183,3 @@ imp.expect(DEFAULTS.flags).to.equal('--shortstat') | ||
DEFAULTS.flags = '--oops' | ||
var actual = gitDiffSync(str1, str2, {color: false, flags: '--oops'}) | ||
var actual = gitDiffSync(str1, str2, {flags: '--oops'}) | ||
imp.expect(actual).to.equal(imp.data.lineDiffReal) | ||
@@ -205,3 +205,3 @@ imp.expect(DEFAULTS.flags).to.equal(null) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false}) | ||
var actual = gitDiffSync(str1, str2) | ||
imp.expect(actual).to.startWith('@@') | ||
@@ -212,3 +212,3 @@ }) | ||
if (testObj.stub) stub() | ||
var actual = gitDiffSync(str1, str2, {color: false, noHeaders: true}) | ||
var actual = gitDiffSync(str1, str2, {noHeaders: true}) | ||
imp.expect(actual).to.not.startWith('@@') | ||
@@ -215,0 +215,0 @@ }) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
133711
49
225
0