UNPKG

3.44 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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 | null
35 | undefined;
36
37export declare type Config = {
38 callToJSON: boolean;
39 compareKeys: CompareKeys;
40 colors: Colors;
41 escapeRegex: boolean;
42 escapeString: boolean;
43 indent: string;
44 maxDepth: number;
45 maxWidth: number;
46 min: boolean;
47 plugins: Plugins;
48 printBasicPrototype: boolean;
49 printFunctionName: boolean;
50 spacingInner: string;
51 spacingOuter: string;
52};
53
54export declare const DEFAULT_OPTIONS: {
55 callToJSON: true;
56 compareKeys: undefined;
57 escapeRegex: false;
58 escapeString: true;
59 highlight: false;
60 indent: number;
61 maxDepth: number;
62 maxWidth: number;
63 min: false;
64 plugins: never[];
65 printBasicPrototype: true;
66 printFunctionName: true;
67 theme: Required<{
68 readonly comment?: string | undefined;
69 readonly content?: string | undefined;
70 readonly prop?: string | undefined;
71 readonly tag?: string | undefined;
72 readonly value?: string | undefined;
73 }>;
74};
75
76/**
77 * Returns a presentation string of your `val` object
78 * @param val any potential JavaScript object
79 * @param options Custom settings
80 */
81declare function format(val: unknown, options?: OptionsReceived): string;
82export default format;
83export {format};
84
85declare type Indent = (arg0: string) => string;
86
87export declare type NewPlugin = {
88 serialize: (
89 val: any,
90 config: Config,
91 indentation: string,
92 depth: number,
93 refs: Refs,
94 printer: Printer,
95 ) => string;
96 test: Test;
97};
98
99export declare type OldPlugin = {
100 print: (
101 val: unknown,
102 print: Print,
103 indent: Indent,
104 options: PluginOptions,
105 colors: Colors,
106 ) => string;
107 test: Test;
108};
109
110export declare interface Options
111 extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
112 compareKeys: CompareKeys;
113 theme: Required<RequiredOptions['theme']>;
114}
115
116export declare type OptionsReceived = PrettyFormatOptions;
117
118declare type Plugin_2 = NewPlugin | OldPlugin;
119export {Plugin_2 as Plugin};
120
121declare type PluginOptions = {
122 edgeSpacing: string;
123 min: boolean;
124 spacing: string;
125};
126
127export declare type Plugins = Array<Plugin_2>;
128
129export declare const plugins: {
130 AsymmetricMatcher: NewPlugin;
131 DOMCollection: NewPlugin;
132 DOMElement: NewPlugin;
133 Immutable: NewPlugin;
134 ReactElement: NewPlugin;
135 ReactTestComponent: NewPlugin;
136};
137
138export declare interface PrettyFormatOptions
139 extends Omit<SnapshotFormat, 'compareKeys'> {
140 compareKeys?: CompareKeys;
141 plugins?: Plugins;
142}
143
144declare type Print = (arg0: unknown) => string;
145
146export declare type Printer = (
147 val: unknown,
148 config: Config,
149 indentation: string,
150 depth: number,
151 refs: Refs,
152 hasCalledToJSON?: boolean,
153) => string;
154
155export declare type Refs = Array<unknown>;
156
157declare type RequiredOptions = Required<PrettyFormatOptions>;
158
159declare type Test = (arg0: any) => boolean;
160
161export declare type Theme = Options['theme'];
162
163export {};