{"name":"git-diff","version":"1.0.2","description":"Returns the git diff of two strings","author":{"name":"Daniel Lewis BSc","url":"Hons"},"license":"ISC","main":"index.js","scripts":{"test":"istanbul cover -x \"**/*.spec.js\" ./node_modules/mocha/bin/_mocha","enforcer":"istanbul check-coverage --statement 100 --branch 100 --function 100 --line 100","build":"npm-run-all test enforcer","prepush":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/danday74/git-diff.git"},"bugs":{"url":"https://github.com/danday74/git-diff/issues"},"homepage":"https://github.com/danday74/git-diff#readme","keywords":["diff","git diff","string diff"],"dependencies":{"diff":"^3.3.0"},"devDependencies":{"chai":"^4.1.1","coveralls":"2.11.16","eslint":"^4.5.0","husky":"^0.14.3","istanbul":"^0.4.5","mocha":"^3.5.0","npm-run-all":"^4.0.2","sinon":"^3.2.1","sinon-chai":"^2.13.0"},"engines":{"node":">= 4"},"gitHead":"ebe84c99b5b9d0b2daf36e3ad070a133369b402d","_id":"git-diff@1.0.2","_shasum":"9ac7ff944cafaa3d9774d6698d666bd0a1c11dbe","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.0","_npmUser":{"name":"daniel-lewis-bsc-hons","email":"dan.lewis.web@gmail.com"},"dist":{"shasum":"9ac7ff944cafaa3d9774d6698d666bd0a1c11dbe","tarball":"http://registry-npm.ywwl.com/git-diff/download/git-diff-1.0.2.tgz","integrity":"sha512-6F7TCdh6uTxZbVO3mJmeKlAhCQq/eEX/JyK4frG9iI1lVdNsn5DIdZdd+NLQ6lNZnWoAaK45mmRig/CSVlv48g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC5NhqqqhDoXKFpC2TAUvIozjLKWClvYGd//FxY8HFakwIgGAsjigFcHYMqQWmCDfn94TurhZ//q28OzfXawAX7g6Y="}],"size":21230,"noattachment":false,"key":"/git-diff/-/git-diff-1.0.2.tgz"},"maintainers":[{"name":"daniel-lewis-bsc-hons","email":"dan.lewis.web@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/git-diff-1.0.2.tgz_1503543031734_0.735472971573472"},"directories":{},"readme":"# git-diff\n\n<br>[![Linux Build](https://img.shields.io/travis/danday74/git-diff/master.svg?label=linux)](https://travis-ci.org/danday74/git-diff)\n[![Windows Build](https://img.shields.io/appveyor/ci/danday74/git-diff/master.svg?label=windows)](https://ci.appveyor.com/project/danday74/git-diff)\n[![Coverage Status](https://coveralls.io/repos/github/danday74/git-diff/badge.svg)](https://coveralls.io/github/danday74/git-diff)\n<br>[![npm](https://img.shields.io/npm/v/git-diff.svg)](https://www.npmjs.com/package/git-diff)\n[![Dependencies Status](https://david-dm.org/danday74/git-diff/status.svg)](https://david-dm.org/danday74/git-diff)\n[![npm](https://img.shields.io/npm/dm/git-diff.svg)](https://www.npmjs.com/package/git-diff)\n[![node](https://img.shields.io/node/v/git-diff.svg)](https://www.npmjs.com/package/git-diff)\n\n**Returns the git diff of two strings**\n\n\n\n<br>\n\n## Introduction\n\ngit-diff will use ```git``` (if installed) and ```printf``` (if available) to get the real git diff of two strings, viz the actual diff output produced by git itself.\n\nAs a fallback, if either command is unavailable, git-diff will instead use the [diff](https://www.npmjs.com/package/diff) module to produce a very good fake git diff.\n\nIf desired, you may then console.log the returned git diff. An example of **actual output**:\n\n![Line diff v Word diff](diffs.png \"Line diff v Word diff\")\n\n\n\n<br>\n\n## Usage\n\n`npm install --save git-diff`\n\ngit-diff takes 3 arguments, the **old string** to diff, the **new string** to diff and optionally an [options object](#options-object)\n\ngit-diff returns the git difference or `undefined` where there is no difference.\n\nString diff example usage:\n\n```javascript 1.5\nvar gitDiff = require('git-diff')\nvar oldStr = 'fred\\nis\\nfunny\\n'\nvar newStr = 'paul\\nis\\nfunny\\n'\nvar diff = gitDiff(oldStr, newStr)\n\nvar assert = require('assert')\nassert.equal(diff, '@@ -1,3 +1,3 @@\\n-fred\\n+paul\\n is\\n funny\\n')\n```\n\nFile diff example usage:\n\n```javascript 1.5\nvar gitDiff = require('git-diff')\nvar readFileGo = require('readfile-go') // or your preferred file reader\nvar oldStr = readFileGo(__dirname + '/oldStr.txt')\nvar newStr = readFileGo(__dirname + '/newStr.txt')\nvar diff = gitDiff(oldStr, newStr)\n```\n\n\n\n<br>\n\n## Options object\n\nAvailable options are:\n\ncolor | [flags](#flags-string--null-) | [forceFake](#forcefake-boolean-) | noHeaders | [save](#save-boolean-) | wordDiff\n\nDefault options are:\n\n```javascript 1.5\nvar options = {\n  color: false,      // Add color to the git diff returned?\n  flags: null,       // A space separated string of git diff flags from https://git-scm.com/docs/git-diff#_options\n  forceFake: false,  // Do not try and get a real git diff, just get me a fake? Faster but may not be 100% accurate\n  noHeaders: false,  // Remove the ugly @@ -1,3 +1,3 @@ header?\n  save: false,       // Remember the options for next time?\n  wordDiff: false    // Get a word diff instead of a line diff?\n}\n```\n\nFurther assistance is given below for options that are not self explanatory.\n\n\n\n<br>\n\n#### **flags** (string | null) [![top](top.png)](#options-object)\n\nThe flags option allows you to use any [git diff flags](https://git-scm.com/docs/git-diff#_options)\n\nThis only applies to real git diffs and will not effect the output if it is fake.\n\nAn example to illustrate:\n\n```javascript 1.5\nvar gitDiff = require('git-diff')\nvar oldStr = 'fred\\n   is   \\nfunny\\n'\nvar newStr = 'paul\\nis\\n   funny   \\n'\nvar diff = gitDiff(oldStr, newStr, {flags: '--diff-algorithm=minimal --ignore-all-space'})\n\nvar assert = require('assert')\nassert.equal(diff, '@@ -1,3 +1,3 @@\\n-fred\\n+paul\\n is\\n    funny   \\n')\n```\n\nHere, the use of ```--ignore-all-space``` prevents a difference being reported on the 2nd and 3rd lines.\n\n\n\n<br>\n\n#### **forceFake** (boolean) [![top](top.png)](#options-object)\n\ngit-diff will initially attempt to use ```git``` and ```printf``` to get the real git diff.\n\nIf it cannot, it instead returns a very good fake git diff.\n\nA fake git diff is faster to produce but may not be 100% representative of a real git diff.\n\nThe [flags](#flags-string--null-) option is ignored when faking and fake diffs never have a header.\n\nHowever, if a fake is good enough and speed is of the essence then you may want to force a fake git diff.\n\nThe forceFake option allows you to do exactly that:\n\n```javascript 1.5\nvar gitDiff = require('git-diff')\nvar oldStr = 'fred\\nis\\nfunny\\n'\nvar newStr = 'paul\\nis\\nfunny\\n'\nvar diff = gitDiff(oldStr, newStr, {forceFake: true})\n\nvar assert = require('assert')\nassert.equal(diff, '-fred\\n+paul\\n is\\n funny\\n')\n```\n\n\n\n<br>\n\n#### **save** (boolean) [![top](top.png)](#options-object)\n\nIts annoying to keep passing the same options every time.\n\ngit-diff, if instructed to do so, will remember previously used options for you.\n\nWhen the `{save: true}` option is used in a call to git-diff subsequent calls remember the options.\n\n```javascript 1.5\nvar gitDiff = require('git-diff')\nvar oldStr = 'fred\\nis\\nfunny\\n'\nvar newStr = 'paul\\nis\\nfunny\\n'\nvar diff1 = gitDiff(oldStr, newStr, {save: true, wordDiff: true})\nvar diff2 = gitDiff(oldStr, newStr)\n\nvar assert = require('assert')\nassert.equal(diff1, '@@ -1,3 +1,3 @@\\n[-fred-]{+paul+}\\nis\\nfunny\\n')\nassert.equal(diff2, '@@ -1,3 +1,3 @@\\n[-fred-]{+paul+}\\nis\\nfunny\\n')\n```\n\nHere, the second call remembers that the wordDiff option is on. `{wordDiff: true}` is now the default.\n\n\n\n<br>\n\n## Async execution\n\ngit-diff offers a promise based async solution:\n\n```javascript 1.5\nvar gitDiff = require('git-diff/async')\nvar oldStr = 'fred\\nis\\nfunny\\n'\nvar newStr = 'paul\\nis\\nfunny\\n'\ngitDiff(oldStr, newStr).then(function(diff) {\n  var assert = require('assert')\n  assert.equal(diff, '@@ -1,3 +1,3 @@\\n-fred\\n+paul\\n is\\n funny\\n')\n})\n```\n\n\n\n<br>\n\n## FAQs\n\n> **How good is the fake git diff?**<br>\n> The diff module used for the fake diff does not use the same difference algorithm as git.\n> As such, a line diff is likely to be identical to a git line diff whereas a word diff will have some variance.\n\n> **How can I tell whether the returned git diff is real or fake?**<br>\n> If the ```@@ -1,3 +1,3 @@``` header is present then the returned git diff is real.<br>\n> If the header is absent then either the [noHeaders](#options-object) option is on or the returned git diff is fake.\n\n> **Will my environment produce a real or fake git diff?**<br>\n> Linux and mac have the coveted ```printf``` command available. On Windows [git bash](https://git-for-windows.github.io) makes ```printf``` accessible.<br>\n> Assuming that git is installed, any of these environments will produce a real git diff.\n\n\n\n<br>\n\n## Author says\n\nWhat's the **difference** between how God treats the righteous and the wicked?\n\n> And God saw that the light was good. And God separated the light from the darkness. [Genesis 1:4 ESV](https://www.biblegateway.com/passage/?search=Genesis+1%3A4&version=ESV)\n\nAnd He will do it again:\n\n> Let both grow together until the harvest, and at harvest time I will tell the reapers, “Gather the weeds first and bind them in bundles to be burned, but gather the wheat into my barn.” [Matthew 13:30 ESV](https://www.biblegateway.com/passage/?search=matthew+13%3A30&version=ESV)\n\nMuch love :D\n\n\n\n<br><br><br><br><br>\n","publish_time":1503543033497,"_cnpm_publish_time":1503543033497,"dist-tags":{"latest":"2.0.7"}}