Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Language: JavaScript

Neil Fraser edited this pageFeb 10, 2018 ·1 revision

Each language port of Diff Match Patch uses thesame API. These are the language-specific notes regardingJavaScript.

javascript/diff_match_patch_uncompressed.js is the human-readable version. This should be used by developers and Node.js.

javascript/diff_match_patch.js has been compressed usingGoogle's Closure Compiler on 'simple' mode. This reduces the size to 25% of the uncompressed version.

The JavaScript version has no dependencies. It works in Netscape 4, Internet Explorer 5.5, and all browsers released since the year 2000 (the limiting factor is the use of theencodeURI function).

Hello World

Here's a minimal example of a diff in #"<html> <body> <script src="diff_match_patch.js"></script> <script> var dmp = new diff_match_patch(); var diff = dmp.diff_main('Hello World.', 'Goodbye World.'); // Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")] dmp.diff_cleanupSemantic(diff); // Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")] alert(diff); </script> </body></html>">

<html><body><scriptsrc="diff_match_patch.js"></script><script>vardmp=newdiff_match_patch();vardiff=dmp.diff_main('Hello World.','Goodbye World.');// Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")]dmp.diff_cleanupSemantic(diff);// Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")]alert(diff);</script></body></html>

Save the above as an HTML file in thejavascript directory, then open the file in any web browser.

Tests

Unit tests can be performed by pointing a web browser atjavascript/tests/diff_match_patch_test.html. Over a hundred tests should run, with zero failures.

Speed test for diff can be performed by pointing a web browser atjavascript/tests/speedtest.html and pressing "Compute Diff".

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp