cdk-common 2.0.751 → 2.0.753

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.jsii CHANGED
@@ -3667,7 +3667,7 @@
3667
3667
  "stability": "experimental"
3668
3668
  },
3669
3669
  "homepage": "https://github.com/neilkuan/cdk-common.git",
3670
- "jsiiVersion": "5.3.15 (build 463ed1e)",
3670
+ "jsiiVersion": "5.3.18 (build 4f1b2de)",
3671
3671
  "keywords": [
3672
3672
  "aws",
3673
3673
  "aws-cdk",
@@ -10848,6 +10848,6 @@
10848
10848
  "symbolId": "src/main:LambdaArmFunctionProps"
10849
10849
  }
10850
10850
  },
10851
- "version": "2.0.751",
10852
- "fingerprint": "yLWNFiesdxTpK47ZVgc3im6cgYC2LtCSL3jEDCwajEE="
10851
+ "version": "2.0.753",
10852
+ "fingerprint": "SuMgskIHOGR+b4bqs9l+OKNou4q9jpxO+ThcJ4bLJOA="
10853
10853
  }
package/lib/main.js CHANGED
@@ -41,5 +41,5 @@ class LambdaArmFunction extends constructs_1.Construct {
41
41
  }
42
42
  exports.LambdaArmFunction = LambdaArmFunction;
43
43
  _a = JSII_RTTI_SYMBOL_1;
