@mtkruto/node 0.0.971 → 0.0.972

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 (131) hide show
  1. package/esm/constants.d.ts +1 -1
  2. package/esm/constants.js +1 -1
  3. package/esm/deps/deno.land/std@0.196.0/assert/_constants.d.ts +1 -0
  4. package/esm/deps/deno.land/std@0.196.0/assert/_constants.js +2 -0
  5. package/esm/deps/deno.land/std@0.196.0/assert/assert.d.ts +2 -0
  6. package/esm/deps/deno.land/std@0.196.0/assert/assert.js +8 -0
  7. package/esm/deps/deno.land/std@0.196.0/assert/assert_almost_equals.d.ts +18 -0
  8. package/esm/deps/deno.land/std@0.196.0/assert/assert_almost_equals.js +32 -0
  9. package/esm/deps/deno.land/std@0.196.0/assert/assert_array_includes.d.ts +14 -0
  10. package/esm/deps/deno.land/std@0.196.0/assert/assert_array_includes.js +38 -0
  11. package/esm/deps/deno.land/std@0.196.0/assert/assert_equals.d.ts +17 -0
  12. package/esm/deps/deno.land/std@0.196.0/assert/assert_equals.js +45 -0
  13. package/esm/deps/deno.land/std@0.196.0/assert/assert_exists.d.ts +5 -0
  14. package/esm/deps/deno.land/std@0.196.0/assert/assert_exists.js +14 -0
  15. package/esm/deps/deno.land/std@0.196.0/assert/assert_false.d.ts +4 -0
  16. package/esm/deps/deno.land/std@0.196.0/assert/assert_false.js +7 -0
  17. package/esm/deps/deno.land/std@0.196.0/assert/assert_instance_of.d.ts +8 -0
  18. package/esm/deps/deno.land/std@0.196.0/assert/assert_instance_of.js +38 -0
  19. package/esm/deps/deno.land/std@0.196.0/assert/assert_is_error.d.ts +7 -0
  20. package/esm/deps/deno.land/std@0.196.0/assert/assert_is_error.js +26 -0
  21. package/esm/deps/deno.land/std@0.196.0/assert/assert_match.d.ts +5 -0
  22. package/esm/deps/deno.land/std@0.196.0/assert/assert_match.js +13 -0
  23. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_equals.d.ts +14 -0
  24. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_equals.js +37 -0
  25. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.d.ts +5 -0
  26. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.js +14 -0
  27. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_match.d.ts +5 -0
  28. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_match.js +14 -0
  29. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.d.ts +11 -0
  30. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.js +20 -0
  31. package/esm/deps/deno.land/std@0.196.0/assert/assert_object_match.d.ts +5 -0
  32. package/esm/deps/deno.land/std@0.196.0/assert/assert_object_match.js +78 -0
  33. package/esm/deps/deno.land/std@0.196.0/assert/assert_rejects.d.ts +64 -0
  34. package/esm/deps/deno.land/std@0.196.0/assert/assert_rejects.js +50 -0
  35. package/esm/deps/deno.land/std@0.196.0/assert/assert_strict_equals.d.ts +23 -0
  36. package/esm/deps/deno.land/std@0.196.0/assert/assert_strict_equals.js +60 -0
  37. package/esm/deps/deno.land/std@0.196.0/assert/assert_string_includes.d.ts +5 -0
  38. package/esm/deps/deno.land/std@0.196.0/assert/assert_string_includes.js +13 -0
  39. package/esm/deps/deno.land/std@0.196.0/assert/assert_throws.d.ts +54 -0
  40. package/esm/deps/deno.land/std@0.196.0/assert/assert_throws.js +44 -0
  41. package/esm/deps/deno.land/std@0.196.0/assert/assertion_error.d.ts +4 -0
  42. package/esm/deps/deno.land/std@0.196.0/assert/assertion_error.js +12 -0
  43. package/esm/deps/deno.land/std@0.196.0/assert/equal.d.ts +6 -0
  44. package/esm/deps/deno.land/std@0.196.0/assert/equal.js +102 -0
  45. package/esm/deps/deno.land/std@0.196.0/assert/fail.d.ts +4 -0
  46. package/esm/deps/deno.land/std@0.196.0/assert/fail.js +9 -0
  47. package/esm/deps/deno.land/std@0.196.0/assert/mod.d.ts +32 -0
  48. package/esm/deps/deno.land/std@0.196.0/assert/mod.js +33 -0
  49. package/esm/deps/deno.land/std@0.196.0/assert/unimplemented.d.ts +2 -0
  50. package/esm/deps/deno.land/std@0.196.0/assert/unimplemented.js +7 -0
  51. package/esm/deps/deno.land/std@0.196.0/assert/unreachable.d.ts +2 -0
  52. package/esm/deps/deno.land/std@0.196.0/assert/unreachable.js +6 -0
  53. package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.js +2 -2
  54. package/{script/deps/deno.land/std@0.190.0 → esm/deps/deno.land/std@0.196.0}/testing/asserts.d.ts +204 -159
  55. package/esm/deps/deno.land/std@0.196.0/testing/asserts.js +330 -0
  56. package/esm/deps.d.ts +2 -2
  57. package/esm/deps.js +2 -2
  58. package/package.json +1 -1
  59. package/script/constants.d.ts +1 -1
  60. package/script/constants.js +1 -1
  61. package/script/deps/deno.land/std@0.196.0/assert/_constants.d.ts +1 -0
  62. package/script/deps/deno.land/std@0.196.0/assert/_constants.js +5 -0
  63. package/script/deps/deno.land/std@0.196.0/assert/assert.d.ts +2 -0
  64. package/script/deps/deno.land/std@0.196.0/assert/assert.js +12 -0
  65. package/script/deps/deno.land/std@0.196.0/assert/assert_almost_equals.d.ts +18 -0
  66. package/script/deps/deno.land/std@0.196.0/assert/assert_almost_equals.js +36 -0
  67. package/script/deps/deno.land/std@0.196.0/assert/assert_array_includes.d.ts +14 -0
  68. package/script/deps/deno.land/std@0.196.0/assert/assert_array_includes.js +42 -0
  69. package/script/deps/deno.land/std@0.196.0/assert/assert_equals.d.ts +17 -0
  70. package/script/deps/deno.land/std@0.196.0/assert/assert_equals.js +49 -0
  71. package/script/deps/deno.land/std@0.196.0/assert/assert_exists.d.ts +5 -0
  72. package/script/deps/deno.land/std@0.196.0/assert/assert_exists.js +18 -0
  73. package/script/deps/deno.land/std@0.196.0/assert/assert_false.d.ts +4 -0
  74. package/script/deps/deno.land/std@0.196.0/assert/assert_false.js +11 -0
  75. package/script/deps/deno.land/std@0.196.0/assert/assert_instance_of.d.ts +8 -0
  76. package/script/deps/deno.land/std@0.196.0/assert/assert_instance_of.js +42 -0
  77. package/script/deps/deno.land/std@0.196.0/assert/assert_is_error.d.ts +7 -0
  78. package/script/deps/deno.land/std@0.196.0/assert/assert_is_error.js +30 -0
  79. package/script/deps/deno.land/std@0.196.0/assert/assert_match.d.ts +5 -0
  80. package/script/deps/deno.land/std@0.196.0/assert/assert_match.js +17 -0
  81. package/script/deps/deno.land/std@0.196.0/assert/assert_not_equals.d.ts +14 -0
  82. package/script/deps/deno.land/std@0.196.0/assert/assert_not_equals.js +41 -0
  83. package/script/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.d.ts +5 -0
  84. package/script/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.js +18 -0
  85. package/script/deps/deno.land/std@0.196.0/assert/assert_not_match.d.ts +5 -0
  86. package/script/deps/deno.land/std@0.196.0/assert/assert_not_match.js +18 -0
  87. package/script/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.d.ts +11 -0
  88. package/script/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.js +24 -0
  89. package/script/deps/deno.land/std@0.196.0/assert/assert_object_match.d.ts +5 -0
  90. package/script/deps/deno.land/std@0.196.0/assert/assert_object_match.js +82 -0
  91. package/script/deps/deno.land/std@0.196.0/assert/assert_rejects.d.ts +64 -0
  92. package/script/deps/deno.land/std@0.196.0/assert/assert_rejects.js +54 -0
  93. package/script/deps/deno.land/std@0.196.0/assert/assert_strict_equals.d.ts +23 -0
  94. package/script/deps/deno.land/std@0.196.0/assert/assert_strict_equals.js +64 -0
  95. package/script/deps/deno.land/std@0.196.0/assert/assert_string_includes.d.ts +5 -0
  96. package/script/deps/deno.land/std@0.196.0/assert/assert_string_includes.js +17 -0
  97. package/script/deps/deno.land/std@0.196.0/assert/assert_throws.d.ts +54 -0
  98. package/script/deps/deno.land/std@0.196.0/assert/assert_throws.js +48 -0
  99. package/script/deps/deno.land/std@0.196.0/assert/assertion_error.d.ts +4 -0
  100. package/script/deps/deno.land/std@0.196.0/assert/assertion_error.js +16 -0
  101. package/script/deps/deno.land/std@0.196.0/assert/equal.d.ts +6 -0
  102. package/script/deps/deno.land/std@0.196.0/assert/equal.js +106 -0
  103. package/script/deps/deno.land/std@0.196.0/assert/fail.d.ts +4 -0
  104. package/script/deps/deno.land/std@0.196.0/assert/fail.js +13 -0
  105. package/script/deps/deno.land/std@0.196.0/assert/mod.d.ts +32 -0
  106. package/script/deps/deno.land/std@0.196.0/assert/mod.js +49 -0
  107. package/script/deps/deno.land/std@0.196.0/assert/unimplemented.d.ts +2 -0
  108. package/script/deps/deno.land/std@0.196.0/assert/unimplemented.js +11 -0
  109. package/script/deps/deno.land/std@0.196.0/assert/unreachable.d.ts +2 -0
  110. package/script/deps/deno.land/std@0.196.0/assert/unreachable.js +10 -0
  111. package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.js +2 -2
  112. package/{esm/deps/deno.land/std@0.190.0 → script/deps/deno.land/std@0.196.0}/testing/asserts.d.ts +204 -159
  113. package/script/deps/deno.land/std@0.196.0/testing/asserts.js +333 -0
  114. package/script/deps.d.ts +2 -2
  115. package/script/deps.js +2 -2
  116. package/esm/deps/deno.land/std@0.190.0/testing/asserts.js +0 -633
  117. package/script/deps/deno.land/std@0.190.0/testing/asserts.js +0 -659
  118. /package/esm/deps/deno.land/{std@0.190.0/testing/_diff.d.ts → std@0.196.0/_util/diff.d.ts} +0 -0
  119. /package/esm/deps/deno.land/{std@0.190.0/testing/_diff.js → std@0.196.0/_util/diff.js} +0 -0
  120. /package/esm/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.d.ts +0 -0
  121. /package/esm/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.js +0 -0
  122. /package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.d.ts +0 -0
  123. /package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.js +0 -0
  124. /package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.d.ts +0 -0
  125. /package/script/deps/deno.land/{std@0.190.0/testing/_diff.d.ts → std@0.196.0/_util/diff.d.ts} +0 -0
  126. /package/script/deps/deno.land/{std@0.190.0/testing/_diff.js → std@0.196.0/_util/diff.js} +0 -0
  127. /package/script/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.d.ts +0 -0
  128. /package/script/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.js +0 -0
  129. /package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.d.ts +0 -0
  130. /package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.js +0 -0
  131. /package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.d.ts +0 -0
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 160;
8
- export declare const APP_VERSION = "MTKruto 0.0.971";
8
+ export declare const APP_VERSION = "MTKruto 0.0.972";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 160;
57
- export const APP_VERSION = "MTKruto 0.0.971";
57
+ export const APP_VERSION = "MTKruto 0.0.972";
58
58
  // @ts-ignore: lib
