Skip to content

Commit 4dce9cb

Browse files
TheSpydersirreal
andcommitted
Add basic NPM boilerplate. Apply API changes from https://github.com/JackuB/diff-match-patch. Swap to ESM. Fixes dmsnell#3.
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
1 parent 70f5f62 commit 4dce9cb

File tree

6 files changed

+46
-90
lines changed

6 files changed

+46
-90
lines changed

javascript/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
npm-debug.log
2+
node_modules

javascript/.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests

javascript/diff_match_patch.js

-61
This file was deleted.

javascript/diff_match_patch_uncompressed.js renamed to javascript/index.mjs

+13-29
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Class containing the diff, match and patch methods.
2727
* @constructor
2828
*/
29-
var diff_match_patch = function() {
29+
export const diff_match_patch = function() {
3030

3131
// Defaults.
3232
// Redefine these in your program to override the defaults.
@@ -62,9 +62,9 @@ var diff_match_patch = function() {
6262
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
6363
* which means: delete 'Hello', add 'Goodbye' and keep ' world.'
6464
*/
65-
var DIFF_DELETE = -1;
66-
var DIFF_INSERT = 1;
67-
var DIFF_EQUAL = 0;
65+
export const DIFF_DELETE = -1;
66+
export const DIFF_INSERT = 1;
67+
export const DIFF_EQUAL = 0;
6868

6969
/**
7070
* Class representing one diff tuple.
@@ -90,12 +90,12 @@ diff_match_patch.Diff.prototype.toString = function() {
9090

9191
/**
9292
* Provide an iterable instance on a Diff object.
93-
*
93+
*
9494
* While it's not intended that the Diff be iterated,
9595
* this instance is useful for destructuring assignment.
96-
*
96+
*
9797
* Example:
98-
*
98+
*
9999
* const diff = new diff_match_patch.Diff(DIFF_EQUAL, 'hello');
100100
* const [op, text] = diff;
101101
*/
@@ -1223,7 +1223,7 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) {
12231223

12241224
/**
12251225
* Rearrange diff boundaries that split Unicode surrogate pairs.
1226-
*
1226+
*
12271227
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
12281228
*/
12291229
diff_match_patch.prototype.diff_cleanupSplitSurrogates = function(diffs) {
@@ -1290,17 +1290,17 @@ diff_match_patch.prototype.digit16 = function(c) {
12901290

12911291
/**
12921292
* Decode URI-encoded string but allow for encoded surrogate halves
1293-
*
1293+
*
12941294
* diff_match_patch needs this relaxation of the requirements because
12951295
* not all libraries and versions produce valid URI strings in toDelta
12961296
* and we don't want to crash this code when the input is valid input
12971297
* but at the same time invalid utf-8
1298-
*
1298+
*
12991299
* @example: decodeURI( 'abcd%3A %F0%9F%85%B0' ) = 'abcd: \ud83c\udd70'
13001300
* @example: decodeURI( 'abcd%3A %ED%A0%BC' ) = 'abcd: \ud83c'
1301-
*
1301+
*
13021302
* @cite: @mathiasbynens utf8.js at https://github.com/mathiasbynens/utf8.js
1303-
*
1303+
*
13041304
* @param {String} text input string encoded by encodeURI() or equivalent
13051305
* @return {String}
13061306
*/
@@ -2408,20 +2408,4 @@ diff_match_patch.patch_obj.prototype.toString = function() {
24082408
text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n';
24092409
}
24102410
return text.join('').replace(/%20/g, ' ');
2411-
};
2412-
2413-
// CLOSURE:begin_strip
2414-
// Lines below here will not be included in the Closure-compatible library.
2415-
2416-
// Export these global variables so that they survive Google's JS compiler.
2417-
// In a browser, 'this' will be 'window'.
2418-
// Users of node.js should 'require' the uncompressed version since Google's
2419-
// JS compiler may break the following exports for non-browser environments.
2420-
/** @suppress {globalThis} */
2421-
this['diff_match_patch'] = diff_match_patch;
2422-
/** @suppress {globalThis} */
2423-
this['DIFF_DELETE'] = DIFF_DELETE;
2424-
/** @suppress {globalThis} */
2425-
this['DIFF_INSERT'] = DIFF_INSERT;
2426-
/** @suppress {globalThis} */
2427-
this['DIFF_EQUAL'] = DIFF_EQUAL;
2411+
};

javascript/package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@dmsnell/diff-match-patch",
3+
"version": "1.0.0",
4+
"license": "Apache-2.0",
5+
"description": "Efficient and human-readable text diffs with helpers",
6+
"keywords": [
7+
"diff",
8+
"diff-match-patch",
9+
"google-diff-match-patch"
10+
],
11+
"type": "module",
12+
"main": "./index.mjs",
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/dmsnell/diff-match-patch"
16+
}
17+
}

0 commit comments

Comments
 (0)