44
- LambdaArmFunction[_a] = { fqn: "cdk-common.LambdaArmFunction", version: "2.0.751" };
44
+ LambdaArmFunction[_a] = { fqn: "cdk-common.LambdaArmFunction", version: "2.0.753" };
45
45
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9tYWluLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsbUNBQW1DO0FBQ25DLGlEQUFpRDtBQUNqRCwyQ0FBdUM7QUFLdkMsTUFBYSxpQkFBa0IsU0FBUSxzQkFBUztJQUU5QyxZQUFZLEtBQWdCLEVBQUUsRUFBVSxFQUFFLEtBQTRCO1FB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LmF3cy5hbWF6b24uY29tL2xhbWJkYS9sYXRlc3QvZGcvZm91bmRhdGlvbi1hcmNoLmh0bWw/aWNtcGlkPWRvY3NfbGFtYmRhX3Jzc2ApO1xuICAgIH1cblxuICAgIHRoaXMubGFtYmRhRnVuY3Rpb24gPSBuZXcgbGFtYmRhLkZ1bmN0aW9uKHRoaXMsICdMYW1iZGFGdW5jdGlvbicsIHsgYXJjaGl0ZWN0dXJlOiBsYW1iZGEuQXJjaGl0ZWN0dXJlLkFSTV82NCwgLi4ucHJvcHMgfSk7XG4gIH1cbn0iXX0=
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [v1.1.3](https://github.com/ljharb/define-data-property/compare/v1.1.2...v1.1.3) - 2024-02-12
9
+
10
+ ### Commits
11
+
12
+ - [types] hand-write d.ts instead of emitting it [`0cbc988`](https://github.com/ljharb/define-data-property/commit/0cbc988203c105f2d97948327c7167ebd33bd318)
13
+ - [meta] simplify `exports` [`690781e`](https://github.com/ljharb/define-data-property/commit/690781eed28bbf2d6766237efda0ba6dd591609e)
14
+ - [Dev Deps] update `hasown`; clean up DT packages [`6cdfd1c`](https://github.com/ljharb/define-data-property/commit/6cdfd1cb2d91d791bfd18cda5d5cab232fd5d8fc)
15
+ - [actions] cleanup [`3142bc6`](https://github.com/ljharb/define-data-property/commit/3142bc6a4bc406a51f5b04f31e98562a27f35ffd)
16
+ - [meta] add `funding` [`8474423`](https://github.com/ljharb/define-data-property/commit/847442391a79779af3e0f1bf0b5bb923552b7804)
17
+ - [Deps] update `get-intrinsic` [`3e9be00`](https://github.com/ljharb/define-data-property/commit/3e9be00e07784ba34e7c77d8bc0fdbc832ad61de)
18
+
8
19
  ## [v1.1.2](https://github.com/ljharb/define-data-property/compare/v1.1.1...v1.1.2) - 2024-02-05
9
20
 
10
21
  ### Commits
@@ -1,3 +1,12 @@
1
- declare const _exports: (obj: Record<PropertyKey, unknown>, property: PropertyKey, value: unknown, nonEnumerable?: boolean | null, nonWritable?: boolean | null, nonConfigurable?: boolean | null, loose?: boolean) => void;
2
- export = _exports;
3
- //# sourceMappingURL=index.d.ts.map
1
+
2
+ declare function defineDataProperty(
3
+ obj: Record<PropertyKey, unknown>,
4
+ property: keyof typeof obj,
5
+ value: typeof obj[typeof property],
6
+ nonEnumerable?: boolean | null,
7
+ nonWritable?: boolean | null,
8
+ nonConfigurable?: boolean | null,
9
+ loose?: boolean
10
+ ): void;
11
+
12
+ export = defineDataProperty;
@@ -19,7 +19,7 @@ var $TypeError = require('es-errors/type');
19
19
 
20
20
  var gopd = require('gopd');
21
21
 
22
- /** @type {(obj: Record<PropertyKey, unknown>, property: PropertyKey, value: unknown, nonEnumerable?: boolean | null, nonWritable?: boolean | null, nonConfigurable?: boolean | null, loose?: boolean) => void} */
22
+ /** @type {import('.')} */
23
23
  module.exports = function defineDataProperty(
24
24
  obj,
25
25
  property,
@@ -1,28 +1,19 @@
1
1
  {
2
2
  "name": "define-data-property",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Define a data property on an object. Will fall back to assignment in an engine without descriptors.",
5
5
  "main": "index.js",
6
+ "types": "./index.d.ts",
6
7
  "exports": {
7
- ".": [
8
- {
9
- "types": "./index.d.ts",
10
- "default": "./index.js"
11
- },
12
- "./index.js"
13
- ],
8
+ ".": "./index.js",
14
9
  "./package.json": "./package.json"
15
10
  },
16
11
  "sideEffects": false,
17
- "types": "./index.d.ts",
18
12
  "scripts": {
19
- "prepack": "npmignore --auto --commentLines=autogenerated && npm run emit-types",
13
+ "prepack": "npmignore --auto --commentLines=autogenerated",
20
14
  "prepublish": "not-in-publish || npm run prepublishOnly",
21
15
  "prepublishOnly": "safe-publish-latest",
22
16
  "tsc": "tsc -p .",
23
- "preemit-types": "rm -f *.ts *.ts.map test/*.ts test/*.ts.map",
24
- "emit-types": "npm run tsc -- --noEmit false --emitDeclarationOnly",
25
- "postemit-types": "rm test/*.ts test/*.ts.map",
26
17
  "prelint": "evalmd README.md",
27
18
  "lint": "eslint --ext=js,mjs .",
28
19
  "postlint": "npm run tsc",
@@ -50,6 +41,9 @@
50
41
  "writable"
51
42
  ],
52
43
  "author": "Jordan Harband <ljharb@gmail.com>",
44
+ "funding": {
45
+ "url": "https://github.com/sponsors/ljharb"
46
+ },
53
47
  "license": "MIT",
54
48
  "bugs": {
55
49
  "url": "https://github.com/ljharb/define-data-property/issues"
@@ -57,17 +51,18 @@
57
51
  "homepage": "https://github.com/ljharb/define-data-property#readme",
58
52
  "dependencies": {
59
53
  "es-errors": "^1.3.0",
60
- "get-intrinsic": "^1.2.2",
54
+ "get-intrinsic": "^1.2.4",
61
55
  "gopd": "^1.0.1",
62
56
  "has-property-descriptors": "^1.0.1"
63
57
  },
64
58
  "devDependencies": {
65
59
  "@ljharb/eslint-config": "^21.1.0",
60
+ "@types/call-bind": "^1.0.5",
61
+ "@types/define-properties": "^1.1.5",
66
62
  "@types/es-value-fixtures": "^1.4.4",
67
63
  "@types/for-each": "^0.3.3",
68
64
  "@types/get-intrinsic": "^1.2.2",
69
65
  "@types/gopd": "^1.0.3",
70
- "@types/has": "^1.0.1",
71
66
  "@types/has-property-descriptors": "^1.0.3",
72
67
  "@types/object-inspect": "^1.8.4",
73
68
  "@types/object.getownpropertydescriptors": "^2.1.3",
@@ -78,7 +73,7 @@
78
73
  "eslint": "=8.8.0",
79
74
  "evalmd": "^0.0.19",
80
75
  "for-each": "^0.3.3",
81
- "hasown": "^2.0.0",
76
+ "hasown": "^2.0.1",
82
77
  "in-publish": "^2.0.1",
83
78
  "npmignore": "^0.3.1",
84
79
  "nyc": "^10.3.2",
@@ -106,8 +101,6 @@
106
101
  "publishConfig": {
107
102
  "ignore": [
108
103
  ".github/workflows",
109
- "!*.ts",
110
- "!*.ts.map",
111
104
  "types/reflect.ownkeys"
112
105
  ]
113
106
  }
@@ -34,21 +34,21 @@ test('defineDataProperty', function (t) {
34
34
  forEach(v.nonBooleans, function (nonBoolean) {
35
35
  if (nonBoolean !== null) {
36
36
  st['throws'](
37
- // @ts-expect-error
37
+ // @ts-expect-error
38
38
  function () { defineDataProperty({}, 'key', 'value', nonBoolean); },
39
39
  TypeError,
40
40
  'throws on non-boolean nonEnumerable: ' + inspect(nonBoolean)
41
41
  );
42
42
 
43
43
  st['throws'](
44
- // @ts-expect-error
44
+ // @ts-expect-error
45
45
  function () { defineDataProperty({}, 'key', 'value', false, nonBoolean); },
46
46
  TypeError,
47
47
  'throws on non-boolean nonWritable: ' + inspect(nonBoolean)
48
48
  );
49
49
 
50
50
  st['throws'](
51
- // @ts-expect-error
51
+ // @ts-expect-error
52
52
  function () { defineDataProperty({}, 'key', 'value', false, false, nonBoolean); },
53
53
  TypeError,
54
54
  'throws on non-boolean nonConfigurable: ' + inspect(nonBoolean)
@@ -15,25 +15,22 @@ Generally we like to see pull requests that
15
15
  ## Building
16
16
 
17
17
  ```
18
- npm install
19
- npm test
18
+ yarn
19
+ yarn test
20
20
  ```
21
21
 
22
- The `npm test -- dev` implements watching for tests within Node and `karma start` may be used for manual testing in browsers.
22
+ Running `yarn test -- dev` will watch for tests within Node and `karma start` may be used for manual testing in browsers.
23
23
 
24
24
  If you notice any problems, please report them to the GitHub issue tracker at
25
25
  [http://github.com/kpdecker/jsdiff/issues](http://github.com/kpdecker/jsdiff/issues).
26
26
 
27
27
  ## Releasing
28
28
 
29
- JsDiff utilizes the [release yeoman generator][generator-release] to perform most release tasks.
30
-
31
29
  A full release may be completed with the following:
32
30
 
33
31
  ```
34
- yo release
35
- npm publish
32
+ yarn clean
33
+ yarn grunt
34
+ yarn grunt uglify
35
+ yarn publish
36
36
  ```
37
-
38
- [generator-release]: https://github.com/walmartlabs/generator-release
39
- [pull-request]: https://github.com/kpdecker/jsdiff/pull/new/master
@@ -1,31 +1,29 @@
1
- Software License Agreement (BSD License)
1
+ BSD 3-Clause License
2
2
 
3
3
  Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
4
-
5
4
  All rights reserved.
6
5
 
7
- Redistribution and use of this software in source and binary forms, with or without modification,
8
- are permitted provided that the following conditions are met:
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
9
8
 
10
- * Redistributions of source code must retain the above
11
- copyright notice, this list of conditions and the
12
- following disclaimer.
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
13
11
 
14
- * Redistributions in binary form must reproduce the above
15
- copyright notice, this list of conditions and the
16
- following disclaimer in the documentation and/or other
17
- materials provided with the distribution.
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
18
15
 
19
- * Neither the name of Kevin Decker nor the names of its
20
- contributors may be used to endorse or promote products
21
- derived from this software without specific prior
22
- written permission.
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
23
19
 
24
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
25
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
26
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30
- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31
- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -3,87 +3,113 @@
3
3
  [![Build Status](https://secure.travis-ci.org/kpdecker/jsdiff.svg)](http://travis-ci.org/kpdecker/jsdiff)
4
4
  [![Sauce Test Status](https://saucelabs.com/buildstatus/jsdiff)](https://saucelabs.com/u/jsdiff)
5
5
 
6
- A javascript text differencing implementation.
6
+ A JavaScript text differencing implementation. Try it out in the **[online demo](https://kpdecker.github.io/jsdiff)**.
7
7
 
8
8
  Based on the algorithm proposed in
9
- ["An O(ND) Difference Algorithm and its Variations" (Myers, 1986)](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927).
9
+ ["An O(ND) Difference Algorithm and its Variations" (Myers, 1986)](http://www.xmailserver.org/diff2.pdf).
10
10
 
11
11
  ## Installation
12
12
  ```bash
13
13
  npm install diff --save
14
14
  ```
15
15
 
16
- ## API
16
+ ## Usage
17
17
 
18
- * `Diff.diffChars(oldStr, newStr[, options])` - diffs two blocks of text, comparing character by character.
18
+ Broadly, jsdiff's diff functions all take an old text and a new text and perform three steps:
19
19
 
20
- Returns a list of change objects (See below).
20
+ 1. Split both texts into arrays of "tokens". What constitutes a token varies; in `diffChars`, each character is a token, while in `diffLines`, each line is a token.
21
21
 
22
- Options
23
- * `ignoreCase`: `true` to ignore casing difference. Defaults to `false`.
22
+ 2. Find the smallest set of single-token *insertions* and *deletions* needed to transform the first array of tokens into the second.
23
+
24
+ This step depends upon having some notion of a token from the old array being "equal" to one from the new array, and this notion of equality affects the results. Usually two tokens are equal if `===` considers them equal, but some of the diff functions use an alternative notion of equality or have options to configure it. For instance, by default `diffChars("Foo", "FOOD")` will require two deletions (`o`, `o`) and three insertions (`O`, `O`, `D`), but `diffChars("Foo", "FOOD", {ignoreCase: true})` will require just one insertion (of a `D`), since `ignoreCase` causes `o` and `O` to be considered equal.
25
+
26
+ 3. Return an array representing the transformation computed in the previous step as a series of [change objects](#change-objects). The array is ordered from the start of the input to the end, and each change object represents *inserting* one or more tokens, *deleting* one or more tokens, or *keeping* one or more tokens.
27
+
28
+ ### API
24
29
 
25
- * `Diff.diffWords(oldStr, newStr[, options])` - diffs two blocks of text, comparing word by word, ignoring whitespace.
30
+ * `Diff.diffChars(oldStr, newStr[, options])` - diffs two blocks of text, treating each character as a token.
26
31
 
27
- Returns a list of change objects (See below).
32
+ Returns a list of [change objects](#change-objects).
28
33
 
29
34
  Options
30
- * `ignoreCase`: Same as in `diffChars`.
35
+ * `ignoreCase`: If `true`, the uppercase and lowercase forms of a character are considered equal. Defaults to `false`.
36
+
37
+ * `Diff.diffWords(oldStr, newStr[, options])` - diffs two blocks of text, treating each word and each word separator (punctuation, newline, or run of whitespace) as a token.
38
+
39
+ (Whitespace-only tokens are automatically treated as equal to each other, so changes like changing a space to a newline or a run of multiple spaces will be ignored.)
40
+
41
+ Returns a list of [change objects](#change-objects).
31
42
 
32
- * `Diff.diffWordsWithSpace(oldStr, newStr[, options])` - diffs two blocks of text, comparing word by word, treating whitespace as significant.
43
+ Options
44
+ * `ignoreCase`: Same as in `diffChars`. Defaults to false.
33
45
 
34
- Returns a list of change objects (See below).
46
+ * `Diff.diffWordsWithSpace(oldStr, newStr[, options])` - same as `diffWords`, except whitespace-only tokens are not automatically considered equal, so e.g. changing a space to a tab is considered a change.
35
47
 
36
- * `Diff.diffLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line.
48
+ * `Diff.diffLines(oldStr, newStr[, options])` - diffs two blocks of text, treating each line as a token.
37
49
 
38
50
  Options
39
- * `ignoreWhitespace`: `true` to ignore leading and trailing whitespace. This is the same as `diffTrimmedLines`
40
- * `newlineIsToken`: `true` to treat newline characters as separate tokens. This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more human friendly form of `diffLines` and `diffLines` is better suited for patches and other computer friendly output.
51
+ * `ignoreWhitespace`: `true` to strip all leading and trailing whitespace characters from each line before performing the diff. Defaults to `false`.
52
+ * `stripTrailingCr`: `true` to remove all trailing CR (`\r`) characters before performing the diff. Defaults to `false`.
53
+ This helps to get a useful diff when diffing UNIX text files against Windows text files.
54
+ * `newlineIsToken`: `true` to treat the newline character at the end of each line as its own token. This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more human friendly form of `diffLines`; the default behavior with this option turned off is better suited for patches and other computer friendly output. Defaults to `false`.
55
+
56
+ Returns a list of [change objects](#change-objects).
41
57
 
42
- Returns a list of change objects (See below).
58
+ * `Diff.diffTrimmedLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line, after stripping leading and trailing whitespace. Equivalent to calling `diffLines` with `ignoreWhitespace: true`.
43
59
 
44
- * `Diff.diffTrimmedLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line, ignoring leading and trailing whitespace.
60
+ Options
61
+ * `stripTrailingCr`: Same as in `diffLines`. Defaults to `false`.
62
+ * `newlineIsToken`: Same as in `diffLines`. Defaults to `false`.
45
63
 
46
- Returns a list of change objects (See below).
64
+ Returns a list of [change objects](#change-objects).
47
65
 
48
- * `Diff.diffSentences(oldStr, newStr[, options])` - diffs two blocks of text, comparing sentence by sentence.
66
+ * `Diff.diffSentences(oldStr, newStr[, options])` - diffs two blocks of text, treating each sentence as a token.
49
67
 
50
- Returns a list of change objects (See below).
68
+ Returns a list of [change objects](#change-objects).
51
69
 
52
70
  * `Diff.diffCss(oldStr, newStr[, options])` - diffs two blocks of text, comparing CSS tokens.
53
71
 
54
- Returns a list of change objects (See below).
72
+ Returns a list of [change objects](#change-objects).
55
73
 
56
- * `Diff.diffJson(oldObj, newObj[, options])` - diffs two JSON objects, comparing the fields defined on each. The order of fields, etc does not matter in this comparison.
74
+ * `Diff.diffJson(oldObj, newObj[, options])` - diffs two JSON-serializable objects by first serializing them to prettily-formatted JSON and then treating each line of the JSON as a token. Object properties are ordered alphabetically in the serialized JSON, so the order of properties in the objects being compared doesn't affect the result.
57
75
 
58
- Returns a list of change objects (See below).
76
+ Returns a list of [change objects](#change-objects).
77
+
78
+ Options
79
+ * `stringifyReplacer`: A custom replacer function. Operates similarly to the `replacer` parameter to [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter), but must be a function.
80
+ * `undefinedReplacement`: A value to replace `undefined` with. Ignored if a `stringifyReplacer` is provided.
59
81
 
60
- * `Diff.diffArrays(oldArr, newArr[, options])` - diffs two arrays, comparing each item for strict equality (===).
82
+ * `Diff.diffArrays(oldArr, newArr[, options])` - diffs two arrays of tokens, comparing each item for strict equality (===).
61
83
 
62
84
  Options
63
85
  * `comparator`: `function(left, right)` for custom equality checks
64
86
 
65
- Returns a list of change objects (See below).
87
+ Returns a list of [change objects](#change-objects).
66
88
 
67
- * `Diff.createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch.
89
+ * `Diff.createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr[, oldHeader[, newHeader[, options]]])` - creates a unified diff patch by first computing a diff with `diffLines` and then serializing it to unified diff format.
68
90
 
69
91
  Parameters:
70
92
  * `oldFileName` : String to be output in the filename section of the patch for the removals
71
93
  * `newFileName` : String to be output in the filename section of the patch for the additions
72
94
  * `oldStr` : Original string value
73
95
  * `newStr` : New string value
74
- * `oldHeader` : Additional information to include in the old file header
75
- * `newHeader` : Additional information to include in the new file header
96
+ * `oldHeader` : Optional additional information to include in the old file header. Default: `undefined`.
97
+ * `newHeader` : Optional additional information to include in the new file header. Default: `undefined`.
76
98
  * `options` : An object with options.
77
- - `context` describes how many lines of context should be included.
78
- - `ignoreWhitespace`: `true` to ignore leading and trailing whitespace.
79
- - `newlineIsToken`: `true` to treat newline characters as separate tokens. This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more human friendly form of `diffLines` and `diffLines` is better suited for patches and other computer friendly output.
99
+ - `context` describes how many lines of context should be included. You can set this to `Number.MAX_SAFE_INTEGER` or `Infinity` to include the entire file content in one hunk.
100
+ - `ignoreWhitespace`: Same as in `diffLines`. Defaults to `false`.
101
+ - `stripTrailingCr`: Same as in `diffLines`. Defaults to `false`.
102
+ - `newlineIsToken`: Same as in `diffLines`. Defaults to `false`.
80
103
 
81
- * `Diff.createPatch(fileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch.
104
+ * `Diff.createPatch(fileName, oldStr, newStr[, oldHeader[, newHeader[, options]]])` - creates a unified diff patch.
82
105
 
83
106
  Just like Diff.createTwoFilesPatch, but with oldFileName being equal to newFileName.
84
107
 
108
+ * `Diff.formatPatch(patch)` - creates a unified diff patch.
109
+
110
+ `patch` may be either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`).
85
111
 
86
- * `Diff.structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options)` - returns an object with an array of hunk objects.
112
+ * `Diff.structuredPatch(oldFileName, newFileName, oldStr, newStr[, oldHeader[, newHeader[, options]]])` - returns an object with an array of hunk objects.
87
113
 
88
114
  This method is similar to createTwoFilesPatch, but returns a data structure
89
115
  suitable for further processing. Parameters are the same as createTwoFilesPatch. The data structure returned may look like this:
@@ -99,9 +125,11 @@ npm install diff --save
99
125
  }
100
126
  ```
101
127
 
102
- * `Diff.applyPatch(source, patch[, options])` - applies a unified diff patch.
128
+ * `Diff.applyPatch(source, patch[, options])` - attempts to apply a unified diff patch.
129
+
130
+ If the patch was applied successfully, returns a string containing the patched text. If the patch could not be applied (because some hunks in the patch couldn't be fitted to the text in `source`), returns false.
103
131
 
104
- Return a string containing new version of provided data. `patch` may be a string diff or the output from the `parsePatch` or `structuredPatch` methods.
132
+ `patch` may be a string diff or the output from the `parsePatch` or `structuredPatch` methods.
105
133
 
106
134
  The optional `options` object may have the following keys:
107
135
 
@@ -110,6 +138,8 @@ npm install diff --save
110
138
 
111
139
  * `Diff.applyPatches(patch, options)` - applies one or more patches.
112
140
 
141
+ `patch` may be either an array of structured patch objects, or a string representing a patch in unified diff format (which may patch one or more files).
142
+
113
143
  This method will iterate over the contents of the patch and apply to data provided through callbacks. The general flow for each patch index is:
114
144
 
115
145
  - `options.loadFile(index, callback)` is called. The caller should then load the contents of the file and then pass that to the `callback(err, data)` callback. Passing an `err` will terminate further patch execution.
@@ -121,23 +151,56 @@ npm install diff --save
121
151
 
122
152
  Return a JSON object representation of the a patch, suitable for use with the `applyPatch` method. This parses to the same structure returned by `Diff.structuredPatch`.
123
153
 
124
- * `convertChangesToXML(changes)` - converts a list of changes to a serialized XML format
154
+ * `Diff.reversePatch(patch)` - Returns a new structured patch which when applied will undo the original `patch`.
155
+
156
+ `patch` may be either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`).
157
+
158
+ * `Diff.convertChangesToXML(changes)` - converts a list of change objects to a serialized XML format
159
+
160
+ * `Diff.convertChangesToDMP(changes)` - converts a list of change objects to the format returned by Google's [diff-match-patch](https://github.com/google/diff-match-patch) library
161
+
162
+ #### Universal `options`
163
+
164
+ Certain options can be provided in the `options` object of *any* method that calculates a diff:
165
+
166
+ * `callback`: if provided, the diff will be computed in async mode to avoid blocking the event loop while the diff is calculated. The value of the `callback` option should be a function and will be passed the result of the diff as its second argument. The first argument will always be undefined. Only works with functions that return change objects, like `diffLines`, not those that return patches, like `structuredPatch` or `createPatch`.
167
+
168
+ (Note that if the ONLY option you want to provide is a callback, you can pass the callback function directly as the `options` parameter instead of passing an object with a `callback` property.)
169
+ * `maxEditLength`: a number specifying the maximum edit distance to consider between the old and new texts. If the edit distance is higher than this, jsdiff will return `undefined` instead of a diff. You can use this to limit the computational cost of diffing large, very different texts by giving up early if the cost will be huge. Works for functions that return change objects and also for `structuredPatch`, but not other patch-generation functions.
170
+
171
+ * `timeout`: a number of milliseconds after which the diffing algorithm will abort and return `undefined`. Supported by the same functions as `maxEditLength`.
172
+
173
+ ### Defining custom diffing behaviors
174
+
175
+ If you need behavior a little different to what any of the text diffing functions above offer, you can roll your own by customizing both the tokenization behavior used and the notion of equality used to determine if two tokens are equal.
176
+
177
+ The simplest way to customize tokenization behavior is to simply tokenize the texts you want to diff yourself, with your own code, then pass the arrays of tokens to `diffArrays`. For instance, if you wanted a semantically-aware diff of some code, you could try tokenizing it using a parser specific to the programming language the code is in, then passing the arrays of tokens to `diffArrays`.
178
+
179
+ To customize the notion of token equality used, use the `comparator` option to `diffArrays`.
125
180
 
181
+ For even more customisation of the diffing behavior, you can create a `new Diff.Diff()` object, overwrite its `castInput`, `tokenize`, `removeEmpty`, `equals`, and `join` properties with your own functions, then call its `diff(oldString, newString[, options])` method. The methods you can overwrite are used as follows:
126
182
 
127
- All methods above which accept the optional `callback` method will run in sync mode when that parameter is omitted and in async mode when supplied. This allows for larger diffs without blocking the event loop. This may be passed either directly as the final parameter or as the `callback` field in the `options` object.
183
+ * `castInput(value)`: used to transform the `oldString` and `newString` before any other steps in the diffing algorithm happen. For instance, `diffJson` uses `castInput` to serialize the objects being diffed to JSON. Defaults to a no-op.
184
+ * `tokenize(value)`: used to convert each of `oldString` and `newString` (after they've gone through `castInput`) to an array of tokens. Defaults to returning `value.split('')` (returning an array of individual characters).
185
+ * `removeEmpty(array)`: called on the arrays of tokens returned by `tokenize` and can be used to modify them. Defaults to stripping out falsey tokens, such as empty strings. `diffArrays` overrides this to simply return the `array`, which means that falsey values like empty strings can be handled like any other token by `diffArrays`.
186
+ * `equals(left, right)`: called to determine if two tokens (one from the old string, one from the new string) should be considered equal. Defaults to comparing them with `===`.
187
+ * `join(tokens)`: gets called with an array of consecutive tokens that have either all been added, all been removed, or are all common. Needs to join them into a single value that can be used as the `value` property of the [change object](#change-objects) for these tokens. Defaults to simply returning `tokens.join('')`.
128
188
 
129
189
  ### Change Objects
130
190
  Many of the methods above return change objects. These objects consist of the following fields:
131
191
 
132
- * `value`: Text content
192
+ * `value`: The concatenated content of all the tokens represented by this change object - i.e. generally the text that is either added, deleted, or common, as a single string. In cases where tokens are considered common but are non-identical (e.g. because an option like `ignoreCase` or a custom `comparator` was used), the value from the *new* string will be provided here.
133
193
  * `added`: True if the value was inserted into the new string
134
194
  * `removed`: True if the value was removed from the old string
195
+ * `count`: How many tokens (e.g. chars for `diffChars`, lines for `diffLines`) the value in the change object consists of
196
+
197
+ (Change objects where `added` and `removed` are both falsey represent content that is common to the old and new strings.)
135
198
 
136
199
  Note that some cases may omit a particular flag field. Comparison on the flag fields should always be done in a truthy or falsy manner.
137
200
 
138
201
  ## Examples
139
202
 
140
- Basic example in Node
203
+ #### Basic example in Node
141
204
 
142
205
  ```js
143
206
  require('colors');
@@ -150,10 +213,10 @@ const diff = Diff.diffChars(one, other);
150
213
 
151
214
  diff.forEach((part) => {
152
215
  // green for additions, red for deletions
153
- // grey for common parts
154
- const color = part.added ? 'green' :
155
- part.removed ? 'red' : 'grey';
156
- process.stderr.write(part.value[color]);
216
+ let text = part.added ? part.value.bgGreen :
217
+ part.removed ? part.value.bgRed :
218
+ part.value;
219
+ process.stderr.write(text);
157
220
  });
158
221
 
159
222
  console.log();
@@ -162,7 +225,7 @@ Running the above program should yield
162
225
 
163
226
  <img src="images/node_example.png" alt="Node Example">
164
227
 
165
- Basic example in a web page
228
+ #### Basic example in a web page
166
229
 
167
230
  ```html
168
231
  <pre id="display"></pre>
@@ -198,7 +261,65 @@ Open the above .html file in a browser and you should see
198
261
 
199
262
  <img src="images/web_example.png" alt="Node Example">
200
263
 
201
- **[Full online demo](https://kpdecker.github.io/jsdiff)**
264
+ #### Example of generating a patch from Node
265
+
266
+ The code below is roughly equivalent to the Unix command `diff -u file1.txt file2.txt > mydiff.patch`:
267
+
268
+ ```
269
+ const Diff = require('diff');
270
+ const file1Contents = fs.readFileSync("file1.txt").toString();
271
+ const file2Contents = fs.readFileSync("file2.txt").toString();
272
+ const patch = Diff.createTwoFilesPatch("file1.txt", "file2.txt", file1Contents, file2Contents);
273
+ fs.writeFileSync("mydiff.patch", patch);
274
+ ```
275
+
276
+ #### Examples of parsing and applying a patch from Node
277
+
278
+ ##### Applying a patch to a specified file
279
+
280
+ The code below is roughly equivalent to the Unix command `patch file1.txt mydiff.patch`:
281
+
282
+ ```
283
+ const Diff = require('diff');
284
+ const file1Contents = fs.readFileSync("file1.txt").toString();
285
+ const patch = fs.readFileSync("mydiff.patch").toString();
286
+ const patchedFile = Diff.applyPatch(file1Contents, patch);
287
+ fs.writeFileSync("file1.txt", patchedFile);
288
+ ```
289
+
290
+ ##### Applying a multi-file patch to the files specified by the patch file itself
291
+
292
+ The code below is roughly equivalent to the Unix command `patch < mydiff.patch`:
293
+
294
+ ```
295
+ const Diff = require('diff');
296
+ const patch = fs.readFileSync("mydiff.patch").toString();
297
+ Diff.applyPatches(patch, {
298
+ loadFile: (patch, callback) => {
299
+ let fileContents;
300
+ try {
301
+ fileContents = fs.readFileSync(patch.oldFileName).toString();
302
+ } catch (e) {
303
+ callback(`No such file: ${patch.oldFileName}`);
304
+ return;
305
+ }
306
+ callback(undefined, fileContents);
307
+ },
308
+ patched: (patch, patchedContent, callback) => {
309
+ if (patchedContent === false) {
310
+ callback(`Failed to apply patch to ${patch.oldFileName}`)
311
+ return;
312
+ }
313
+ fs.writeFileSync(patch.oldFileName, patchedContent);
314
+ callback();
315
+ },
316
+ complete: (err) => {
317
+ if (err) {
318
+ console.log("Failed with error:", err);
319
+ }
320
+ }
321
+ });
322
+ ```
202
323
 
203
324
  ## Compatibility
204
325
 
@@ -209,3 +330,10 @@ jsdiff supports all ES3 environments with some known issues on IE8 and below. Un
209
330
  ## License
210
331
 
211
332
  See [LICENSE](https://github.com/kpdecker/jsdiff/blob/master/LICENSE).
333
+
334
+ ## Deviations from the published Myers diff algorithm
335
+
336
+ jsdiff deviates from the published algorithm in a couple of ways that don't affect results but do affect performance:
337
+
338
+ * jsdiff keeps track of the diff for each diagonal using a linked list of change objects for each diagonal, rather than the historical array of furthest-reaching D-paths on each diagonal contemplated on page 8 of Myers's paper.
339
+ * jsdiff skips considering diagonals where the furthest-reaching D-path would go off the edge of the edit graph. This dramatically reduces the time cost (from quadratic to linear) in cases where the new text just appends or truncates content at the end of the old text.