@casual-simulation/expect 2.0.18

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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -0
  3. package/index.d.ts +6 -0
  4. package/index.js +5 -0
  5. package/index.js.map +1 -0
  6. package/package.json +35 -0
  7. package/src/asymmetricMatchers.d.ts +67 -0
  8. package/src/asymmetricMatchers.js +188 -0
  9. package/src/asymmetricMatchers.js.map +1 -0
  10. package/src/diff/cleanupSemantic.d.ts +58 -0
  11. package/src/diff/cleanupSemantic.js +526 -0
  12. package/src/diff/cleanupSemantic.js.map +1 -0
  13. package/src/diff/constants.d.ts +9 -0
  14. package/src/diff/constants.js +10 -0
  15. package/src/diff/constants.js.map +1 -0
  16. package/src/diff/diffLines.d.ts +13 -0
  17. package/src/diff/diffLines.js +138 -0
  18. package/src/diff/diffLines.js.map +1 -0
  19. package/src/diff/diffStrings.d.ts +10 -0
  20. package/src/diff/diffStrings.js +36 -0
  21. package/src/diff/diffStrings.js.map +1 -0
  22. package/src/diff/getAlignedDiffs.d.ts +11 -0
  23. package/src/diff/getAlignedDiffs.js +187 -0
  24. package/src/diff/getAlignedDiffs.js.map +1 -0
  25. package/src/diff/index.d.ts +16 -0
  26. package/src/diff/index.js +139 -0
  27. package/src/diff/index.js.map +1 -0
  28. package/src/diff/joinAlignedDiffs.d.ts +11 -0
  29. package/src/diff/joinAlignedDiffs.js +191 -0
  30. package/src/diff/joinAlignedDiffs.js.map +1 -0
  31. package/src/diff/normalizeDiffOptions.d.ts +10 -0
  32. package/src/diff/normalizeDiffOptions.js +40 -0
  33. package/src/diff/normalizeDiffOptions.js.map +1 -0
  34. package/src/diff/printDiffs.d.ts +11 -0
  35. package/src/diff/printDiffs.js +46 -0
  36. package/src/diff/printDiffs.js.map +1 -0
  37. package/src/diff/types.d.ts +49 -0
  38. package/src/diff/types.js +2 -0
  39. package/src/diff/types.js.map +1 -0
  40. package/src/diff-sequences/index.d.ts +19 -0
  41. package/src/diff-sequences/index.js +506 -0
  42. package/src/diff-sequences/index.js.map +1 -0
  43. package/src/extractExpectedAssertionsErrors.d.ts +11 -0
  44. package/src/extractExpectedAssertionsErrors.js +58 -0
  45. package/src/extractExpectedAssertionsErrors.js.map +1 -0
  46. package/src/get-type/index.d.ts +11 -0
  47. package/src/get-type/index.js +57 -0
  48. package/src/get-type/index.js.map +1 -0
  49. package/src/index.d.ts +16 -0
  50. package/src/index.js +247 -0
  51. package/src/index.js.map +1 -0
  52. package/src/jasmineUtils.d.ts +9 -0
  53. package/src/jasmineUtils.js +218 -0
  54. package/src/jasmineUtils.js.map +1 -0
  55. package/src/jestMatchersObject.d.ts +14 -0
  56. package/src/jestMatchersObject.js +78 -0
  57. package/src/jestMatchersObject.js.map +1 -0
  58. package/src/matcher-utils/Replaceable.d.ts +18 -0
  59. package/src/matcher-utils/Replaceable.js +57 -0
  60. package/src/matcher-utils/Replaceable.js.map +1 -0
  61. package/src/matcher-utils/deepCyclicCopyReplaceable.d.ts +8 -0
  62. package/src/matcher-utils/deepCyclicCopyReplaceable.js +96 -0
  63. package/src/matcher-utils/deepCyclicCopyReplaceable.js.map +1 -0
  64. package/src/matcher-utils/index.d.ts +53 -0
  65. package/src/matcher-utils/index.js +341 -0
  66. package/src/matcher-utils/index.js.map +1 -0
  67. package/src/matchers.d.ts +11 -0
  68. package/src/matchers.js +575 -0
  69. package/src/matchers.js.map +1 -0
  70. package/src/message-util/index.d.ts +11 -0
  71. package/src/message-util/index.js +34 -0
  72. package/src/message-util/index.js.map +1 -0
  73. package/src/pretty-format/collections.d.ts +33 -0
  74. package/src/pretty-format/collections.js +130 -0
  75. package/src/pretty-format/collections.js.map +1 -0
  76. package/src/pretty-format/index.d.ts +25 -0
  77. package/src/pretty-format/index.js +390 -0
  78. package/src/pretty-format/index.js.map +1 -0
  79. package/src/pretty-format/plugins/AsymmetricMatcher.d.ts +12 -0
  80. package/src/pretty-format/plugins/AsymmetricMatcher.js +53 -0
  81. package/src/pretty-format/plugins/AsymmetricMatcher.js.map +1 -0
  82. package/src/pretty-format/plugins/ConvertAnsi.d.ts +12 -0
  83. package/src/pretty-format/plugins/ConvertAnsi.js +58 -0
  84. package/src/pretty-format/plugins/ConvertAnsi.js.map +1 -0
  85. package/src/pretty-format/plugins/DOMCollection.d.ts +12 -0
  86. package/src/pretty-format/plugins/DOMCollection.js +39 -0
  87. package/src/pretty-format/plugins/DOMCollection.js.map +1 -0
  88. package/src/pretty-format/plugins/DOMElement.d.ts +12 -0
  89. package/src/pretty-format/plugins/DOMElement.js +68 -0
  90. package/src/pretty-format/plugins/DOMElement.js.map +1 -0
  91. package/src/pretty-format/plugins/Immutable.d.ts +12 -0
  92. package/src/pretty-format/plugins/Immutable.js +113 -0
  93. package/src/pretty-format/plugins/Immutable.js.map +1 -0
  94. package/src/pretty-format/plugins/ReactTestComponent.d.ts +19 -0
  95. package/src/pretty-format/plugins/ReactTestComponent.js +29 -0
  96. package/src/pretty-format/plugins/ReactTestComponent.js.map +1 -0
  97. package/src/pretty-format/plugins/lib/escapeHTML.d.ts +8 -0
  98. package/src/pretty-format/plugins/lib/escapeHTML.js +10 -0
  99. package/src/pretty-format/plugins/lib/escapeHTML.js.map +1 -0
  100. package/src/pretty-format/plugins/lib/markup.d.ts +14 -0
  101. package/src/pretty-format/plugins/lib/markup.js +98 -0
  102. package/src/pretty-format/plugins/lib/markup.js.map +1 -0
  103. package/src/pretty-format/types.d.ts +109 -0
  104. package/src/pretty-format/types.js +8 -0
  105. package/src/pretty-format/types.js.map +1 -0
  106. package/src/print.d.ts +16 -0
  107. package/src/print.js +71 -0
  108. package/src/print.js.map +1 -0
  109. package/src/spyMatchers.d.ts +10 -0
  110. package/src/spyMatchers.js +766 -0
  111. package/src/spyMatchers.js.map +1 -0
  112. package/src/test-utils/ConditionalTest.d.ts +10 -0
  113. package/src/test-utils/ConditionalTest.js +25 -0
  114. package/src/test-utils/ConditionalTest.js.map +1 -0
  115. package/src/test-utils/alignedAnsiStyleSerializer.d.ts +9 -0
  116. package/src/test-utils/alignedAnsiStyleSerializer.js +46 -0
  117. package/src/test-utils/alignedAnsiStyleSerializer.js.map +1 -0
  118. package/src/test-utils/config.d.ts +10 -0
  119. package/src/test-utils/config.js +143 -0
  120. package/src/test-utils/config.js.map +1 -0
  121. package/src/test-utils/index.d.ts +10 -0
  122. package/src/test-utils/index.js +10 -0
  123. package/src/test-utils/index.js.map +1 -0
  124. package/src/toThrowMatchers.d.ts +12 -0
  125. package/src/toThrowMatchers.js +258 -0
  126. package/src/toThrowMatchers.js.map +1 -0
  127. package/src/types.d.ts +327 -0
  128. package/src/types.js +9 -0
  129. package/src/types.js.map +1 -0
  130. package/src/utils.d.ts +26 -0
  131. package/src/utils.js +303 -0
  132. package/src/utils.js.map +1 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { AsymmetricMatcher } from './asymmetricMatchers';
9
+ // Global matchers object holds the list of available matchers and
10
+ // the state, that can hold matcher specific values that change over time.
11
+ const JEST_MATCHERS_OBJECT = Symbol.for('$$jest-matchers-object');
12
+ // Notes a built-in/internal Jest matcher.
13
+ // Jest may override the stack trace of Errors thrown by internal matchers.
14
+ export const INTERNAL_MATCHER_FLAG = Symbol.for('$$jest-internal-matcher');
15
+ if (!global.hasOwnProperty(JEST_MATCHERS_OBJECT)) {
16
+ const defaultState = {
17
+ assertionCalls: 0,
18
+ expectedAssertionsNumber: null,
19
+ isExpectingAssertions: false,
20
+ suppressedErrors: [], // errors that are not thrown immediately.
21
+ };
22
+ Object.defineProperty(global, JEST_MATCHERS_OBJECT, {
23
+ value: {
24
+ matchers: Object.create(null),
25
+ state: defaultState,
26
+ },
27
+ });
28
+ }
29
+ export const getState = () => global[JEST_MATCHERS_OBJECT].state;
30
+ export const setState = (state) => {
31
+ Object.assign(global[JEST_MATCHERS_OBJECT].state, state);
32
+ };
33
+ export const getMatchers = () => global[JEST_MATCHERS_OBJECT].matchers;
34
+ export const setMatchers = (matchers, isInternal, expect) => {
35
+ Object.keys(matchers).forEach((key) => {
36
+ const matcher = matchers[key];
37
+ Object.defineProperty(matcher, INTERNAL_MATCHER_FLAG, {
38
+ value: isInternal,
39
+ });
40
+ if (!isInternal) {
41
+ // expect is defined
42
+ class CustomMatcher extends AsymmetricMatcher {
43
+ constructor(inverse = false, ...sample) {
44
+ super(sample, inverse);
45
+ }
46
+ asymmetricMatch(other) {
47
+ const { pass } = matcher.call(this.getMatcherContext(), other, ...this.sample);
48
+ return this.inverse ? !pass : pass;
49
+ }
50
+ toString() {
51
+ return `${this.inverse ? 'not.' : ''}${key}`;
52
+ }
53
+ getExpectedType() {
54
+ return 'any';
55
+ }
56
+ toAsymmetricMatcher() {
57
+ return `${this.toString()}<${this.sample
58
+ .map(String)
59
+ .join(', ')}>`;
60
+ }
61
+ }
62
+ Object.defineProperty(expect, key, {
63
+ configurable: true,
64
+ enumerable: true,
65
+ value: (...sample) => new CustomMatcher(false, ...sample),
66
+ writable: true,
67
+ });
68
+ Object.defineProperty(expect.not, key, {
69
+ configurable: true,
70
+ enumerable: true,
71
+ value: (...sample) => new CustomMatcher(true, ...sample),
72
+ writable: true,
73
+ });
74
+ }
75
+ });
76
+ Object.assign(global[JEST_MATCHERS_OBJECT].matchers, matchers);
77
+ };
78
+ //# sourceMappingURL=jestMatchersObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jestMatchersObject.js","sourceRoot":"","sources":["jestMatchersObject.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAQzD,kEAAkE;AAClE,0EAA0E;AAC1E,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAElE,0CAA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Aa,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC;gBACtC,QAAQ,EAAE,IAAI;aACjB,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5E,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ declare type ReplaceableForEachCallBack = (value: unknown, key: unknown, object: unknown) => void;
8
+ export default class Replaceable {
9
+ object: any;
10
+ type: string;
11
+ constructor(object: any);
12
+ static isReplaceable(obj1: unknown, obj2: unknown): boolean;
13
+ forEach(cb: ReplaceableForEachCallBack): void;
14
+ get(key: any): any;
15
+ set(key: any, value: any): void;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=Replaceable.d.ts.map
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { getType } from '../get-type';
8
+ const supportTypes = ['map', 'array', 'object'];
9
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
10
+ export default class Replaceable {
11
+ constructor(object) {
12
+ this.object = object;
13
+ this.type = getType(object);
14
+ if (!supportTypes.includes(this.type)) {
15
+ throw new Error(`Type ${this.type} is not support in Replaceable!`);
16
+ }
17
+ }
18
+ static isReplaceable(obj1, obj2) {
19
+ const obj1Type = getType(obj1);
20
+ const obj2Type = getType(obj2);
21
+ return obj1Type === obj2Type && supportTypes.includes(obj1Type);
22
+ }
23
+ forEach(cb) {
24
+ if (this.type === 'object') {
25
+ const descriptors = Object.getOwnPropertyDescriptors(this.object);
26
+ [
27
+ ...Object.keys(descriptors),
28
+ ...Object.getOwnPropertySymbols(descriptors),
29
+ ]
30
+ //@ts-expect-error because typescript do not support symbol key in object
31
+ //https://github.com/microsoft/TypeScript/issues/1863
32
+ .filter((key) => descriptors[key].enumerable)
33
+ .forEach((key) => {
34
+ cb(this.object[key], key, this.object);
35
+ });
36
+ }
37
+ else {
38
+ this.object.forEach(cb);
39
+ }
40
+ }
41
+ get(key) {
42
+ if (this.type === 'map') {
43
+ return this.object.get(key);
44
+ }
45
+ return this.object[key];
46
+ }
47
+ set(key, value) {
48
+ if (this.type === 'map') {
49
+ this.object.set(key, value);
50
+ }
51
+ else {
52
+ this.object[key] = value;
53
+ }
54
+ }
55
+ }
56
+ /* eslint-enable */
57
+ //# sourceMappingURL=Replaceable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Replaceable.js","sourceRoot":"","sources":["Replaceable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAQhD,sEAAsE;AACtE,MAAM,CAAC,OAAO,OAAO,WAAW;IAI5B,YAAY,MAAW;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,IAAI,iCAAiC,CAAC,CAAC;SACvE;IACL,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,IAAa,EAAE,IAAa;QAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,QAAQ,KAAK,QAAQ,IAAI,YA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inc. and its affiliates. All Rights Reserved.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export default function deepCyclicCopyReplaceable<T>(value: T, cycles?: WeakMap<any, any>): T;
8
+ //# sourceMappingURL=deepCyclicCopyReplaceable.d.ts.map
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { plugins } from '../pretty-format';
8
+ const builtInObject = [
9
+ Array,
10
+ Date,
11
+ Float32Array,
12
+ Float64Array,
13
+ Int16Array,
14
+ Int32Array,
15
+ Int8Array,
16
+ Map,
17
+ Set,
18
+ RegExp,
19
+ Uint16Array,
20
+ Uint32Array,
21
+ Uint8Array,
22
+ Uint8ClampedArray,
23
+ ];
24
+ if (typeof Buffer !== 'undefined') {
25
+ builtInObject.push(Buffer);
26
+ }
27
+ const isBuiltInObject = (object) => builtInObject.includes(object.constructor);
28
+ const isMap = (value) => value.constructor === Map;
29
+ export default function deepCyclicCopyReplaceable(value, cycles = new WeakMap()) {
30
+ if (typeof value !== 'object' || value === null) {
31
+ return value;
32
+ }
33
+ else if (cycles.has(value)) {
34
+ return cycles.get(value);
35
+ }
36
+ else if (Array.isArray(value)) {
37
+ return deepCyclicCopyArray(value, cycles);
38
+ }
39
+ else if (isMap(value)) {
40
+ return deepCyclicCopyMap(value, cycles);
41
+ }
42
+ else if (isBuiltInObject(value)) {
43
+ return value;
44
+ }
45
+ else if (plugins.DOMElement.test(value)) {
46
+ return value.cloneNode(true);
47
+ }
48
+ else {
49
+ return deepCyclicCopyObject(value, cycles);
50
+ }
51
+ }
52
+ function deepCyclicCopyObject(object, cycles) {
53
+ const newObject = Object.create(Object.getPrototypeOf(object));
54
+ const descriptors = Object.getOwnPropertyDescriptors(object);
55
+ cycles.set(object, newObject);
56
+ const newDescriptors = [
57
+ ...Object.keys(descriptors),
58
+ ...Object.getOwnPropertySymbols(descriptors),
59
+ ].reduce(
60
+ // @ts-ignore because typescript do not support symbol key in object
61
+ // https://github.com/microsoft/TypeScript/issues/1863
62
+ (newDescriptors, key) => {
63
+ const enumerable = descriptors[key].enumerable;
64
+ newDescriptors[key] = {
65
+ configurable: true,
66
+ enumerable,
67
+ value: deepCyclicCopyReplaceable(
68
+ // this accesses the value or getter, depending. We just care about the value anyways, and this allows us to not mess with accessors
69
+ // it has the side effect of invoking the getter here though, rather than copying it over
70
+ object[key], cycles),
71
+ writable: true,
72
+ };
73
+ return newDescriptors;
74
+ }, {});
75
+ // @ts-ignore because typescript do not support symbol key in object
76
+ //https://github.com/microsoft/TypeScript/issues/1863
77
+ return Object.defineProperties(newObject, newDescriptors);
78
+ }
79
+ function deepCyclicCopyArray(array, cycles) {
80
+ const newArray = new (Object.getPrototypeOf(array).constructor)(array.length);
81
+ const length = array.length;
82
+ cycles.set(array, newArray);
83
+ for (let i = 0; i < length; i++) {
84
+ newArray[i] = deepCyclicCopyReplaceable(array[i], cycles);
85
+ }
86
+ return newArray;
87
+ }
88
+ function deepCyclicCopyMap(map, cycles) {
89
+ const newMap = new Map();
90
+ cycles.set(map, newMap);
91
+ map.forEach((value, key) => {
92
+ newMap.set(key, deepCyclicCopyReplaceable(value, cycles));
93
+ });
94
+ return newMap;
95
+ }
96
+ //# sourceMappingURL=deepCyclicCopyReplaceable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepCyclicCopyReplaceable.js","sourceRoot":"","sources":["deepCyclicCopyReplaceable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,aAAa,GAAmB;IAClC,KAAK;IACL,IAAI;IACJ,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,UAAU;IACV,SAAS;IACT,GAAG;IACH,GAAG;IACH,MAAM;IACN,WAAW;IACX,WAAW;IACX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AAC,CAAC,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;KAC7D;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,iBAAiB,CACtB,GAA0B,EAC1B,MAA6B;IAE7B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;IAEzB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAExB,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACvB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,OAAO,MAAa,CAAC;AACzB,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { DiffOptions as ImportDiffOptions } from '../diff';
8
+ declare type MatcherHintColor = (arg: string) => string;
9
+ export declare type MatcherHintOptions = {
10
+ comment?: string;
11
+ expectedColor?: MatcherHintColor;
12
+ isDirectExpectCall?: boolean;
13
+ isNot?: boolean;
14
+ promise?: string;
15
+ receivedColor?: MatcherHintColor;
16
+ secondArgument?: string;
17
+ secondArgumentColor?: MatcherHintColor;
18
+ };
19
+ export declare type DiffOptions = ImportDiffOptions;
20
+ export declare const EXPECTED_COLOR: import("@casual-simulation/chalk").ChalkInstance;
21
+ export declare const RECEIVED_COLOR: import("@casual-simulation/chalk").ChalkInstance;
22
+ export declare const INVERTED_COLOR: import("@casual-simulation/chalk").ChalkInstance;
23
+ export declare const BOLD_WEIGHT: import("@casual-simulation/chalk").ChalkInstance;
24
+ export declare const DIM_COLOR: import("@casual-simulation/chalk").ChalkInstance;
25
+ export declare const SUGGEST_TO_CONTAIN_EQUAL: string;
26
+ export declare const stringify: (object: unknown, maxDepth?: number) => string;
27
+ export declare const highlightTrailingWhitespace: (text: string) => string;
28
+ export declare const printReceived: (object: unknown) => string;
29
+ export declare const printExpected: (value: unknown) => string;
30
+ export declare const printWithType: (name: string, value: unknown, print: (value: unknown) => string) => string;
31
+ export declare const ensureNoExpected: (expected: unknown, matcherName: string, options?: MatcherHintOptions) => void;
32
+ /**
33
+ * Ensures that `actual` is of type `number | bigint`
34
+ */
35
+ export declare const ensureActualIsNumber: (actual: unknown, matcherName: string, options?: MatcherHintOptions) => void;
36
+ /**
37
+ * Ensures that `expected` is of type `number | bigint`
38
+ */
39
+ export declare const ensureExpectedIsNumber: (expected: unknown, matcherName: string, options?: MatcherHintOptions) => void;
40
+ /**
41
+ * Ensures that `actual` & `expected` are of type `number | bigint`
42
+ */
43
+ export declare const ensureNumbers: (actual: unknown, expected: unknown, matcherName: string, options?: MatcherHintOptions) => void;
44
+ export declare const ensureExpectedIsNonNegativeInteger: (expected: unknown, matcherName: string, options?: MatcherHintOptions) => void;
45
+ export declare const printDiffOrStringify: (expected: unknown, received: unknown, expectedLabel: string, receivedLabel: string, expand: boolean) => string;
46
+ export declare const diff: (a: unknown, b: unknown, options?: DiffOptions) => string | null;
47
+ export declare const pluralize: (word: string, count: number) => string;
48
+ declare type PrintLabel = (string: string) => string;
49
+ export declare const getLabelPrinter: (...strings: Array<string>) => PrintLabel;
50
+ export declare const matcherErrorMessage: (hint: string, generic: string, specific?: string) => string;
51
+ export declare const matcherHint: (matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions) => string;
52
+ export {};
53
+ //# sourceMappingURL=index.d.ts.map