@xyne/xyne-cli-linux-x64 0.4.3 → 0.4.5

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.
Files changed (151) hide show
  1. package/node_modules/@opentui/core/index-4kfx7p6q.js +47 -9
  2. package/package.json +1 -1
  3. package/xyne-linux-x64 +0 -0
  4. package/node_modules/@opentui/core/node_modules/diff/CONTRIBUTING.md +0 -28
  5. package/node_modules/@opentui/core/node_modules/diff/LICENSE +0 -29
  6. package/node_modules/@opentui/core/node_modules/diff/README.md +0 -378
  7. package/node_modules/@opentui/core/node_modules/diff/dist/diff.js +0 -1674
  8. package/node_modules/@opentui/core/node_modules/diff/dist/diff.min.js +0 -1
  9. package/node_modules/@opentui/core/node_modules/diff/eslint.config.mjs +0 -182
  10. package/node_modules/@opentui/core/node_modules/diff/libcjs/convert/dmp.d.ts +0 -8
  11. package/node_modules/@opentui/core/node_modules/diff/libcjs/convert/dmp.d.ts.map +0 -1
  12. package/node_modules/@opentui/core/node_modules/diff/libcjs/convert/dmp.js +0 -24
  13. package/node_modules/@opentui/core/node_modules/diff/libcjs/convert/xml.d.ts +0 -6
  14. package/node_modules/@opentui/core/node_modules/diff/libcjs/convert/xml.d.ts.map +0 -1
  15. package/node_modules/@opentui/core/node_modules/diff/libcjs/convert/xml.js +0 -34
  16. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/array.d.ts +0 -19
  17. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/array.d.ts.map +0 -1
  18. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/array.js +0 -40
  19. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/base.d.ts +0 -20
  20. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/base.d.ts.map +0 -1
  21. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/base.js +0 -265
  22. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/character.d.ts +0 -19
  23. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/character.d.ts.map +0 -1
  24. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/character.js +0 -31
  25. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/css.d.ts +0 -18
  26. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/css.d.ts.map +0 -1
  27. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/css.js +0 -34
  28. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/json.d.ts +0 -24
  29. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/json.d.ts.map +0 -1
  30. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/json.js +0 -105
  31. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/line.d.ts +0 -24
  32. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/line.d.ts.map +0 -1
  33. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/line.js +0 -89
  34. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/sentence.d.ts +0 -21
  35. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/sentence.d.ts.map +0 -1
  36. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/sentence.js +0 -67
  37. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/word.d.ts +0 -35
  38. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/word.d.ts.map +0 -1
  39. package/node_modules/@opentui/core/node_modules/diff/libcjs/diff/word.js +0 -307
  40. package/node_modules/@opentui/core/node_modules/diff/libcjs/index.d.ts +0 -20
  41. package/node_modules/@opentui/core/node_modules/diff/libcjs/index.d.ts.map +0 -1
  42. package/node_modules/@opentui/core/node_modules/diff/libcjs/index.js +0 -61
  43. package/node_modules/@opentui/core/node_modules/diff/libcjs/package.json +0 -1
  44. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/apply.d.ts +0 -62
  45. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/apply.d.ts.map +0 -1
  46. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/apply.js +0 -267
  47. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/create.d.ts +0 -100
  48. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/create.d.ts.map +0 -1
  49. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/create.js +0 -223
  50. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/line-endings.d.ts +0 -17
  51. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/line-endings.d.ts.map +0 -1
  52. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/line-endings.js +0 -61
  53. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/parse.d.ts +0 -8
  54. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/parse.d.ts.map +0 -1
  55. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/parse.js +0 -133
  56. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/reverse.d.ts +0 -9
  57. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/reverse.d.ts.map +0 -1
  58. package/node_modules/@opentui/core/node_modules/diff/libcjs/patch/reverse.js +0 -37
  59. package/node_modules/@opentui/core/node_modules/diff/libcjs/types.d.ts +0 -213
  60. package/node_modules/@opentui/core/node_modules/diff/libcjs/types.d.ts.map +0 -1
  61. package/node_modules/@opentui/core/node_modules/diff/libcjs/types.js +0 -2
  62. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/array.d.ts +0 -3
  63. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/array.d.ts.map +0 -1
  64. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/array.js +0 -21
  65. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/distance-iterator.d.ts +0 -2
  66. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/distance-iterator.d.ts.map +0 -1
  67. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/distance-iterator.js +0 -40
  68. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/params.d.ts +0 -4
  69. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/params.d.ts.map +0 -1
  70. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/params.js +0 -17
  71. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/string.d.ts +0 -18
  72. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/string.d.ts.map +0 -1
  73. package/node_modules/@opentui/core/node_modules/diff/libcjs/util/string.js +0 -141
  74. package/node_modules/@opentui/core/node_modules/diff/libesm/convert/dmp.d.ts +0 -8
  75. package/node_modules/@opentui/core/node_modules/diff/libesm/convert/dmp.d.ts.map +0 -1
  76. package/node_modules/@opentui/core/node_modules/diff/libesm/convert/dmp.js +0 -21
  77. package/node_modules/@opentui/core/node_modules/diff/libesm/convert/xml.d.ts +0 -6
  78. package/node_modules/@opentui/core/node_modules/diff/libesm/convert/xml.d.ts.map +0 -1
  79. package/node_modules/@opentui/core/node_modules/diff/libesm/convert/xml.js +0 -31
  80. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/array.d.ts +0 -19
  81. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/array.d.ts.map +0 -1
  82. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/array.js +0 -16
  83. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/base.d.ts +0 -20
  84. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/base.d.ts.map +0 -1
  85. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/base.js +0 -253
  86. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/character.d.ts +0 -19
  87. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/character.d.ts.map +0 -1
  88. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/character.js +0 -7
  89. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/css.d.ts +0 -18
  90. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/css.d.ts.map +0 -1
  91. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/css.js +0 -10
  92. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/json.d.ts +0 -24
  93. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/json.d.ts.map +0 -1
  94. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/json.js +0 -78
  95. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/line.d.ts +0 -24
  96. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/line.d.ts.map +0 -1
  97. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/line.js +0 -65
  98. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/sentence.d.ts +0 -21
  99. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/sentence.d.ts.map +0 -1
  100. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/sentence.js +0 -43
  101. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/word.d.ts +0 -35
  102. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/word.d.ts.map +0 -1
  103. package/node_modules/@opentui/core/node_modules/diff/libesm/diff/word.js +0 -276
  104. package/node_modules/@opentui/core/node_modules/diff/libesm/index.d.ts +0 -20
  105. package/node_modules/@opentui/core/node_modules/diff/libesm/index.d.ts.map +0 -1
  106. package/node_modules/@opentui/core/node_modules/diff/libesm/index.js +0 -30
  107. package/node_modules/@opentui/core/node_modules/diff/libesm/package.json +0 -1
  108. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/apply.d.ts +0 -62
  109. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/apply.d.ts.map +0 -1
  110. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/apply.js +0 -257
  111. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/create.d.ts +0 -100
  112. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/create.d.ts.map +0 -1
  113. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/create.js +0 -201
  114. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/line-endings.d.ts +0 -17
  115. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/line-endings.d.ts.map +0 -1
  116. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/line-endings.js +0 -44
  117. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/parse.d.ts +0 -8
  118. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/parse.d.ts.map +0 -1
  119. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/parse.js +0 -130
  120. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/reverse.d.ts +0 -9
  121. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/reverse.d.ts.map +0 -1
  122. package/node_modules/@opentui/core/node_modules/diff/libesm/patch/reverse.js +0 -23
  123. package/node_modules/@opentui/core/node_modules/diff/libesm/types.d.ts +0 -213
  124. package/node_modules/@opentui/core/node_modules/diff/libesm/types.d.ts.map +0 -1
  125. package/node_modules/@opentui/core/node_modules/diff/libesm/types.js +0 -1
  126. package/node_modules/@opentui/core/node_modules/diff/libesm/util/array.d.ts +0 -3
  127. package/node_modules/@opentui/core/node_modules/diff/libesm/util/array.d.ts.map +0 -1
  128. package/node_modules/@opentui/core/node_modules/diff/libesm/util/array.js +0 -17
  129. package/node_modules/@opentui/core/node_modules/diff/libesm/util/distance-iterator.d.ts +0 -2
  130. package/node_modules/@opentui/core/node_modules/diff/libesm/util/distance-iterator.d.ts.map +0 -1
  131. package/node_modules/@opentui/core/node_modules/diff/libesm/util/distance-iterator.js +0 -37
  132. package/node_modules/@opentui/core/node_modules/diff/libesm/util/params.d.ts +0 -4
  133. package/node_modules/@opentui/core/node_modules/diff/libesm/util/params.d.ts.map +0 -1
  134. package/node_modules/@opentui/core/node_modules/diff/libesm/util/params.js +0 -14
  135. package/node_modules/@opentui/core/node_modules/diff/libesm/util/string.d.ts +0 -18
  136. package/node_modules/@opentui/core/node_modules/diff/libesm/util/string.d.ts.map +0 -1
  137. package/node_modules/@opentui/core/node_modules/diff/libesm/util/string.js +0 -128
  138. package/node_modules/@opentui/core/node_modules/diff/package.json +0 -131
  139. package/node_modules/@opentui/core/node_modules/diff/release-notes.md +0 -397
  140. package/node_modules/@opentui/core/node_modules/marked/LICENSE.md +0 -44
  141. package/node_modules/@opentui/core/node_modules/marked/README.md +0 -107
  142. package/node_modules/@opentui/core/node_modules/marked/bin/main.js +0 -283
  143. package/node_modules/@opentui/core/node_modules/marked/bin/marked.js +0 -16
  144. package/node_modules/@opentui/core/node_modules/marked/lib/marked.d.ts +0 -756
  145. package/node_modules/@opentui/core/node_modules/marked/lib/marked.esm.js +0 -72
  146. package/node_modules/@opentui/core/node_modules/marked/lib/marked.esm.js.map +0 -7
  147. package/node_modules/@opentui/core/node_modules/marked/lib/marked.umd.js +0 -74
  148. package/node_modules/@opentui/core/node_modules/marked/lib/marked.umd.js.map +0 -7
  149. package/node_modules/@opentui/core/node_modules/marked/man/marked.1 +0 -113
  150. package/node_modules/@opentui/core/node_modules/marked/man/marked.1.md +0 -93
  151. package/node_modules/@opentui/core/node_modules/marked/package.json +0 -103