59
59
  export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -0,0 +1 @@
1
+ export declare const CAN_NOT_DISPLAY = "[Cannot display]";
@@ -0,0 +1,2 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ export const CAN_NOT_DISPLAY = "[Cannot display]";
@@ -0,0 +1,2 @@
1
+ /** Make an assertion, error will be thrown if `expr` does not have truthy value. */
2
+ export declare function assert(expr: unknown, msg?: string): asserts expr;
@@ -0,0 +1,8 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /** Make an assertion, error will be thrown if `expr` does not have truthy value. */
4
+ export function assert(expr, msg = "") {
5
+ if (!expr) {
6
+ throw new AssertionError(msg);
7
+ }
8
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are almost equal numbers through
3
+ * a given tolerance. It can be used to take into account IEEE-754 double-precision
4
+ * floating-point representation limitations.
5
+ * If the values are not almost equal then throw.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
10
+ *
11
+ * assertAlmostEquals(0.1, 0.2);
12
+ *
13
+ * // Using a custom tolerance value
14
+ * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
15
+ * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));
16
+ * ```
17
+ */
18
+ export declare function assertAlmostEquals(actual: number, expected: number, tolerance?: number, msg?: string): void;
@@ -0,0 +1,32 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `actual` and `expected` are almost equal numbers through
5
+ * a given tolerance. It can be used to take into account IEEE-754 double-precision
6
+ * floating-point representation limitations.
7
+ * If the values are not almost equal then throw.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
12
+ *
13
+ * assertAlmostEquals(0.1, 0.2);
14
+ *
15
+ * // Using a custom tolerance value
16
+ * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
17
+ * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));
18
+ * ```
19
+ */
20
+ export function assertAlmostEquals(actual, expected, tolerance = 1e-7, msg) {
21
+ if (Object.is(actual, expected)) {
22
+ return;
23
+ }
24
+ const delta = Math.abs(expected - actual);
25
+ if (delta <= tolerance) {
26
+ return;
27
+ }
28
+ const msgSuffix = msg ? `: ${msg}` : ".";
29
+ const f = (n) => Number.isInteger(n) ? n : n.toExponential();
30
+ throw new AssertionError(`Expected actual: "${f(actual)}" to be close to "${f(expected)}": \
31
+ delta "${f(delta)}" is greater than "${f(tolerance)}"${msgSuffix}`);
32
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Make an assertion that `actual` includes the `expected` values.
3
+ * If not then an error will be thrown.
4
+ *
5
+ * Type parameter can be specified to ensure values under comparison have the same type.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/assert/assert_array_includes.ts";
10
+ *
11
+ * assertArrayIncludes<number>([1, 2], [2])
12
+ * ```
13
+ */
14
+ export declare function assertArrayIncludes<T>(actual: ArrayLike<T>, expected: ArrayLike<T>, msg?: string): void;
@@ -0,0 +1,38 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { equal } from "./equal.js";
3
+ import { format } from "./_format.js";
4
+ import { AssertionError } from "./assertion_error.js";
5
+ /**
6
+ * Make an assertion that `actual` includes the `expected` values.
7
+ * If not then an error will be thrown.
8
+ *
9
+ * Type parameter can be specified to ensure values under comparison have the same type.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/assert/assert_array_includes.ts";
14
+ *
15
+ * assertArrayIncludes<number>([1, 2], [2])
16
+ * ```
17
+ */
18
+ export function assertArrayIncludes(actual, expected, msg) {
19
+ const missing = [];
20
+ for (let i = 0; i < expected.length; i++) {
21
+ let found = false;
22
+ for (let j = 0; j < actual.length; j++) {
23
+ if (equal(expected[i], actual[j])) {
24
+ found = true;
25
+ break;
26
+ }
27
+ }
28
+ if (!found) {
29
+ missing.push(expected[i]);
30
+ }
31
+ }
32
+ if (missing.length === 0) {
33
+ return;
34
+ }
35
+ const msgSuffix = msg ? `: ${msg}` : ".";
36
+ msg = `Expected actual: "${format(actual)}" to include: "${format(expected)}"${msgSuffix}\nmissing: ${format(missing)}`;
37
+ throw new AssertionError(msg);
38
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are equal, deeply. If not
3
+ * deeply equal, then throw.
4
+ *
5
+ * Type parameter can be specified to ensure values under comparison have the same type.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts";
10
+ *
11
+ * Deno.test("example", function (): void {
12
+ * assertEquals("world", "world");
13
+ * assertEquals({ hello: "world" }, { hello: "world" });
14
+ * });
15
+ * ```
16
+ */
17
+ export declare function assertEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,45 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { equal } from "./equal.js";
3
+ import { format } from "./_format.js";
4
+ import { AssertionError } from "./assertion_error.js";
5
+ import { red } from "../fmt/colors.js";
6
+ import { buildMessage, diff, diffstr } from "../_util/diff.js";
7
+ import { CAN_NOT_DISPLAY } from "./_constants.js";
8
+ /**
9
+ * Make an assertion that `actual` and `expected` are equal, deeply. If not
10
+ * deeply equal, then throw.
11
+ *
12
+ * Type parameter can be specified to ensure values under comparison have the same type.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts";
17
+ *
18
+ * Deno.test("example", function (): void {
19
+ * assertEquals("world", "world");
20
+ * assertEquals({ hello: "world" }, { hello: "world" });
21
+ * });
22
+ * ```
23
+ */
24
+ export function assertEquals(actual, expected, msg) {
25
+ if (equal(actual, expected)) {
26
+ return;
27
+ }
28
+ const msgSuffix = msg ? `: ${msg}` : ".";
29
+ let message = `Values are not equal${msgSuffix}`;
30
+ const actualString = format(actual);
31
+ const expectedString = format(expected);
32
+ try {
33
+ const stringDiff = (typeof actual === "string") &&
34
+ (typeof expected === "string");
35
+ const diffResult = stringDiff
36
+ ? diffstr(actual, expected)
37
+ : diff(actualString.split("\n"), expectedString.split("\n"));
38
+ const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
39
+ message = `${message}\n${diffMsg}`;
40
+ }
41
+ catch {
42
+ message = `${message}\n${red(CAN_NOT_DISPLAY)} + \n\n`;
43
+ }
44
+ throw new AssertionError(message);
45
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that actual is not null or undefined.
3
+ * If not then throw.
4
+ */
5
+ export declare function assertExists<T>(actual: T, msg?: string): asserts actual is NonNullable<T>;
@@ -0,0 +1,14 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that actual is not null or undefined.
5
+ * If not then throw.
6
+ */
7
+ export function assertExists(actual, msg) {
8
+ if (actual === undefined || actual === null) {
9
+ const msgSuffix = msg ? `: ${msg}` : ".";
10
+ msg =
11
+ `Expected actual: "${actual}" to not be null or undefined${msgSuffix}`;
12
+ throw new AssertionError(msg);
13
+ }
14
+ }
@@ -0,0 +1,4 @@
1
+ /** Make an assertion, error will be thrown if `expr` have truthy value. */
2
+ type Falsy = false | 0 | 0n | "" | null | undefined;
3
+ export declare function assertFalse(expr: unknown, msg?: string): asserts expr is Falsy;
4
+ export {};
@@ -0,0 +1,7 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ export function assertFalse(expr, msg = "") {
4
+ if (expr) {
5
+ throw new AssertionError(msg);
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ type AnyConstructor = new (...args: any[]) => any;
2
+ type GetConstructorType<T extends AnyConstructor> = T extends new (...args: any) => infer C ? C : never;
3
+ /**
4
+ * Make an assertion that `obj` is an instance of `type`.
5
+ * If not then throw.
6
+ */
7
+ export declare function assertInstanceOf<T extends AnyConstructor>(actual: unknown, expectedType: T, msg?: string): asserts actual is GetConstructorType<T>;
8
+ export {};
@@ -0,0 +1,38 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `obj` is an instance of `type`.
5
+ * If not then throw.
6
+ */
7
+ export function assertInstanceOf(actual, expectedType, msg = "") {
8
+ if (actual instanceof expectedType)
9
+ return;
10
+ const msgSuffix = msg ? `: ${msg}` : ".";
11
+ const expectedTypeStr = expectedType.name;
12
+ let actualTypeStr = "";
13
+ if (actual === null) {
14
+ actualTypeStr = "null";
15
+ }
16
+ else if (actual === undefined) {
17
+ actualTypeStr = "undefined";
18
+ }
19
+ else if (typeof actual === "object") {
20
+ actualTypeStr = actual.constructor?.name ?? "Object";
21
+ }
22
+ else {
23
+ actualTypeStr = typeof actual;
24
+ }
25
+ if (expectedTypeStr == actualTypeStr) {
26
+ msg =
27
+ `Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`;
28
+ }
29
+ else if (actualTypeStr == "function") {
30
+ msg =
31
+ `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`;
32
+ }
33
+ else {
34
+ msg =
35
+ `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}"${msgSuffix}`;
36
+ }
37
+ throw new AssertionError(msg);
38
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Make an assertion that `error` is an `Error`.
3
+ * If not then an error will be thrown.
4
+ * An error class and a string that should be included in the
5
+ * error message can also be asserted.
6
+ */
7
+ export declare function assertIsError<E extends Error = Error>(error: unknown, ErrorClass?: new (...args: any[]) => E, msgIncludes?: string, msg?: string): asserts error is E;
@@ -0,0 +1,26 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ import { stripColor } from "../fmt/colors.js";
4
+ /**
5
+ * Make an assertion that `error` is an `Error`.
6
+ * If not then an error will be thrown.
7
+ * An error class and a string that should be included in the
8
+ * error message can also be asserted.
9
+ */
10
+ export function assertIsError(error,
11
+ // deno-lint-ignore no-explicit-any
12
+ ErrorClass, msgIncludes, msg) {
13
+ const msgSuffix = msg ? `: ${msg}` : ".";
14
+ if (error instanceof Error === false) {
15
+ throw new AssertionError(`Expected "error" to be an Error object${msgSuffix}}`);
16
+ }
17
+ if (ErrorClass && !(error instanceof ErrorClass)) {
18
+ msg = `Expected error to be instance of "${ErrorClass.name}", but was "${typeof error === "object" ? error?.constructor?.name : "[not an object]"}"${msgSuffix}`;
19
+ throw new AssertionError(msg);
20
+ }
21
+ if (msgIncludes && (!(error instanceof Error) ||
22
+ !stripColor(error.message).includes(stripColor(msgIncludes)))) {
23
+ msg = `Expected error message to include "${msgIncludes}", but got "${error instanceof Error ? error.message : "[not an Error]"}"${msgSuffix}`;
24
+ throw new AssertionError(msg);
25
+ }
26
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `actual` match RegExp `expected`. If not
3
+ * then throw.
4
+ */
5
+ export declare function assertMatch(actual: string, expected: RegExp, msg?: string): void;
@@ -0,0 +1,13 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `actual` match RegExp `expected`. If not
5
+ * then throw.
6
+ */
7
+ export function assertMatch(actual, expected, msg) {
8
+ if (!expected.test(actual)) {
9
+ const msgSuffix = msg ? `: ${msg}` : ".";
10
+ msg = `Expected actual: "${actual}" to match: "${expected}"${msgSuffix}`;
11
+ throw new AssertionError(msg);
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
3
+ * If not then throw.
4
+ *
5
+ * Type parameter can be specified to ensure values under comparison have the same type.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_equals.ts";
10
+ *
11
+ * assertNotEquals<number>(1, 2)
12
+ * ```
13
+ */
14
+ export declare function assertNotEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,37 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { equal } from "./equal.js";
3
+ import { AssertionError } from "./assertion_error.js";
4
+ /**
5
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
6
+ * If not then throw.
7
+ *
8
+ * Type parameter can be specified to ensure values under comparison have the same type.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_equals.ts";
13
+ *
14
+ * assertNotEquals<number>(1, 2)
15
+ * ```
16
+ */
17
+ export function assertNotEquals(actual, expected, msg) {
18
+ if (!equal(actual, expected)) {
19
+ return;
20
+ }
21
+ let actualString;
22
+ let expectedString;
23
+ try {
24
+ actualString = String(actual);
25
+ }
26
+ catch {
27
+ actualString = "[Cannot display]";
28
+ }
29
+ try {
30
+ expectedString = String(expected);
31
+ }
32
+ catch {
33
+ expectedString = "[Cannot display]";
34
+ }
35
+ const msgSuffix = msg ? `: ${msg}` : ".";
36
+ throw new AssertionError(`Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`);
37
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `obj` is not an instance of `type`.
3
+ * If so, then throw.
4
+ */
5
+ export declare function assertNotInstanceOf<A, T>(actual: A, unexpectedType: new (...args: any[]) => T, msg?: string): asserts actual is Exclude<A, T>;
@@ -0,0 +1,14 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { assertFalse } from "./assert_false.js";
3
+ /**
4
+ * Make an assertion that `obj` is not an instance of `type`.
5
+ * If so, then throw.
6
+ */
7
+ export function assertNotInstanceOf(actual,
8
+ // deno-lint-ignore no-explicit-any
9
+ unexpectedType, msg) {
10
+ const msgSuffix = msg ? `: ${msg}` : ".";
11
+ msg =
12
+ `Expected object to not be an instance of "${typeof unexpectedType}"${msgSuffix}`;
13
+ assertFalse(actual instanceof unexpectedType, msg);
14
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `actual` not match RegExp `expected`. If match
3
+ * then throw.
4
+ */
5
+ export declare function assertNotMatch(actual: string, expected: RegExp, msg?: string): void;
@@ -0,0 +1,14 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `actual` not match RegExp `expected`. If match
5
+ * then throw.
6
+ */
7
+ export function assertNotMatch(actual, expected, msg) {
8
+ if (expected.test(actual)) {
9
+ const msgSuffix = msg ? `: ${msg}` : ".";
10
+ msg =
11
+ `Expected actual: "${actual}" to not match: "${expected}"${msgSuffix}`;
12
+ throw new AssertionError(msg);
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are not strictly equal.
3
+ * If the values are strictly equal then throw.
4
+ *
5
+ * ```ts
6
+ * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_strict_equals.ts";
7
+ *
8
+ * assertNotStrictEquals(1, 1)
9
+ * ```
10
+ */
11
+ export declare function assertNotStrictEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,20 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ import { format } from "./_format.js";
4
+ /**
5
+ * Make an assertion that `actual` and `expected` are not strictly equal.
6
+ * If the values are strictly equal then throw.
7
+ *
8
+ * ```ts
9
+ * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_strict_equals.ts";
10
+ *
11
+ * assertNotStrictEquals(1, 1)
12
+ * ```
13
+ */
14
+ export function assertNotStrictEquals(actual, expected, msg) {
15
+ if (!Object.is(actual, expected)) {
16
+ return;
17
+ }
18
+ const msgSuffix = msg ? `: ${msg}` : ".";
19
+ throw new AssertionError(`Expected "actual" to be strictly unequal to: ${format(actual)}${msgSuffix}\n`);
20
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `actual` object is a subset of `expected` object, deeply.
3
+ * If not, then throw.
4
+ */
5
+ export declare function assertObjectMatch(actual: Record<PropertyKey, any>, expected: Record<PropertyKey, unknown>, msg?: string): void;
@@ -0,0 +1,78 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { assertEquals } from "./assert_equals.js";
3
+ /**
4
+ * Make an assertion that `actual` object is a subset of `expected` object, deeply.
5
+ * If not, then throw.
6
+ */
7
+ export function assertObjectMatch(
8
+ // deno-lint-ignore no-explicit-any
9
+ actual, expected, msg) {
10
+ function filter(a, b) {
11
+ const seen = new WeakMap();
12
+ return fn(a, b);
13
+ function fn(a, b) {
14
+ // Prevent infinite loop with circular references with same filter
15
+ if ((seen.has(a)) && (seen.get(a) === b)) {
16
+ return a;
17
+ }
18
+ try {
19
+ seen.set(a, b);
20
+ }
21
+ catch (err) {
22
+ if (err instanceof TypeError) {
23
+ throw new TypeError(`Cannot assertObjectMatch ${a === null ? null : `type ${typeof a}`}`);
24
+ }
25
+ else
26
+ throw err;
27
+ }
28
+ // Filter keys and symbols which are present in both actual and expected
29
+ const filtered = {};
30
+ const entries = [
31
+ ...Object.getOwnPropertyNames(a),
32
+ ...Object.getOwnPropertySymbols(a),
33
+ ]
34
+ .filter((key) => key in b)
35
+ .map((key) => [key, a[key]]);
36
+ for (const [key, value] of entries) {
37
+ // On array references, build a filtered array and filter nested objects inside
38
+ if (Array.isArray(value)) {
39
+ const subset = b[key];
40
+ if (Array.isArray(subset)) {
41
+ filtered[key] = fn({ ...value }, { ...subset });
42
+ continue;
43
+ }
44
+ } // On regexp references, keep value as it to avoid loosing pattern and flags
45
+ else if (value instanceof RegExp) {
46
+ filtered[key] = value;
47
+ continue;
48
+ } // On nested objects references, build a filtered object recursively
49
+ else if (typeof value === "object" && value !== null) {
50
+ const subset = b[key];
51
+ if ((typeof subset === "object") && (subset)) {
52
+ // When both operands are maps, build a filtered map with common keys and filter nested objects inside
53
+ if ((value instanceof Map) && (subset instanceof Map)) {
54
+ filtered[key] = new Map([...value].filter(([k]) => subset.has(k)).map(([k, v]) => [k, typeof v === "object" ? fn(v, subset.get(k)) : v]));
55
+ continue;
56
+ }
57
+ // When both operands are set, build a filtered set with common values
58
+ if ((value instanceof Set) && (subset instanceof Set)) {
59
+ filtered[key] = new Set([...value].filter((v) => subset.has(v)));
60
+ continue;
61
+ }
62
+ filtered[key] = fn(value, subset);
63
+ continue;
64
+ }
65
+ }
66
+ filtered[key] = value;
67
+ }
68
+ return filtered;
69
+ }
70
+ }
71
+ return assertEquals(
72
+ // get the intersection of "actual" and "expected"
73
+ // side effect: all the instances' constructor field is "Object" now.
74
+ filter(actual, expected),
75
+ // set (nested) instances' constructor field to be "Object" without changing expected value.
76
+ // see https://github.com/denoland/deno_std/pull/1419
77
+ filter(expected, expected), msg);
78
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Executes a function which returns a promise, expecting it to reject.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { assertRejects } from "https://deno.land/std@$STD_VERSION/assert/assert_rejects.ts";
7
+ *
8
+ * Deno.test("doesThrow", async function () {
9
+ * await assertRejects(
10
+ * async () => {
11
+ * throw new TypeError("hello world!");
12
+ * },
13
+ * );
14
+ * await assertRejects(
15
+ * async () => {
16
+ * return Promise.reject(new Error());
17
+ * },
18
+ * );
19
+ * });
20
+ *
21
+ * // This test will not pass.
22
+ * Deno.test("fails", async function () {
23
+ * await assertRejects(
24
+ * async () => {
25
+ * console.log("Hello world");
26
+ * },
27
+ * );
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function assertRejects(fn: () => PromiseLike<unknown>, msg?: string): Promise<unknown>;
32
+ /**
33
+ * Executes a function which returns a promise, expecting it to reject.
34
+ * If it does not, then it throws. An error class and a string that should be
35
+ * included in the error message can also be asserted.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { assertRejects } from "https://deno.land/std@$STD_VERSION/assert/assert_rejects.ts";
40
+ *
41
+ * Deno.test("doesThrow", async function () {
42
+ * await assertRejects(async () => {
43
+ * throw new TypeError("hello world!");
44
+ * }, TypeError);
45
+ * await assertRejects(
46
+ * async () => {
47
+ * throw new TypeError("hello world!");
48
+ * },
49
+ * TypeError,
50
+ * "hello",
51
+ * );
52
+ * });
53
+ *
54
+ * // This test will not pass.
55
+ * Deno.test("fails", async function () {
56
+ * await assertRejects(
57
+ * async () => {
58
+ * console.log("Hello world");
59
+ * },
60
+ * );
61
+ * });
62
+ * ```
63
+ */
64
+ export declare function assertRejects<E extends Error = Error>(fn: () => PromiseLike<unknown>, ErrorClass: new (...args: any[]) => E, msgIncludes?: string, msg?: string): Promise<E>;