[html] Add types for html (#43956)

This commit is contained in:
Florian Keller 2020-04-18 00:55:45 +02:00 committed by GitHub
parent 00a3022d2a
commit 031f592cc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 0 deletions

12
types/html/html-tests.ts Normal file
View File

@ -0,0 +1,12 @@
import { prettyPrint } from 'html';
prettyPrint('<h2><strong>Hello, <a href="http://example.com">World</a>!</strong></h2>'); // $ExpectType string
prettyPrint('<h2><strong>Hello, <a href="http://example.com">World</a>!</strong></h2>', {}); // $ExpectType string
prettyPrint('<h2><strong>Hello, <a href="http://example.com">World</a>!</strong></h2>', {
brace_style: 'collapse',
indent_scripts: 'keep',
indent_size: 2,
indent_char: ' ',
max_char: 5,
unformatted: [],
});

25
types/html/index.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
// Type definitions for html 1.0
// Project: https://github.com/maxogden/commonjs-html-prettyprinter
// Definitions by: Florian Keller <https://github.com/ffflorian>
// 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;

23
types/html/tsconfig.json Normal file
View File

@ -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"
]
}

1
types/html/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }