mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Types for Html-validator (#37607)
* draft * clear to tests * Clear for tests
This commit is contained in:
parent
a26e3956af
commit
f18ba003c3
37
types/html-validator/html-validator-tests.ts
Normal file
37
types/html-validator/html-validator-tests.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import validateHtml = require('html-validator');
|
||||
|
||||
const testHtml = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>Invalid</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>I'm baaaaaaaaaaaad code</div></p>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
validateHtml({
|
||||
data: testHtml,
|
||||
format: 'json'
|
||||
}).then((validationResults: validateHtml.ParsedJsonAsValidationResults) => {
|
||||
if (validationResults.messages.length === 0) {
|
||||
console.warn(`File "test" contains W3C standard violations or guidelines neglects.`);
|
||||
return;
|
||||
}
|
||||
|
||||
validationResults.messages.forEach((violation: validateHtml.ValidationMessageObject) => {
|
||||
if (violation.type === 'error') {
|
||||
console.log(`W3C standard violation: ${violation.message}`);
|
||||
}
|
||||
|
||||
if (violation.type === 'info') {
|
||||
console.warn(`W3C guidelines neglect: ${violation.message}`);
|
||||
}
|
||||
|
||||
console.log(violation.extract);
|
||||
console.log(`line: ${violation.lastLine}, column: ${violation.firstColumn}-${violation.lastColumn}\n`);
|
||||
});
|
||||
});
|
||||
91
types/html-validator/index.d.ts
vendored
Normal file
91
types/html-validator/index.d.ts
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
// Type definitions for html-validator 4.1
|
||||
// Project: https://github.com/zrrrzzt/html-validator
|
||||
// Definitions by: Takesi Tokugawa <https://github.com/TokugawaTakesi>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare function HtmlValidator(
|
||||
options:
|
||||
HtmlValidator.OptionsForHtmlFileAsValidationTargetAndObjectAsResult |
|
||||
HtmlValidator.OptionsForExternalUrlAsValidationTargetAndObjectAsResult
|
||||
): Promise<HtmlValidator.ParsedJsonAsValidationResults>;
|
||||
|
||||
declare function HtmlValidator(
|
||||
options:
|
||||
HtmlValidator.OptionsForHtmlFileAsValidationTargetAndTextAsResults |
|
||||
HtmlValidator.OptionsForExternalUrlAsValidationTargetAndTextAsResults
|
||||
): Promise<string>;
|
||||
|
||||
declare namespace HtmlValidator {
|
||||
interface BasicOptions {
|
||||
validator?: object;
|
||||
ignore?: string | string[];
|
||||
isLocal?: boolean;
|
||||
isFragment?: boolean;
|
||||
}
|
||||
|
||||
interface OptionsForHtmlFileAsValidationTarget extends BasicOptions {
|
||||
data: string;
|
||||
}
|
||||
|
||||
interface OptionsForExternalUrlAsValidationTarget extends BasicOptions {
|
||||
url: string;
|
||||
}
|
||||
|
||||
// Could be used to avoid string literals
|
||||
enum ValidationResultsOutputFormats {
|
||||
json = 'json',
|
||||
html = 'html',
|
||||
xhtml = 'xhtml',
|
||||
xml = 'xml',
|
||||
gnu = 'gnu',
|
||||
text = 'text'
|
||||
}
|
||||
|
||||
interface OptionsForHtmlFileAsValidationTargetAndObjectAsResult extends OptionsForHtmlFileAsValidationTarget {
|
||||
format?: 'json';
|
||||
}
|
||||
|
||||
interface OptionsForHtmlFileAsValidationTargetAndTextAsResults extends OptionsForHtmlFileAsValidationTarget {
|
||||
format: 'html' | 'xhtml' | 'xml' | 'gnu' | 'text';
|
||||
}
|
||||
|
||||
interface OptionsForExternalUrlAsValidationTargetAndObjectAsResult extends OptionsForExternalUrlAsValidationTarget {
|
||||
format?: 'json';
|
||||
}
|
||||
|
||||
interface OptionsForExternalUrlAsValidationTargetAndTextAsResults extends OptionsForHtmlFileAsValidationTarget {
|
||||
format: 'html' | 'xhtml' | 'xml' | 'gnu' | 'text';
|
||||
}
|
||||
|
||||
interface ParsedJsonAsValidationResults {
|
||||
messages: ValidationMessageObject[];
|
||||
}
|
||||
|
||||
// Could be used to avoid string literals
|
||||
enum ValidationMessageTypes {
|
||||
error = 'error',
|
||||
info = 'info'
|
||||
}
|
||||
|
||||
// Could be used to avoid string literals
|
||||
enum ValidationMessageSubTypes {
|
||||
warning = 'warning'
|
||||
}
|
||||
|
||||
interface ValidationMessageObject {
|
||||
type: 'error' | 'info';
|
||||
subType?: 'warning';
|
||||
lastLine: number;
|
||||
firstColumn: number;
|
||||
lastColumn: number;
|
||||
hiliteStart: number;
|
||||
hiliteLength: number;
|
||||
message: string;
|
||||
extract: string;
|
||||
}
|
||||
}
|
||||
|
||||
export = HtmlValidator;
|
||||
23
types/html-validator/tsconfig.json
Normal file
23
types/html-validator/tsconfig.json
Normal 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-validator-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/html-validator/tslint.json
Normal file
3
types/html-validator/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user