UNPKG

2.96 kBTypeScriptView Raw
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 */
7import type {SnapshotFormat} from '@jest/schemas';
8
9export declare type Colors = {
10 comment: {
11 close: string;
12 open: string;
13 };
14 content: {
15 close: string;
16 open: string;
17 };
18 prop: {
19 close: string;
20 open: string;
21 };
22 tag: {
23 close: string;
24 open: string;
25 };
26 value: {
27 close: string;
28 open: string;
29 };
30};
31
32export declare type CompareKeys =
33 | ((a: string, b: string) => number)
34 | undefined;
35
36export declare type Config = {
37 callToJSON: boolean;
38 compareKeys: CompareKeys;
39 colors: Colors;
40 escapeRegex: boolean;
41 escapeString: boolean;
42 indent: string;
43 maxDepth: number;
44 maxWidth: number;
45 min: boolean;
46 plugins: Plugins;
47 printBasicPrototype: boolean;
48 printFunctionName: boolean;
49 spacingInner: string;
50 spacingOuter: string;
51};
52
53export declare const DEFAULT_OPTIONS: Options;
54
55/**
56 * Returns a presentation string of your `val` object
57 * @param val any potential JavaScript object
58 * @param options Custom settings
59 */
60declare function format(val: unknown, options?: OptionsReceived): string;
61export default format;
62export {format};
63
64declare type Indent = (arg0: string) => string;
65
66export declare type NewPlugin = {
67 serialize: (
68 val: any,
69 config: Config,
70 indentation: string,
71 depth: number,
72 refs: Refs,
73 printer: Printer,
74 ) => string;
75 test: Test;
76};
77
78export declare type OldPlugin = {
79 print: (
80 val: unknown,
81 print: Print,
82 indent: Indent,
83 options: PluginOptions,
84 colors: Colors,
85 ) => string;
86 test: Test;
87};
88
89export declare interface Options
90 extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
91 compareKeys: CompareKeys;
92 theme: Required<RequiredOptions['theme']>;
93}
94
95export declare type OptionsReceived = PrettyFormatOptions;
96
97declare type Plugin_2 = NewPlugin | OldPlugin;
98export {Plugin_2 as Plugin};
99
100declare type PluginOptions = {
101 edgeSpacing: string;
102 min: boolean;
103 spacing: string;
104};
105
106export declare type Plugins = Array<Plugin_2>;
107
108export declare const plugins: {
109 AsymmetricMatcher: NewPlugin;
110 ConvertAnsi: NewPlugin;
111 DOMCollection: NewPlugin;
112 DOMElement: NewPlugin;
113 Immutable: NewPlugin;
114 ReactElement: NewPlugin;
115 ReactTestComponent: NewPlugin;
116};
117
118export declare interface PrettyFormatOptions extends SnapshotFormat {
119 compareKeys?: CompareKeys;
120 plugins?: Plugins;
121}
122
123declare type Print = (arg0: unknown) => string;
124
125export declare type Printer = (
126 val: unknown,
127 config: Config,
128 indentation: string,
129 depth: number,
130 refs: Refs,
131 hasCalledToJSON?: boolean,
132) => string;
133
134export declare type Refs = Array<unknown>;
135
136declare type RequiredOptions = Required<PrettyFormatOptions>;
137
138declare type Test = (arg0: any) => boolean;
139
140export declare type Theme = Options['theme'];
141
142export {};