@mtkruto/node 0.0.6

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 (167) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +1 -0
  3. package/esm/_dnt.shims.js +68 -0
  4. package/esm/client/client.js +169 -0
  5. package/esm/client/client_abstract.js +51 -0
  6. package/esm/client/client_plain.js +112 -0
  7. package/esm/connection/connection.js +2 -0
  8. package/esm/connection/connection_web_socket.js +90 -0
  9. package/esm/constants.js +60 -0
  10. package/esm/deps/deno.land/std@0.186.0/fmt/colors.js +474 -0
  11. package/esm/deps/deno.land/std@0.186.0/testing/_diff.js +311 -0
  12. package/esm/deps/deno.land/std@0.186.0/testing/_format.js +23 -0
  13. package/esm/deps/deno.land/std@0.186.0/testing/asserts.js +633 -0
  14. package/esm/deps/deno.land/x/crc32@v0.2.0/mod.js +105 -0
  15. package/esm/deps/deno.land/x/tgcrypto@0.1.1/mod.js +68 -0
  16. package/esm/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1127 -0
  17. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +239 -0
  18. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +10 -0
  19. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +139 -0
  20. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +176 -0
  21. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +2 -0
  22. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +19 -0
  23. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +25 -0
  24. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1941 -0
  25. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +85 -0
  26. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +321 -0
  27. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1658 -0
  28. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +355 -0
  29. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +11 -0
  30. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +42 -0
  31. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1107 -0
  32. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +86 -0
  33. package/esm/deps.js +4 -0
  34. package/esm/mod.js +4 -0
  35. package/esm/package.json +3 -0
  36. package/esm/tl/0_tl_raw_reader.js +62 -0
  37. package/esm/tl/0_tl_raw_writer.js +60 -0
  38. package/esm/tl/1_tl_object.js +149 -0
  39. package/esm/tl/2_types.js +48220 -0
  40. package/esm/tl/3_functions.js +19856 -0
  41. package/esm/tl/3_tl_object_deserializer.js +72 -0
  42. package/esm/tl/3_tl_reader.js +16 -0
  43. package/esm/tl/3_tl_writer.js +7 -0
  44. package/esm/tl/4_rpc_result.js +27 -0
  45. package/esm/tl/5_message.js +54 -0
  46. package/esm/tl/6_message_container.js +35 -0
  47. package/esm/transport/transport.js +32 -0
  48. package/esm/transport/transport_intermediate.js +56 -0
  49. package/esm/transport/transport_provider.js +23 -0
  50. package/esm/types.js +1 -0
  51. package/esm/utilities/0_bigint.js +37 -0
  52. package/esm/utilities/0_buffer.js +33 -0
  53. package/esm/utilities/0_crypto.js +35 -0
  54. package/esm/utilities/0_hash.js +7 -0
  55. package/esm/utilities/1_auth.js +29 -0
  56. package/esm/utilities/1_message.js +94 -0
  57. package/esm/utilities/1_obfuscation.js +33 -0
  58. package/package.json +40 -0
  59. package/script/_dnt.shims.js +77 -0
  60. package/script/client/client.js +173 -0
  61. package/script/client/client_abstract.js +55 -0
  62. package/script/client/client_plain.js +116 -0
  63. package/script/connection/connection.js +6 -0
  64. package/script/connection/connection_web_socket.js +117 -0
  65. package/script/constants.js +63 -0
  66. package/script/deps/deno.land/std@0.186.0/fmt/colors.js +548 -0
  67. package/script/deps/deno.land/std@0.186.0/testing/_diff.js +317 -0
  68. package/script/deps/deno.land/std@0.186.0/testing/_format.js +50 -0
  69. package/script/deps/deno.land/std@0.186.0/testing/asserts.js +659 -0
  70. package/script/deps/deno.land/x/crc32@v0.2.0/mod.js +113 -0
  71. package/script/deps/deno.land/x/tgcrypto@0.1.1/mod.js +82 -0
  72. package/script/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1152 -0
  73. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +271 -0
  74. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +14 -0
  75. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +172 -0
  76. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +208 -0
  77. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +18 -0
  78. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +22 -0
  79. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +30 -0
  80. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1976 -0
  81. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +88 -0
  82. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +324 -0
  83. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1674 -0
  84. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +358 -0
  85. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +14 -0
  86. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +44 -0
  87. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1115 -0
  88. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +89 -0
  89. package/script/deps.js +30 -0
  90. package/script/mod.js +32 -0
  91. package/script/package.json +3 -0
  92. package/script/tl/0_tl_raw_reader.js +66 -0
  93. package/script/tl/0_tl_raw_writer.js +64 -0
  94. package/script/tl/1_tl_object.js +156 -0
  95. package/script/tl/2_types.js +49824 -0
  96. package/script/tl/3_functions.js +20413 -0
  97. package/script/tl/3_tl_object_deserializer.js +76 -0
  98. package/script/tl/3_tl_reader.js +20 -0
  99. package/script/tl/3_tl_writer.js +11 -0
  100. package/script/tl/4_rpc_result.js +31 -0
  101. package/script/tl/5_message.js +58 -0
  102. package/script/tl/6_message_container.js +39 -0
  103. package/script/transport/transport.js +36 -0
  104. package/script/transport/transport_intermediate.js +60 -0
  105. package/script/transport/transport_provider.js +27 -0
  106. package/script/types.js +2 -0
  107. package/script/utilities/0_bigint.js +67 -0
  108. package/script/utilities/0_buffer.js +38 -0
  109. package/script/utilities/0_crypto.js +39 -0
  110. package/script/utilities/0_hash.js +35 -0
  111. package/script/utilities/1_auth.js +56 -0
  112. package/script/utilities/1_message.js +102 -0
  113. package/script/utilities/1_obfuscation.js +60 -0
  114. package/types/_dnt.shims.d.ts +10 -0
  115. package/types/client/client.d.ts +19 -0
  116. package/types/client/client_abstract.d.ts +20 -0
  117. package/types/client/client_plain.d.ts +10 -0
  118. package/types/connection/connection.d.ts +7 -0
  119. package/types/connection/connection_web_socket.d.ts +13 -0
  120. package/types/constants.d.ts +2 -0
  121. package/types/deps/deno.land/std@0.186.0/fmt/colors.d.ts +270 -0
  122. package/types/deps/deno.land/std@0.186.0/testing/_diff.d.ts +26 -0
  123. package/types/deps/deno.land/std@0.186.0/testing/_format.d.ts +1 -0
  124. package/types/deps/deno.land/std@0.186.0/testing/asserts.d.ts +284 -0
  125. package/types/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +15 -0
  126. package/types/deps/deno.land/x/tgcrypto@0.1.1/mod.d.ts +47 -0
  127. package/types/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.d.ts +2 -0
  128. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +16 -0
  129. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +1 -0
  130. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +29 -0
  131. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +23 -0
  132. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +2 -0
  133. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +1 -0
  134. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +2 -0
  135. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +78 -0
  136. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +12 -0
  137. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +1 -0
  138. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +47 -0
  139. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +1 -0
  140. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +12 -0
  141. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +30 -0
  142. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +5 -0
  143. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +14 -0
  144. package/types/deps.d.ts +4 -0
  145. package/types/mod.d.ts +4 -0
  146. package/types/tl/0_tl_raw_reader.d.ts +13 -0
  147. package/types/tl/0_tl_raw_writer.d.ts +13 -0
  148. package/types/tl/1_tl_object.d.ts +36 -0
  149. package/types/tl/2_types.d.ts +14815 -0
  150. package/types/tl/3_functions.d.ts +6122 -0
  151. package/types/tl/3_tl_object_deserializer.d.ts +3 -0
  152. package/types/tl/3_tl_reader.d.ts +4 -0
  153. package/types/tl/3_tl_writer.d.ts +5 -0
  154. package/types/tl/4_rpc_result.d.ts +8 -0
  155. package/types/tl/5_message.d.ts +11 -0
  156. package/types/tl/6_message_container.d.ts +9 -0
  157. package/types/transport/transport.d.ts +15 -0
  158. package/types/transport/transport_intermediate.d.ts +11 -0
  159. package/types/transport/transport_provider.d.ts +12 -0
  160. package/types/types.d.ts +1 -0
  161. package/types/utilities/0_bigint.d.ts +4 -0
  162. package/types/utilities/0_buffer.d.ts +2 -0
  163. package/types/utilities/0_crypto.d.ts +8 -0
  164. package/types/utilities/0_hash.d.ts +2 -0
  165. package/types/utilities/1_auth.d.ts +1 -0
  166. package/types/utilities/1_message.d.ts +10 -0
  167. package/types/utilities/1_obfuscation.d.ts +6 -0
