From 031f592cc7cf4bc962dc72f0890315855ce8c15a Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Sat, 18 Apr 2020 00:55:45 +0200 Subject: [PATCH] [html] Add types for html (#43956) --- types/html/html-tests.ts | 12 ++++++++++++ types/html/index.d.ts | 25 +++++++++++++++++++++++++ types/html/tsconfig.json | 23 +++++++++++++++++++++++ types/html/tslint.json | 1 + 4 files changed, 61 insertions(+) create mode 100644 types/html/html-tests.ts create mode 100644 types/html/index.d.ts create mode 100644 types/html/tsconfig.json create mode 100644 types/html/tslint.json diff --git a/types/html/html-tests.ts b/types/html/html-tests.ts new file mode 100644 index 0000000000..3a8e4f2d79 --- /dev/null +++ b/types/html/html-tests.ts @@ -0,0 +1,12 @@ +import { prettyPrint } from 'html'; + +prettyPrint('

Hello, World!

'); // $ExpectType string +prettyPrint('

Hello, World!

', {}); // $ExpectType string +prettyPrint('

Hello, World!

', { + brace_style: 'collapse', + indent_scripts: 'keep', + indent_size: 2, + indent_char: ' ', + max_char: 5, + unformatted: [], +}); diff --git a/types/html/index.d.ts b/types/html/index.d.ts new file mode 100644 index 0000000000..467ce701e4 --- /dev/null +++ b/types/html/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for html 1.0 +// Project: https://github.com/maxogden/commonjs-html-prettyprinter +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface PrintOptions { + /** + * Put braces on the same line as control statements (`collapse`), + * or put braces on own line (Allman / ANSI style, `expand`), + * or just put end braces on own line (`end-expand`). Default: `collapse`. + */ + brace_style?: 'collapse' | 'expand' | 'end-expand'; + /** Default: `normal`. */ + indent_scripts?: 'keep' | 'separate' | 'normal'; + /** indentation size. Default: 4. */ + indent_size?: number; + /** character to indent with. Default: " " (space). */ + indent_char?: string; + /** Maximum amount of characters per line. Default: 70. */ + max_char?: number; + /** list of tags, that shouldn't be reformatted. Defaults to inline tags. */ + unformatted?: string[]; +} + +export function prettyPrint(htmlSource: string, options?: PrintOptions): string; diff --git a/types/html/tsconfig.json b/types/html/tsconfig.json new file mode 100644 index 0000000000..cc82d56966 --- /dev/null +++ b/types/html/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "html-tests.ts" + ] +} diff --git a/types/html/tslint.json b/types/html/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/html/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }