66 */
77
88import style from 'ansi-styles' ;
9- import {
10- Colors ,
11- Config ,
12- Options ,
13- OptionsReceived ,
14- NewPlugin ,
15- Plugin ,
16- Plugins ,
17- Refs ,
18- Theme ,
19- } from './types' ;
9+ import * as PrettyFormat from './types' ;
2010
2111import {
2212 printIteratorEntries ,
@@ -179,10 +169,10 @@ function printBasicValue(
179169 */
180170function printComplexValue (
181171 val : any ,
182- config : Config ,
172+ config : PrettyFormat . Config ,
183173 indentation : string ,
184174 depth : number ,
185- refs : Refs ,
175+ refs : PrettyFormat . Refs ,
186176 hasCalledToJSON ?: boolean ,
187177) : string {
188178 if ( refs . indexOf ( val ) !== - 1 ) {
@@ -261,17 +251,19 @@ function printComplexValue(
261251 '}' ;
262252}
263253
264- function isNewPlugin ( plugin : Plugin ) : plugin is NewPlugin {
265- return ( plugin as NewPlugin ) . serialize != null ;
254+ function isNewPlugin (
255+ plugin : PrettyFormat . Plugin ,
256+ ) : plugin is PrettyFormat . NewPlugin {
257+ return ( plugin as PrettyFormat . NewPlugin ) . serialize != null ;
266258}
267259
268260function printPlugin (
269- plugin : Plugin ,
261+ plugin : PrettyFormat . Plugin ,
270262 val : any ,
271- config : Config ,
263+ config : PrettyFormat . Config ,
272264 indentation : string ,
273265 depth : number ,
274- refs : Refs ,
266+ refs : PrettyFormat . Refs ,
275267) : string {
276268 let printed ;
277269
@@ -306,7 +298,7 @@ function printPlugin(
306298 return printed ;
307299}
308300
309- function findPlugin ( plugins : Plugins , val : any ) {
301+ function findPlugin ( plugins : PrettyFormat . Plugins , val : any ) {
310302 for ( let p = 0 ; p < plugins . length ; p ++ ) {
311303 try {
312304 if ( plugins [ p ] . test ( val ) ) {
@@ -322,10 +314,10 @@ function findPlugin(plugins: Plugins, val: any) {
322314
323315function printer (
324316 val : any ,
325- config : Config ,
317+ config : PrettyFormat . Config ,
326318 indentation : string ,
327319 depth : number ,
328- refs : Refs ,
320+ refs : PrettyFormat . Refs ,
329321 hasCalledToJSON ?: boolean ,
330322) : string {
331323 const plugin = findPlugin ( config . plugins , val ) ;
@@ -353,7 +345,7 @@ function printer(
353345 ) ;
354346}
355347
356- const DEFAULT_THEME : Theme = {
348+ const DEFAULT_THEME : PrettyFormat . Theme = {
357349 comment : 'gray' ,
358350 content : 'reset' ,
359351 prop : 'yellow' ,
@@ -363,7 +355,7 @@ const DEFAULT_THEME: Theme = {
363355
364356const DEFAULT_THEME_KEYS = Object . keys ( DEFAULT_THEME ) ;
365357
366- const DEFAULT_OPTIONS : Options = {
358+ const DEFAULT_OPTIONS : PrettyFormat . Options = {
367359 callToJSON : true ,
368360 escapeRegex : false ,
369361 escapeString : true ,
@@ -376,7 +368,7 @@ const DEFAULT_OPTIONS: Options = {
376368 theme : DEFAULT_THEME ,
377369} ;
378370
379- function validateOptions ( options : OptionsReceived ) {
371+ function validateOptions ( options : PrettyFormat . OptionsReceived ) {
380372 Object . keys ( options ) . forEach ( key => {
381373 if ( ! DEFAULT_OPTIONS . hasOwnProperty ( key ) ) {
382374 throw new Error ( `pretty-format: Unknown option "${ key } ".` ) ;
@@ -402,7 +394,9 @@ function validateOptions(options: OptionsReceived) {
402394 }
403395}
404396
405- const getColorsHighlight = ( options : OptionsReceived ) : Colors =>
397+ const getColorsHighlight = (
398+ options : PrettyFormat . OptionsReceived ,
399+ ) : PrettyFormat . Colors =>
406400 DEFAULT_THEME_KEYS . reduce ( ( colors , key ) => {
407401 const value =
408402 options . theme && ( options . theme as any ) [ key ] !== undefined
@@ -423,28 +417,30 @@ const getColorsHighlight = (options: OptionsReceived): Colors =>
423417 return colors ;
424418 } , Object . create ( null ) ) ;
425419
426- const getColorsEmpty = ( ) : Colors =>
420+ const getColorsEmpty = ( ) : PrettyFormat . Colors =>
427421 DEFAULT_THEME_KEYS . reduce ( ( colors , key ) => {
428422 colors [ key ] = { close : '' , open : '' } ;
429423 return colors ;
430424 } , Object . create ( null ) ) ;
431425
432- const getPrintFunctionName = ( options ?: OptionsReceived ) =>
426+ const getPrintFunctionName = ( options ?: PrettyFormat . OptionsReceived ) =>
433427 options && options . printFunctionName !== undefined
434428 ? options . printFunctionName
435429 : DEFAULT_OPTIONS . printFunctionName ;
436430
437- const getEscapeRegex = ( options ?: OptionsReceived ) =>
431+ const getEscapeRegex = ( options ?: PrettyFormat . OptionsReceived ) =>
438432 options && options . escapeRegex !== undefined
439433 ? options . escapeRegex
440434 : DEFAULT_OPTIONS . escapeRegex ;
441435
442- const getEscapeString = ( options ?: OptionsReceived ) =>
436+ const getEscapeString = ( options ?: PrettyFormat . OptionsReceived ) =>
443437 options && options . escapeString !== undefined
444438 ? options . escapeString
445439 : DEFAULT_OPTIONS . escapeString ;
446440
447- const getConfig = ( options ?: OptionsReceived ) : Config => ( {
441+ const getConfig = (
442+ options ?: PrettyFormat . OptionsReceived ,
443+ ) : PrettyFormat . Config => ( {
448444 callToJSON :
449445 options && options . callToJSON !== undefined
450446 ? options . callToJSON
@@ -486,7 +482,10 @@ function createIndent(indent: number): string {
486482 * @param val any potential JavaScript object
487483 * @param options Custom settings
488484 */
489- function prettyFormat ( val : any , options ?: OptionsReceived ) : string {
485+ function prettyFormat (
486+ val : any ,
487+ options ?: PrettyFormat . OptionsReceived ,
488+ ) : string {
490489 if ( options ) {
491490 validateOptions ( options ) ;
492491 if ( options . plugins ) {
@@ -520,4 +519,17 @@ prettyFormat.plugins = {
520519 ReactTestComponent,
521520} ;
522521
522+ /* eslint-disable-next-line no-redeclare */
523+ namespace prettyFormat {
524+ export type Colors = PrettyFormat . Colors ;
525+ export type Config = PrettyFormat . Config ;
526+ export type Options = PrettyFormat . Options ;
527+ export type OptionsReceived = PrettyFormat . OptionsReceived ;
528+ export type NewPlugin = PrettyFormat . NewPlugin ;
529+ export type Plugin = PrettyFormat . Plugin ;
530+ export type Plugins = PrettyFormat . Plugins ;
531+ export type Refs = PrettyFormat . Refs ;
532+ export type Theme = PrettyFormat . Theme ;
533+ }
534+
523535export = prettyFormat ;
0 commit comments