From 9cbabd08c267b20ba9f1ff4283a79a2cdbb5cbb4 Mon Sep 17 00:00:00 2001 From: ikatyang Date: Wed, 23 Aug 2017 16:25:27 +0800 Subject: [PATCH] feat(pretty-format): initial commit --- types/pretty-format/index.d.ts | 80 ++++++++++++++++++++++ types/pretty-format/pretty-format-tests.ts | 10 +++ types/pretty-format/tsconfig.json | 22 ++++++ types/pretty-format/tslint.json | 1 + 4 files changed, 113 insertions(+) create mode 100644 types/pretty-format/index.d.ts create mode 100644 types/pretty-format/pretty-format-tests.ts create mode 100644 types/pretty-format/tsconfig.json create mode 100644 types/pretty-format/tslint.json diff --git a/types/pretty-format/index.d.ts b/types/pretty-format/index.d.ts new file mode 100644 index 0000000000..c4f3484e76 --- /dev/null +++ b/types/pretty-format/index.d.ts @@ -0,0 +1,80 @@ +// Type definitions for pretty-format 20.0 +// Project: https://github.com/facebook/jest/tree/master/packages/pretty-format +// Definitions by: Ika +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/** + * Stringify any JavaScript value. + */ +declare function prettyFormat(value: any, options?: prettyFormat.Options): string; + +declare namespace prettyFormat { + interface Options { + /** + * Call `toJSON()` on passed object. + */ + callToJSON?: boolean; + /** + * Escape special characters in regular expressions. + */ + escapeRegex?: boolean; + /** + * Highlight syntax for terminal (works only with `ReactTestComponent` and `ReactElement` plugins. + */ + highlight?: boolean; + /** + * Number of spaces for indentation. + */ + indent?: number; + /** + * Print only this number of levels. + */ + maxDepth?: number; + /** + * Print without whitespace. + */ + min?: boolean; + /** + * plugins to serialize application-specific data types + */ + plugins?: Plugin[]; + /** + * Print function names or just [Function]. + */ + printFunctionName?: boolean; + /** + * Syntax highlight theme. + * Uses [ansi-styles colors](https://github.com/chalk/ansi-styles#colors) + `reset` for no color. + */ + theme?: Theme; + } + + interface Plugin { + test(value: any): boolean; + print(value: any, serialize: Print, indent: Indent, options: Options, colors: Colors): string; + } + + const plugins: Record<'AsymmetricMatcher' | 'ConvertAnsi' | 'HTMLElement' | 'Immutable' | 'ReactElement' | 'ReactTestComponent', Plugin>; + + type Print = (value: any) => string; + type Indent = (value: string) => string; + + interface Colors { + comment: { close: string; open: string }; + content: { close: string; open: string }; + prop: { close: string; open: string }; + tag: { close: string; open: string }; + value: { close: string; open: string }; + } + + interface Theme { + comment?: string; + content?: string; + prop?: string; + tag?: string; + value?: string; + } +} + +export = prettyFormat; diff --git a/types/pretty-format/pretty-format-tests.ts b/types/pretty-format/pretty-format-tests.ts new file mode 100644 index 0000000000..50194041d3 --- /dev/null +++ b/types/pretty-format/pretty-format-tests.ts @@ -0,0 +1,10 @@ +import prettyFormat = require('pretty-format'); + +prettyFormat({ something: 'value' }); + +prettyFormat({ something: 'value' }, { + plugins: [ + prettyFormat.plugins.ReactElement, + prettyFormat.plugins.ReactTestComponent, + ] +}); diff --git a/types/pretty-format/tsconfig.json b/types/pretty-format/tsconfig.json new file mode 100644 index 0000000000..db0f3e25e4 --- /dev/null +++ b/types/pretty-format/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pretty-format-tests.ts" + ] +} diff --git a/types/pretty-format/tslint.json b/types/pretty-format/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pretty-format/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }