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