@@ -0,0 +1,317 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.buildMessage = exports.diffstr = exports.diff = exports.DiffType = void 0;
6
+ const colors_js_1 = require("../fmt/colors.js");
7
+ var DiffType;
8
+ (function (DiffType) {
9
+ DiffType["removed"] = "removed";
10
+ DiffType["common"] = "common";
11
+ DiffType["added"] = "added";
12
+ })(DiffType = exports.DiffType || (exports.DiffType = {}));
13
+ const REMOVED = 1;
14
+ const COMMON = 2;
15
+ const ADDED = 3;
16
+ function createCommon(A, B, reverse) {
17
+ const common = [];
18
+ if (A.length === 0 || B.length === 0)
19
+ return [];
20
+ for (let i = 0; i < Math.min(A.length, B.length); i += 1) {
21
+ if (A[reverse ? A.length - i - 1 : i] === B[reverse ? B.length - i - 1 : i]) {
22
+ common.push(A[reverse ? A.length - i - 1 : i]);
23
+ }
24
+ else {
25
+ return common;
26
+ }
27
+ }
28
+ return common;
29
+ }
30
+ /**
31
+ * Renders the differences between the actual and expected values
32
+ * @param A Actual value
33
+ * @param B Expected value
34
+ */
35
+ function diff(A, B) {
36
+ const prefixCommon = createCommon(A, B);
37
+ const suffixCommon = createCommon(A.slice(prefixCommon.length), B.slice(prefixCommon.length), true).reverse();
38
+ A = suffixCommon.length
39
+ ? A.slice(prefixCommon.length, -suffixCommon.length)
40
+ : A.slice(prefixCommon.length);
41
+ B = suffixCommon.length
42
+ ? B.slice(prefixCommon.length, -suffixCommon.length)
43
+ : B.slice(prefixCommon.length);
44
+ const swapped = B.length > A.length;
45
+ [A, B] = swapped ? [B, A] : [A, B];
46
+ const M = A.length;
47
+ const N = B.length;
48
+ if (!M && !N && !suffixCommon.length && !prefixCommon.length)
49
+ return [];
50
+ if (!N) {
51
+ return [
52
+ ...prefixCommon.map((c) => ({ type: DiffType.common, value: c })),
53
+ ...A.map((a) => ({
54
+ type: swapped ? DiffType.added : DiffType.removed,
55
+ value: a,
56
+ })),
57
+ ...suffixCommon.map((c) => ({ type: DiffType.common, value: c })),
58
+ ];
59
+ }
60
+ const offset = N;
61
+ const delta = M - N;
62
+ const size = M + N + 1;
63
+ const fp = Array.from({ length: size }, () => ({ y: -1, id: -1 }));
64
+ /**
65
+ * INFO:
66
+ * This buffer is used to save memory and improve performance.
67
+ * The first half is used to save route and last half is used to save diff
68
+ * type.
69
+ * This is because, when I kept new uint8array area to save type,performance
70
+ * worsened.
71
+ */
72
+ const routes = new Uint32Array((M * N + size + 1) * 2);
73
+ const diffTypesPtrOffset = routes.length / 2;
74
+ let ptr = 0;
75
+ let p = -1;
76
+ function backTrace(A, B, current, swapped) {
77
+ const M = A.length;
78
+ const N = B.length;
79
+ const result = [];
80
+ let a = M - 1;
81
+ let b = N - 1;
82
+ let j = routes[current.id];
83
+ let type = routes[current.id + diffTypesPtrOffset];
84
+ while (true) {
85
+ if (!j && !type)
86
+ break;
87
+ const prev = j;
88
+ if (type === REMOVED) {
89
+ result.unshift({
90
+ type: swapped ? DiffType.removed : DiffType.added,
91
+ value: B[b],
92
+ });
93
+ b -= 1;
94
+ }
95
+ else if (type === ADDED) {
96
+ result.unshift({
97
+ type: swapped ? DiffType.added : DiffType.removed,
98
+ value: A[a],
99
+ });
100
+ a -= 1;
101
+ }
102
+ else {
103
+ result.unshift({ type: DiffType.common, value: A[a] });
104
+ a -= 1;
105
+ b -= 1;
106
+ }
107
+ j = routes[prev];
108
+ type = routes[prev + diffTypesPtrOffset];
109
+ }
110
+ return result;
111
+ }
112
+ function createFP(slide, down, k, M) {
113
+ if (slide && slide.y === -1 && down && down.y === -1) {
114
+ return { y: 0, id: 0 };
115
+ }
116
+ if ((down && down.y === -1) ||
117
+ k === M ||
118
+ (slide && slide.y) > (down && down.y) + 1) {
119
+ const prev = slide.id;
120
+ ptr++;
121
+ routes[ptr] = prev;
122
+ routes[ptr + diffTypesPtrOffset] = ADDED;
123
+ return { y: slide.y, id: ptr };
124
+ }
125
+ else {
126
+ const prev = down.id;
127
+ ptr++;
128
+ routes[ptr] = prev;
129
+ routes[ptr + diffTypesPtrOffset] = REMOVED;
130
+ return { y: down.y + 1, id: ptr };
131
+ }
132
+ }
133
+ function snake(k, slide, down, _offset, A, B) {
134
+ const M = A.length;
135
+ const N = B.length;
136
+ if (k < -N || M < k)
137
+ return { y: -1, id: -1 };
138
+ const fp = createFP(slide, down, k, M);
139
+ while (fp.y + k < M && fp.y < N && A[fp.y + k] === B[fp.y]) {
140
+ const prev = fp.id;
141
+ ptr++;
142
+ fp.id = ptr;
143
+ fp.y += 1;
144
+ routes[ptr] = prev;
145
+ routes[ptr + diffTypesPtrOffset] = COMMON;
146
+ }
147
+ return fp;
148
+ }
149
+ while (fp[delta + offset].y < N) {
150
+ p = p + 1;
151
+ for (let k = -p; k < delta; ++k) {
152
+ fp[k + offset] = snake(k, fp[k - 1 + offset], fp[k + 1 + offset], offset, A, B);
153
+ }
154
+ for (let k = delta + p; k > delta; --k) {
155
+ fp[k + offset] = snake(k, fp[k - 1 + offset], fp[k + 1 + offset], offset, A, B);
156
+ }
157
+ fp[delta + offset] = snake(delta, fp[delta - 1 + offset], fp[delta + 1 + offset], offset, A, B);
158
+ }
159
+ return [
160
+ ...prefixCommon.map((c) => ({ type: DiffType.common, value: c })),
161
+ ...backTrace(A, B, fp[delta + offset], swapped),
162
+ ...suffixCommon.map((c) => ({ type: DiffType.common, value: c })),
163
+ ];
164
+ }
165
+ exports.diff = diff;
166
+ /**
167
+ * Renders the differences between the actual and expected strings
168
+ * Partially inspired from https://github.com/kpdecker/jsdiff
169
+ * @param A Actual string
170
+ * @param B Expected string
171
+ */
172
+ function diffstr(A, B) {
173
+ function unescape(string) {
174
+ // unescape invisible characters.
175
+ // ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences
176
+ return string
177
+ .replaceAll("\b", "\\b")
178
+ .replaceAll("\f", "\\f")
179
+ .replaceAll("\t", "\\t")
180
+ .replaceAll("\v", "\\v")
181
+ .replaceAll(// does not remove line breaks
182
+ /\r\n|\r|\n/g, (str) => str === "\r" ? "\\r" : str === "\n" ? "\\n\n" : "\\r\\n\r\n");
183
+ }
184
+ function tokenize(string, { wordDiff = false } = {}) {
185
+ if (wordDiff) {
186
+ // Split string on whitespace symbols
187
+ const tokens = string.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/);
188
+ // Extended Latin character set
189
+ const words = /^[a-zA-Z\u{C0}-\u{FF}\u{D8}-\u{F6}\u{F8}-\u{2C6}\u{2C8}-\u{2D7}\u{2DE}-\u{2FF}\u{1E00}-\u{1EFF}]+$/u;
190
+ // Join boundary splits that we do not consider to be boundaries and merge empty strings surrounded by word chars
191
+ for (let i = 0; i < tokens.length - 1; i++) {
192
+ if (!tokens[i + 1] && tokens[i + 2] && words.test(tokens[i]) &&
193
+ words.test(tokens[i + 2])) {
194
+ tokens[i] += tokens[i + 2];
195
+ tokens.splice(i + 1, 2);
196
+ i--;
197
+ }
198
+ }
199
+ return tokens.filter((token) => token);
200
+ }
201
+ else {
202
+ // Split string on new lines symbols
203
+ const tokens = [], lines = string.split(/(\n|\r\n)/);
204
+ // Ignore final empty token when text ends with a newline
205
+ if (!lines[lines.length - 1]) {
206
+ lines.pop();
207
+ }
208
+ // Merge the content and line separators into single tokens
209
+ for (let i = 0; i < lines.length; i++) {
210
+ if (i % 2) {
211
+ tokens[tokens.length - 1] += lines[i];
212
+ }
213
+ else {
214
+ tokens.push(lines[i]);
215
+ }
216
+ }
217
+ return tokens;
218
+ }
219
+ }
220
+ // Create details by filtering relevant word-diff for current line
221
+ // and merge "space-diff" if surrounded by word-diff for cleaner displays
222
+ function createDetails(line, tokens) {
223
+ return tokens.filter(({ type }) => type === line.type || type === DiffType.common).map((result, i, t) => {
224
+ if ((result.type === DiffType.common) && (t[i - 1]) &&
225
+ (t[i - 1]?.type === t[i + 1]?.type) && /\s+/.test(result.value)) {
226
+ return {
227
+ ...result,
228
+ type: t[i - 1].type,
229
+ };
230
+ }
231
+ return result;
232
+ });
233
+ }
234
+ // Compute multi-line diff
235
+ const diffResult = diff(tokenize(`${unescape(A)}\n`), tokenize(`${unescape(B)}\n`));
236
+ const added = [], removed = [];
237
+ for (const result of diffResult) {
238
+ if (result.type === DiffType.added) {
239
+ added.push(result);
240
+ }
241
+ if (result.type === DiffType.removed) {
242
+ removed.push(result);
243
+ }
244
+ }
245
+ // Compute word-diff
246
+ const aLines = added.length < removed.length ? added : removed;
247
+ const bLines = aLines === removed ? added : removed;
248
+ for (const a of aLines) {
249
+ let tokens = [], b;
250
+ // Search another diff line with at least one common token
251
+ while (bLines.length) {
252
+ b = bLines.shift();
253
+ tokens = diff(tokenize(a.value, { wordDiff: true }), tokenize(b?.value ?? "", { wordDiff: true }));
254
+ if (tokens.some(({ type, value }) => type === DiffType.common && value.trim().length)) {
255
+ break;
256
+ }
257
+ }
258
+ // Register word-diff details
259
+ a.details = createDetails(a, tokens);
260
+ if (b) {
261
+ b.details = createDetails(b, tokens);
262
+ }
263
+ }
264
+ return diffResult;
265
+ }
266
+ exports.diffstr = diffstr;
267
+ /**
268
+ * Colors the output of assertion diffs
269
+ * @param diffType Difference type, either added or removed
270
+ */
271
+ function createColor(diffType, { background = false } = {}) {
272
+ // TODO(@littledivy): Remove this when we can detect
273
+ // true color terminals.
274
+ // https://github.com/denoland/deno_std/issues/2575
275
+ background = false;
276
+ switch (diffType) {
277
+ case DiffType.added:
278
+ return (s) => background ? (0, colors_js_1.bgGreen)((0, colors_js_1.white)(s)) : (0, colors_js_1.green)((0, colors_js_1.bold)(s));
279
+ case DiffType.removed:
280
+ return (s) => background ? (0, colors_js_1.bgRed)((0, colors_js_1.white)(s)) : (0, colors_js_1.red)((0, colors_js_1.bold)(s));
281
+ default:
282
+ return colors_js_1.white;
283
+ }
284
+ }
285
+ /**
286
+ * Prefixes `+` or `-` in diff output
287
+ * @param diffType Difference type, either added or removed
288
+ */
289
+ function createSign(diffType) {
290
+ switch (diffType) {
291
+ case DiffType.added:
292
+ return "+ ";
293
+ case DiffType.removed:
294
+ return "- ";
295
+ default:
296
+ return " ";
297
+ }
298
+ }
299
+ function buildMessage(diffResult, { stringDiff = false } = {}) {
300
+ const messages = [], diffMessages = [];
301
+ messages.push("");
302
+ messages.push("");
303
+ messages.push(` ${(0, colors_js_1.gray)((0, colors_js_1.bold)("[Diff]"))} ${(0, colors_js_1.red)((0, colors_js_1.bold)("Actual"))} / ${(0, colors_js_1.green)((0, colors_js_1.bold)("Expected"))}`);
304
+ messages.push("");
305
+ messages.push("");
306
+ diffResult.forEach((result) => {
307
+ const c = createColor(result.type);
308
+ const line = result.details?.map((detail) => detail.type !== DiffType.common
309
+ ? createColor(detail.type, { background: true })(detail.value)
310
+ : detail.value).join("") ?? result.value;
311
+ diffMessages.push(c(`${createSign(result.type)}${line}`));
312
+ });
313
+ messages.push(...(stringDiff ? [diffMessages.join("")] : diffMessages));
314
+ messages.push("");
315
+ return messages;
316
+ }
317
+ exports.buildMessage = buildMessage;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.format = void 0;
29
+ /**
30
+ * Converts the input into a string. Objects, Sets and Maps are sorted so as to
31
+ * make tests less flaky
32
+ * @param v Value to be formatted
33
+ */
34
+ const dntShim = __importStar(require("../../../../_dnt.shims.js"));
35
+ function format(v) {
36
+ // deno-lint-ignore no-explicit-any
37
+ const { Deno } = dntShim.dntGlobalThis;
38
+ return typeof Deno?.inspect === "function"
39
+ ? Deno.inspect(v, {
40
+ depth: Infinity,
41
+ sorted: true,
42
+ trailingComma: true,
43
+ compact: false,
44
+ iterableLimit: Infinity,
45
+ // getters should be true in assertEquals.
46
+ getters: true,
47
+ })
48
+ : `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
49
+ }
50
+ exports.format = format;