@@ -1,267 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyPatch = applyPatch;
4
- exports.applyPatches = applyPatches;
5
- var string_js_1 = require("../util/string.js");
6
- var line_endings_js_1 = require("./line-endings.js");
7
- var parse_js_1 = require("./parse.js");
8
- var distance_iterator_js_1 = require("../util/distance-iterator.js");
9
- /**
10
- * attempts to apply a unified diff patch.
11
- *
12
- * Hunks are applied first to last.
13
- * `applyPatch` first tries to apply the first hunk at the line number specified in the hunk header, and with all context lines matching exactly.
14
- * If that fails, it tries scanning backwards and forwards, one line at a time, to find a place to apply the hunk where the context lines match exactly.
15
- * If that still fails, and `fuzzFactor` is greater than zero, it increments the maximum number of mismatches (missing, extra, or changed context lines) that there can be between the hunk context and a region where we are trying to apply the patch such that the hunk will still be considered to match.
16
- * Regardless of `fuzzFactor`, lines to be deleted in the hunk *must* be present for a hunk to match, and the context lines *immediately* before and after an insertion must match exactly.
17
- *
18
- * Once a hunk is successfully fitted, the process begins again with the next hunk.
19
- * Regardless of `fuzzFactor`, later hunks must be applied later in the file than earlier hunks.
20
- *
21
- * If a hunk cannot be successfully fitted *anywhere* with fewer than `fuzzFactor` mismatches, `applyPatch` fails and returns `false`.
22
- *
23
- * If a hunk is successfully fitted but not at the line number specified by the hunk header, all subsequent hunks have their target line number adjusted accordingly.
24
- * (e.g. if the first hunk is applied 10 lines below where the hunk header said it should fit, `applyPatch` will *start* looking for somewhere to apply the second hunk 10 lines below where its hunk header says it goes.)
25
- *
26
- * If the patch was applied successfully, returns a string containing the patched text.
27
- * If the patch could not be applied (because some hunks in the patch couldn't be fitted to the text in `source`), `applyPatch` returns false.
28
- *
29
- * @param patch a string diff or the output from the `parsePatch` or `structuredPatch` methods.
30
- */
31
- function applyPatch(source, patch, options) {
32
- if (options === void 0) { options = {}; }
33
- var patches;
34
- if (typeof patch === 'string') {
35
- patches = (0, parse_js_1.parsePatch)(patch);
36
- }
37
- else if (Array.isArray(patch)) {
38
- patches = patch;
39
- }
40
- else {
41
- patches = [patch];
42
- }
43
- if (patches.length > 1) {
44
- throw new Error('applyPatch only works with a single input.');
45
- }
46
- return applyStructuredPatch(source, patches[0], options);
47
- }
48
- function applyStructuredPatch(source, patch, options) {
49
- if (options === void 0) { options = {}; }
50
- if (options.autoConvertLineEndings || options.autoConvertLineEndings == null) {
51
- if ((0, string_js_1.hasOnlyWinLineEndings)(source) && (0, line_endings_js_1.isUnix)(patch)) {
52
- patch = (0, line_endings_js_1.unixToWin)(patch);
53
- }
54
- else if ((0, string_js_1.hasOnlyUnixLineEndings)(source) && (0, line_endings_js_1.isWin)(patch)) {
55
- patch = (0, line_endings_js_1.winToUnix)(patch);
56
- }
57
- }
58
- // Apply the diff to the input
59
- var lines = source.split('\n'), hunks = patch.hunks, compareLine = options.compareLine || (function (lineNumber, line, operation, patchContent) { return line === patchContent; }), fuzzFactor = options.fuzzFactor || 0;
60
- var minLine = 0;
61
- if (fuzzFactor < 0 || !Number.isInteger(fuzzFactor)) {
62
- throw new Error('fuzzFactor must be a non-negative integer');
63
- }
64
- // Special case for empty patch.
65
- if (!hunks.length) {
66
- return source;
67
- }
68
- // Before anything else, handle EOFNL insertion/removal. If the patch tells us to make a change
69
- // to the EOFNL that is redundant/impossible - i.e. to remove a newline that's not there, or add a
70
- // newline that already exists - then we either return false and fail to apply the patch (if
71
- // fuzzFactor is 0) or simply ignore the problem and do nothing (if fuzzFactor is >0).
72
- // If we do need to remove/add a newline at EOF, this will always be in the final hunk:
73
- var prevLine = '', removeEOFNL = false, addEOFNL = false;
74
- for (var i = 0; i < hunks[hunks.length - 1].lines.length; i++) {
75
- var line = hunks[hunks.length - 1].lines[i];
76
- if (line[0] == '\\') {
77
- if (prevLine[0] == '+') {
78
- removeEOFNL = true;
79
- }
80
- else if (prevLine[0] == '-') {
81
- addEOFNL = true;
82
- }
83
- }
84
- prevLine = line;
85
- }
86
- if (removeEOFNL) {
87
- if (addEOFNL) {
88
- // This means the final line gets changed but doesn't have a trailing newline in either the
89
- // original or patched version. In that case, we do nothing if fuzzFactor > 0, and if
90
- // fuzzFactor is 0, we simply validate that the source file has no trailing newline.
91
- if (!fuzzFactor && lines[lines.length - 1] == '') {
92
- return false;
93
- }
94
- }
95
- else if (lines[lines.length - 1] == '') {
96
- lines.pop();
97
- }
98
- else if (!fuzzFactor) {
99
- return false;
100
- }
101
- }
102
- else if (addEOFNL) {
103
- if (lines[lines.length - 1] != '') {
104
- lines.push('');
105
- }
106
- else if (!fuzzFactor) {
107
- return false;
108
- }
109
- }
110
- /**
111
- * Checks if the hunk can be made to fit at the provided location with at most `maxErrors`
112
- * insertions, substitutions, or deletions, while ensuring also that:
113
- * - lines deleted in the hunk match exactly, and
114
- * - wherever an insertion operation or block of insertion operations appears in the hunk, the
115
- * immediately preceding and following lines of context match exactly
116
- *
117
- * `toPos` should be set such that lines[toPos] is meant to match hunkLines[0].
118
- *
119
- * If the hunk can be applied, returns an object with properties `oldLineLastI` and
120
- * `replacementLines`. Otherwise, returns null.
121
- */
122
- function applyHunk(hunkLines, toPos, maxErrors, hunkLinesI, lastContextLineMatched, patchedLines, patchedLinesLength) {
123
- if (hunkLinesI === void 0) { hunkLinesI = 0; }
124
- if (lastContextLineMatched === void 0) { lastContextLineMatched = true; }
125
- if (patchedLines === void 0) { patchedLines = []; }
126
- if (patchedLinesLength === void 0) { patchedLinesLength = 0; }
127
- var nConsecutiveOldContextLines = 0;
128
- var nextContextLineMustMatch = false;
129
- for (; hunkLinesI < hunkLines.length; hunkLinesI++) {
130
- var hunkLine = hunkLines[hunkLinesI], operation = (hunkLine.length > 0 ? hunkLine[0] : ' '), content = (hunkLine.length > 0 ? hunkLine.substr(1) : hunkLine);
131
- if (operation === '-') {
132
- if (compareLine(toPos + 1, lines[toPos], operation, content)) {
133
- toPos++;
134
- nConsecutiveOldContextLines = 0;
135
- }
136
- else {
137
- if (!maxErrors || lines[toPos] == null) {
138
- return null;
139
- }
140
- patchedLines[patchedLinesLength] = lines[toPos];
141
- return applyHunk(hunkLines, toPos + 1, maxErrors - 1, hunkLinesI, false, patchedLines, patchedLinesLength + 1);
142
- }
143
- }
144
- if (operation === '+') {
145
- if (!lastContextLineMatched) {
146
- return null;
147
- }
148
- patchedLines[patchedLinesLength] = content;
149
- patchedLinesLength++;
150
- nConsecutiveOldContextLines = 0;
151
- nextContextLineMustMatch = true;
152
- }
153
- if (operation === ' ') {
154
- nConsecutiveOldContextLines++;
155
- patchedLines[patchedLinesLength] = lines[toPos];
156
- if (compareLine(toPos + 1, lines[toPos], operation, content)) {
157
- patchedLinesLength++;
158
- lastContextLineMatched = true;
159
- nextContextLineMustMatch = false;
160
- toPos++;
161
- }
162
- else {
163
- if (nextContextLineMustMatch || !maxErrors) {
164
- return null;
165
- }
166
- // Consider 3 possibilities in sequence:
167
- // 1. lines contains a *substitution* not included in the patch context, or
168
- // 2. lines contains an *insertion* not included in the patch context, or
169
- // 3. lines contains a *deletion* not included in the patch context
170
- // The first two options are of course only possible if the line from lines is non-null -
171
- // i.e. only option 3 is possible if we've overrun the end of the old file.
172
- return (lines[toPos] && (applyHunk(hunkLines, toPos + 1, maxErrors - 1, hunkLinesI + 1, false, patchedLines, patchedLinesLength + 1) || applyHunk(hunkLines, toPos + 1, maxErrors - 1, hunkLinesI, false, patchedLines, patchedLinesLength + 1)) || applyHunk(hunkLines, toPos, maxErrors - 1, hunkLinesI + 1, false, patchedLines, patchedLinesLength));
173
- }
174
- }
175
- }
176
- // Before returning, trim any unmodified context lines off the end of patchedLines and reduce
177
- // toPos (and thus oldLineLastI) accordingly. This allows later hunks to be applied to a region
178
- // that starts in this hunk's trailing context.
179
- patchedLinesLength -= nConsecutiveOldContextLines;
180
- toPos -= nConsecutiveOldContextLines;
181
- patchedLines.length = patchedLinesLength;
182
- return {
183
- patchedLines: patchedLines,
184
- oldLineLastI: toPos - 1
185
- };
186
- }
187
- var resultLines = [];
188
- // Search best fit offsets for each hunk based on the previous ones
189
- var prevHunkOffset = 0;
190
- for (var i = 0; i < hunks.length; i++) {
191
- var hunk = hunks[i];
192
- var hunkResult = void 0;
193
- var maxLine = lines.length - hunk.oldLines + fuzzFactor;
194
- var toPos = void 0;
195
- for (var maxErrors = 0; maxErrors <= fuzzFactor; maxErrors++) {
196
- toPos = hunk.oldStart + prevHunkOffset - 1;
197
- var iterator = (0, distance_iterator_js_1.default)(toPos, minLine, maxLine);
198
- for (; toPos !== undefined; toPos = iterator()) {
199
- hunkResult = applyHunk(hunk.lines, toPos, maxErrors);
200
- if (hunkResult) {
201
- break;
202
- }
203
- }
204
- if (hunkResult) {
205
- break;
206
- }
207
- }
208
- if (!hunkResult) {
209
- return false;
210
- }
211
- // Copy everything from the end of where we applied the last hunk to the start of this hunk
212
- for (var i_1 = minLine; i_1 < toPos; i_1++) {
213
- resultLines.push(lines[i_1]);
214
- }
215
- // Add the lines produced by applying the hunk:
216
- for (var i_2 = 0; i_2 < hunkResult.patchedLines.length; i_2++) {
217
- var line = hunkResult.patchedLines[i_2];
218
- resultLines.push(line);
219
- }
220
- // Set lower text limit to end of the current hunk, so next ones don't try
221
- // to fit over already patched text
222
- minLine = hunkResult.oldLineLastI + 1;
223
- // Note the offset between where the patch said the hunk should've applied and where we
224
- // applied it, so we can adjust future hunks accordingly:
225
- prevHunkOffset = toPos + 1 - hunk.oldStart;
226
- }
227
- // Copy over the rest of the lines from the old text
228
- for (var i = minLine; i < lines.length; i++) {
229
- resultLines.push(lines[i]);
230
- }
231
- return resultLines.join('\n');
232
- }
233
- /**
234
- * applies one or more patches.
235
- *
236
- * `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).
237
- *
238
- * 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:
239
- *
240
- * - `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.
241
- * - `options.patched(index, content, callback)` is called once the patch has been applied. `content` will be the return value from `applyPatch`. When it's ready, the caller should call `callback(err)` callback. Passing an `err` will terminate further patch execution.
242
- *
243
- * Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made.
244
- */
245
- function applyPatches(uniDiff, options) {
246
- var spDiff = typeof uniDiff === 'string' ? (0, parse_js_1.parsePatch)(uniDiff) : uniDiff;
247
- var currentIndex = 0;
248
- function processIndex() {
249
- var index = spDiff[currentIndex++];
250
- if (!index) {
251
- return options.complete();
252
- }
253
- options.loadFile(index, function (err, data) {
254
- if (err) {
255
- return options.complete(err);
256
- }
257
- var updatedContent = applyPatch(data, index, options);
258
- options.patched(index, updatedContent, function (err) {
259
- if (err) {
260
- return options.complete(err);
261
- }
262
- processIndex();
263
- });
264
- });
265
- }
266
- processIndex();
267
- }
@@ -1,100 +0,0 @@
1
- import type { StructuredPatch, DiffLinesOptionsAbortable, DiffLinesOptionsNonabortable, AbortableDiffOptions } from '../types.js';
2
- type StructuredPatchCallbackAbortable = (patch: StructuredPatch | undefined) => void;
3
- type StructuredPatchCallbackNonabortable = (patch: StructuredPatch) => void;
4
- interface _StructuredPatchOptionsAbortable extends Pick<DiffLinesOptionsAbortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
5
- /**
6
- * describes how many lines of context should be included.
7
- * You can set this to `Number.MAX_SAFE_INTEGER` or `Infinity` to include the entire file content in one hunk.
8
- * @default 4
9
- */
10
- context?: number;
11
- callback?: StructuredPatchCallbackAbortable;
12
- }
13
- export type StructuredPatchOptionsAbortable = _StructuredPatchOptionsAbortable & AbortableDiffOptions;
14
- export interface StructuredPatchOptionsNonabortable extends Pick<DiffLinesOptionsNonabortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
15
- context?: number;
16
- callback?: StructuredPatchCallbackNonabortable;
17
- }
18
- interface StructuredPatchCallbackOptionAbortable {
19
- /**
20
- * If provided, the diff will be computed in async mode to avoid blocking the event loop while the diff is calculated.
21
- * The value of the `callback` option should be a function and will be passed the computed diff or patch as its first argument.
22
- */
23
- callback: StructuredPatchCallbackAbortable;
24
- }
25
- interface StructuredPatchCallbackOptionNonabortable {
26
- /**
27
- * If provided, the diff will be computed in async mode to avoid blocking the event loop while the diff is calculated.
28
- * The value of the `callback` option should be a function and will be passed the computed diff or patch as its first argument.
29
- */
30
- callback: StructuredPatchCallbackNonabortable;
31
- }
32
- /**
33
- * returns an object with an array of hunk objects.
34
- *
35
- * This method is similar to createTwoFilesPatch, but returns a data structure suitable for further processing.
36
- * @param oldFileName String to be output in the filename section of the patch for the removals
37
- * @param newFileName String to be output in the filename section of the patch for the additions
38
- * @param oldStr Original string value
39
- * @param newStr New string value
40
- * @param oldHeader Optional additional information to include in the old file header.
41
- * @param newHeader Optional additional information to include in the new file header.
42
- */
43
- export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchCallbackNonabortable): undefined;
44
- export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchOptionsAbortable & StructuredPatchCallbackOptionAbortable): undefined;
45
- export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchOptionsNonabortable & StructuredPatchCallbackOptionNonabortable): undefined;
46
- export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchOptionsAbortable): StructuredPatch | undefined;
47
- export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader?: string, newHeader?: string, options?: StructuredPatchOptionsNonabortable): StructuredPatch;
48
- /**
49
- * creates a unified diff patch.
50
- * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
51
- */
52
- export declare function formatPatch(patch: StructuredPatch | StructuredPatch[]): string;
53
- type CreatePatchCallbackAbortable = (patch: string | undefined) => void;
54
- type CreatePatchCallbackNonabortable = (patch: string) => void;
55
- interface _CreatePatchOptionsAbortable extends Pick<DiffLinesOptionsAbortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
56
- context?: number;
57
- callback?: CreatePatchCallbackAbortable;
58
- }
59
- export type CreatePatchOptionsAbortable = _CreatePatchOptionsAbortable & AbortableDiffOptions;
60
- export interface CreatePatchOptionsNonabortable extends Pick<DiffLinesOptionsNonabortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
61
- context?: number;
62
- callback?: CreatePatchCallbackNonabortable;
63
- }
64
- interface CreatePatchCallbackOptionAbortable {
65
- callback: CreatePatchCallbackAbortable;
66
- }
67
- interface CreatePatchCallbackOptionNonabortable {
68
- callback: CreatePatchCallbackNonabortable;
69
- }
70
- /**
71
- * creates a unified diff patch by first computing a diff with `diffLines` and then serializing it to unified diff format.
72
- * @param oldFileName String to be output in the filename section of the patch for the removals
73
- * @param newFileName String to be output in the filename section of the patch for the additions
74
- * @param oldStr Original string value
75
- * @param newStr New string value
76
- * @param oldHeader Optional additional information to include in the old file header.
77
- * @param newHeader Optional additional information to include in the new file header.
78
- */
79
- export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchCallbackNonabortable): undefined;
80
- export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable & CreatePatchCallbackOptionAbortable): undefined;
81
- export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsNonabortable & CreatePatchCallbackOptionNonabortable): undefined;
82
- export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable): string | undefined;
83
- export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader?: string, newHeader?: string, options?: CreatePatchOptionsNonabortable): string;
84
- /**
85
- * creates a unified diff patch.
86
- *
87
- * Just like createTwoFilesPatch, but with oldFileName being equal to newFileName.
88
- * @param fileName String to be output in the filename section of the patch
89
- * @param oldStr Original string value
90
- * @param newStr New string value
91
- * @param oldHeader Optional additional information to include in the old file header.
92
- * @param newHeader Optional additional information to include in the new file header.
93
- */
94
- export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchCallbackNonabortable): undefined;
95
- export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable & CreatePatchCallbackOptionAbortable): undefined;
96
- export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsNonabortable & CreatePatchCallbackOptionNonabortable): undefined;
97
- export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable): string | undefined;
98
- export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader?: string, newHeader?: string, options?: CreatePatchOptionsNonabortable): string;
99
- export {};
100
- //# sourceMappingURL=create.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/patch/create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,oBAAoB,EAAgB,MAAM,aAAa,CAAC;AAEhJ,KAAK,gCAAgC,GAAG,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,KAAK,IAAI,CAAC;AACrF,KAAK,mCAAmC,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;AAE5E,UAAU,gCAAiC,SAAQ,IAAI,CAAC,yBAAyB,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;IACxH;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,gCAAgC,CAAC;CAC7C;AACD,MAAM,MAAM,+BAA+B,GAAG,gCAAgC,GAAG,oBAAoB,CAAC;AACtG,MAAM,WAAW,kCAAmC,SAAQ,IAAI,CAAC,4BAA4B,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;IACpI,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,mCAAmC,CAAC;CAChD;AACD,UAAU,sCAAsC;IAC9C;;;OAGG;IACH,QAAQ,EAAE,gCAAgC,CAAC;CAC5C;AACD,UAAU,yCAAyC;IACjD;;;OAGG;IACH,QAAQ,EAAE,mCAAmC,CAAC;CAC/C;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,EAAE,mCAAmC,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QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,EAAE,2BAA2B,GACnC,MAAM,GAAG,SAAS,CAAA;AACrB,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,CAAA"}
@@ -1,223 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.structuredPatch = structuredPatch;
15
- exports.formatPatch = formatPatch;
16
- exports.createTwoFilesPatch = createTwoFilesPatch;
17
- exports.createPatch = createPatch;
18
- var line_js_1 = require("../diff/line.js");
19
- function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
20
- var optionsObj;
21
- if (!options) {
22
- optionsObj = {};
23
- }
24
- else if (typeof options === 'function') {
25
- optionsObj = { callback: options };
26
- }
27
- else {
28
- optionsObj = options;
29
- }
30
- if (typeof optionsObj.context === 'undefined') {
31
- optionsObj.context = 4;
32
- }
33
- // We copy this into its own variable to placate TypeScript, which thinks
34
- // optionsObj.context might be undefined in the callbacks below.
35
- var context = optionsObj.context;
36
- // @ts-expect-error (runtime check for something that is correctly a static type error)
37
- if (optionsObj.newlineIsToken) {
38
- throw new Error('newlineIsToken may not be used with patch-generation functions, only with diffing functions');
39
- }
40
- if (!optionsObj.callback) {
41
- return diffLinesResultToPatch((0, line_js_1.diffLines)(oldStr, newStr, optionsObj));
42
- }
43
- else {
44
- var callback_1 = optionsObj.callback;
45
- (0, line_js_1.diffLines)(oldStr, newStr, __assign(__assign({}, optionsObj), { callback: function (diff) {
46
- var patch = diffLinesResultToPatch(diff);
47
- // TypeScript is unhappy without the cast because it does not understand that `patch` may
48
- // be undefined here only if `callback` is StructuredPatchCallbackAbortable:
49
- callback_1(patch);
50
- } }));
51
- }
52
- function diffLinesResultToPatch(diff) {
53
- // STEP 1: Build up the patch with no "" lines and with the arrays
54
- // of lines containing trailing newline characters. We'll tidy up later...
55
- if (!diff) {
56
- return;
57
- }
58
- diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
59
- function contextLines(lines) {
60
- return lines.map(function (entry) { return ' ' + entry; });
61
- }
62
- var hunks = [];
63
- var oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
64
- for (var i = 0; i < diff.length; i++) {
65
- var current = diff[i], lines = current.lines || splitLines(current.value);
66
- current.lines = lines;
67
- if (current.added || current.removed) {
68
- // If we have previous context, start with that
69
- if (!oldRangeStart) {
70
- var prev = diff[i - 1];
71
- oldRangeStart = oldLine;
72
- newRangeStart = newLine;
73
- if (prev) {
74
- curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
75
- oldRangeStart -= curRange.length;
76
- newRangeStart -= curRange.length;
77
- }
78
- }
79
- // Output our changes
80
- for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
81
- var line = lines_1[_i];
82
- curRange.push((current.added ? '+' : '-') + line);
83
- }
84
- // Track the updated file position
85
- if (current.added) {
86
- newLine += lines.length;
87
- }
88
- else {
89
- oldLine += lines.length;
90
- }
91
- }
92
- else {
93
- // Identical context lines. Track line changes
94
- if (oldRangeStart) {
95
- // Close out any changes that have been output (or join overlapping)
96
- if (lines.length <= context * 2 && i < diff.length - 2) {
97
- // Overlapping
98
- for (var _a = 0, _b = contextLines(lines); _a < _b.length; _a++) {
99
- var line = _b[_a];
100
- curRange.push(line);
101
- }
102
- }
103
- else {
104
- // end the range and output
105
- var contextSize = Math.min(lines.length, context);
106
- for (var _c = 0, _d = contextLines(lines.slice(0, contextSize)); _c < _d.length; _c++) {
107
- var line = _d[_c];
108
- curRange.push(line);
109
- }
110
- var hunk = {
111
- oldStart: oldRangeStart,
112
- oldLines: (oldLine - oldRangeStart + contextSize),
113
- newStart: newRangeStart,
114
- newLines: (newLine - newRangeStart + contextSize),
115
- lines: curRange
116
- };
117
- hunks.push(hunk);
118
- oldRangeStart = 0;
119
- newRangeStart = 0;
120
- curRange = [];
121
- }
122
- }
123
- oldLine += lines.length;
124
- newLine += lines.length;
125
- }
126
- }
127
- // Step 2: eliminate the trailing `\n` from each line of each hunk, and, where needed, add
128
- // "".
129
- for (var _e = 0, hunks_1 = hunks; _e < hunks_1.length; _e++) {
130
- var hunk = hunks_1[_e];
131
- for (var i = 0; i < hunk.lines.length; i++) {
132
- if (hunk.lines[i].endsWith('\n')) {
133
- hunk.lines[i] = hunk.lines[i].slice(0, -1);
134
- }
135
- else {
136
- hunk.lines.splice(i + 1, 0, '\');
137
- i++; // Skip the line we just added, then continue iterating
138
- }
139
- }
140
- }
141
- return {
142
- oldFileName: oldFileName, newFileName: newFileName,
143
- oldHeader: oldHeader, newHeader: newHeader,
144
- hunks: hunks
145
- };
146
- }
147
- }
148
- /**
149
- * creates a unified diff patch.
150
- * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
151
- */
152
- function formatPatch(patch) {
153
- if (Array.isArray(patch)) {
154
- return patch.map(formatPatch).join('\n');
155
- }
156
- var ret = [];
157
- if (patch.oldFileName == patch.newFileName) {
158
- ret.push('Index: ' + patch.oldFileName);
159
- }
160
- ret.push('===================================================================');
161
- ret.push('--- ' + patch.oldFileName + (typeof patch.oldHeader === 'undefined' ? '' : '\t' + patch.oldHeader));
162
- ret.push('+++ ' + patch.newFileName + (typeof patch.newHeader === 'undefined' ? '' : '\t' + patch.newHeader));
163
- for (var i = 0; i < patch.hunks.length; i++) {
164
- var hunk = patch.hunks[i];
165
- // Unified Diff Format quirk: If the chunk size is 0,
166
- // the first number is one lower than one would expect.
167
- // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
168
- if (hunk.oldLines === 0) {
169
- hunk.oldStart -= 1;
170
- }
171
- if (hunk.newLines === 0) {
172
- hunk.newStart -= 1;
173
- }
174
- ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines
175
- + ' +' + hunk.newStart + ',' + hunk.newLines
176
- + ' @@');
177
- for (var _i = 0, _a = hunk.lines; _i < _a.length; _i++) {
178
- var line = _a[_i];
179
- ret.push(line);
180
- }
181
- }
182
- return ret.join('\n') + '\n';
183
- }
184
- function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
185
- if (typeof options === 'function') {
186
- options = { callback: options };
187
- }
188
- if (!(options === null || options === void 0 ? void 0 : options.callback)) {
189
- var patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
190
- if (!patchObj) {
191
- return;
192
- }
193
- return formatPatch(patchObj);
194
- }
195
- else {
196
- var callback_2 = options.callback;
197
- structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, __assign(__assign({}, options), { callback: function (patchObj) {
198
- if (!patchObj) {
199
- callback_2(undefined);
200
- }
201
- else {
202
- callback_2(formatPatch(patchObj));
203
- }
204
- } }));
205
- }
206
- }
207
- function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
208
- return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
209
- }
210
- /**
211
- * Split `text` into an array of lines, including the trailing newline character (where present)
212
- */
213
- function splitLines(text) {
214
- var hasTrailingNl = text.endsWith('\n');
215
- var result = text.split('\n').map(function (line) { return line + '\n'; });
216
- if (hasTrailingNl) {
217
- result.pop();
218
- }
219
- else {
220
- result.push(result.pop().slice(0, -1));
221
- }
222
- return result;
223
- }
@@ -1,17 +0,0 @@
1
- import type { StructuredPatch } from '../types.js';
2
- export declare function unixToWin(patch: StructuredPatch): StructuredPatch;
3
- export declare function unixToWin(patches: StructuredPatch[]): StructuredPatch[];
4
- export declare function unixToWin(patch: StructuredPatch | StructuredPatch[]): StructuredPatch | StructuredPatch[];
5
- export declare function winToUnix(patch: StructuredPatch): StructuredPatch;
6
- export declare function winToUnix(patches: StructuredPatch[]): StructuredPatch[];
7
- export declare function winToUnix(patch: StructuredPatch | StructuredPatch[]): StructuredPatch | StructuredPatch[];
8
- /**
9
- * Returns true if the patch consistently uses Unix line endings (or only involves one line and has
10
- * no line endings).
11
- */
12
- export declare function isUnix(patch: StructuredPatch | StructuredPatch[]): boolean;
13
- /**
14
- * Returns true if the patch uses Windows line endings and only Windows line endings.
15
- */
16
- export declare function isWin(patch: StructuredPatch | StructuredPatch[]): boolean;
17
- //# sourceMappingURL=line-endings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"line-endings.d.ts","sourceRoot":"","sources":["../../src/patch/line-endings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CAAC;AACnE,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAAC;AACzE,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,EAAE,GAAG,eAAe,GAAG,eAAe,EAAE,CAAC;AA0B3G,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CAAC;AACnE,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAAC;AACzE,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,EAAE,GAAG,eAAe,GAAG,eAAe,EAAE,CAAC;AAgB3G;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,EAAE,GAAG,OAAO,CAS1E;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,EAAE,GAAG,OAAO,CAUzE"}