{"_id":"text-diff","_rev":"4119040","name":"text-diff","description":"Compute a diff between two pieces of text with support for same-line diffs, and optionally display a visual diff as HTML. Module made from the text-diff-match-patch library.","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"liddiard","email":""}],"time":{"modified":"2026-02-13T22:09:12.000Z","created":"2015-07-19T13:07:00.017Z","1.0.1":"2015-07-19T13:27:22.124Z","1.0.0":"2015-07-19T13:07:00.017Z"},"users":{},"author":{"name":"Harrison Liddiard","email":"omniaura5@gmail.com","url":"http://harrisonliddiard.com"},"repository":{"type":"git","url":"git+https://github.com/liddiard/text-diff.git"},"versions":{"1.0.1":{"name":"text-diff","version":"1.0.1","description":"Compute a diff between two pieces of text with support for same-line diffs, and optionally display a visual diff as HTML. Module made from the text-diff-match-patch library.","main":"diff.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/liddiard/text-diff.git"},"keywords":["diff","text","visual","difference"],"author":{"name":"Harrison Liddiard","email":"omniaura5@gmail.com","url":"http://harrisonliddiard.com"},"license":"Apache-2.0","bugs":{"url":"https://github.com/liddiard/text-diff/issues"},"homepage":"https://github.com/liddiard/text-diff#readme","gitHead":"cc9a29c198a1da0056ac768baa9976692fcfccaf","_id":"text-diff@1.0.1","_shasum":"6c105905435e337857375c9d2f6ca63e453ff565","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"liddiard","email":"omniaura5@gmail.com"},"dist":{"shasum":"6c105905435e337857375c9d2f6ca63e453ff565","size":17404,"noattachment":false,"key":"/text-diff/-/text-diff-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/text-diff/download/text-diff-1.0.1.tgz"},"maintainers":[{"name":"liddiard","email":""}],"directories":{},"publish_time":1437312442124,"_hasShrinkwrap":false,"_cnpm_publish_time":1437312442124,"_cnpmcore_publish_time":"2021-12-16T23:36:52.791Z"},"1.0.0":{"name":"text-diff","version":"1.0.0","description":"Compute a diff between two pieces of text with support for same-line diffs, and optionally display a visual diff as HTML. Module made from the text-diff-match-patch library.","main":"diff.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/liddiard/text-diff.git"},"keywords":["diff","text","visual","difference"],"author":{"name":"Harrison Liddiard","email":"omniaura5@gmail.com","url":"http://harrisonliddiard.com"},"license":"Apache-2.0","bugs":{"url":"https://github.com/liddiard/text-diff/issues"},"homepage":"https://github.com/liddiard/text-diff#readme","gitHead":"e883d421b51c97a1cdcbb3d228532d1da846ab31","_id":"text-diff@1.0.0","_shasum":"39a04a20c9fdb8488d76148188ca7e54d93482c8","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"liddiard","email":"omniaura5@gmail.com"},"dist":{"shasum":"39a04a20c9fdb8488d76148188ca7e54d93482c8","size":17401,"noattachment":false,"key":"/text-diff/-/text-diff-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/text-diff/download/text-diff-1.0.0.tgz"},"maintainers":[{"name":"liddiard","email":""}],"directories":{},"publish_time":1437311220017,"_hasShrinkwrap":false,"_cnpm_publish_time":1437311220017,"_cnpmcore_publish_time":"2021-12-16T23:36:53.064Z"}},"readme":"# TextDiff\n## JavaScript diff library with support for visual, HTML-formatted output\n\nThis repository contains the diff functionality of the [google-diff-match-patch library](http://code.google.com/p/google-diff-match-patch/) by Neil Fraser, turned into a node module which is suitable for `require`ing into projects.\n\n## [Demo](http://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html)\n\n## Example usage\n\n```javascript\nvar Diff = require('text-diff');\n\nvar diff = new Diff(); // options may be passed to constructor; see below\nvar textDiff = diff.main('text1', 'text2'); // produces diff array\ndiff.prettyHtml(textDiff); // produces a formatted HTML string\n\n```\n\n### Initialization options\n\nArguments may be passed into the `Diff` constructor in the form of an object:\n\n- `timeout`: Number of seconds to map a diff before giving up (0 for infinity).\n- `editCost`: Cost of an empty edit operation in terms of edit characters.\n\nExample initialization with arguments: `var diff = new Diff({ timeout: 2, editCost: 6 });`\n\n## Documentation\n\nThe API documentation below has been modified from the [original API documentation](https://code.google.com/p/google-diff-match-patch/wiki/API).\n\n### Initialization\n\nThe first step is to create a new diff object (see example above). This object contains various properties which set the behaviour of the algorithms, as well as the following methods/functions:\n\n### main(text1, text2) => diffs\n\nAn array of differences is computed which describe the transformation of text1 into text2. Each difference is an array.  The first element specifies if it is an insertion (1), a deletion (-1) or an equality (0). The second element specifies the affected text.\n\n```javascript\nmain(\"Good dog\", \"Bad dog\") => [(-1, \"Goo\"), (1, \"Ba\"), (0, \"d dog\")]\n```\n\nDespite the large number of optimisations used in this function, diff can take a while to compute. The `timeout` setting is available to set how many seconds any diff's exploration phase may take (see \"Initialization options\" section above). The default value is 1.0. A value of 0 disables the timeout and lets diff run until completion. Should diff time out, the return value will still be a valid difference, though probably non-optimal.\n\n### cleanupSemantic(diffs) => null\n\nA diff of two unrelated texts can be filled with coincidental matches. For example, the diff of \"mouse\" and \"sofas\" is `[(-1, \"m\"), (1, \"s\"), (0, \"o\"), (-1, \"u\"), (1, \"fa\"), (0, \"s\"), (-1, \"e\")]`. While this is the optimum diff, it is difficult for humans to understand. Semantic cleanup rewrites the diff, expanding it into a more intelligible format. The above example would become: `[(-1, \"mouse\"), (1, \"sofas\")]`. If a diff is to be human-readable, it should be passed to cleanupSemantic.\n\n### cleanupEfficiency(diffs) => null\n\nThis function is similar to `cleanupSemantic`, except that instead of optimising a diff to be human-readable, it optimises the diff to be efficient for machine processing. The results of both cleanup types are often the same.\n\nThe efficiency cleanup is based on the observation that a diff made up of large numbers of small diffs edits may take longer to process (in downstream applications) or take more capacity to store or transmit than a smaller number of larger diffs. The `diff.EditCost` property sets what the cost of handling a new edit is in terms of handling extra characters in an existing edit. The default value is 4, which means if expanding the length of a diff by three characters can eliminate one edit, then that optimisation will reduce the total costs.\n\n### levenshtein(diffs) => int\n\nGiven a diff, measure its Levenshtein distance in terms of the number of inserted, deleted or substituted characters. The minimum distance is 0 which means equality, the maximum distance is the length of the longer string.\n\n### prettyHtml(diffs) => html\n\nTakes a diff array and returns a string of pretty HTML. Deletions are wrapped in `<del></del>` tags, and insertions are wrapped in `<ins></ins>` tags. Use CSS to apply styling to these tags.\n\n## Tests\n\nTests have not been ported to this library fork, however tests are [available in the original library](https://github.com/liddiard/google-diff-match-patch/tree/master/javascript). If you would like to port tests over, you will need to do some function call renaming (viz. the `diff_` prefix has been removed from functions in the fork) and remove tests specific to the \"patch\" and \"match\" functionalities of the original library.\n","_attachments":{},"homepage":"https://github.com/liddiard/text-diff#readme","bugs":{"url":"https://github.com/liddiard/text-diff/issues"},"license":"Apache-2.0"}