mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[xmlserializer] Add types
This commit is contained in:
parent
7c13736555
commit
22dc1900d5
48
types/xmlserializer/index.d.ts
vendored
Normal file
48
types/xmlserializer/index.d.ts
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
// Type definitions for xmlserializer 0.6
|
||||
// Project: https://github.com/cburgmer/xmlserializer#readme
|
||||
// Definitions by: Eoin O'Brien <https://github.com/eoin-obrien>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as parse5 from 'parse5';
|
||||
|
||||
export as namespace xmlserializer;
|
||||
|
||||
/**
|
||||
* Serializes a DOM subtree or DOM document into XML/XHTML.
|
||||
*
|
||||
* It understands documents generated by `parse5` and regular browser DOMs (and
|
||||
* thus can act as a drop-in replacement for `XMLSerializer` which for some
|
||||
* browsers only serializes true XML documents).
|
||||
*
|
||||
* Currently some cases are treated differently to the `XMLSerializer`
|
||||
* implementation of the browsers:
|
||||
*
|
||||
* - Invalid characters (ASCII control characters) that are invalid in XML 1.0
|
||||
* are removed on serialization. The browsers silently include those
|
||||
* characters and on reparsing those documents throw a parser exception.
|
||||
* - Dashes in comments are escaped to provide valid comments in XHTML. Firefox
|
||||
* does not do this.
|
||||
* - The xmlns attribute has higher precedence than the type of the DOM object
|
||||
* passed to the serializer.
|
||||
* - Small differences in style: no space in self-closing tag, empty value for
|
||||
* boolean attributes, quoting of single apostrophes in attribute values.
|
||||
*
|
||||
* This behaviour might become optional in the future.
|
||||
*
|
||||
* @example
|
||||
* import * as xmlserializer from 'xmlserializer';
|
||||
* import * as parse5 from 'parse5';
|
||||
*
|
||||
* const html2xhtml = (htmlString: string) => {
|
||||
* const dom = parse5.parse(htmlString);
|
||||
* return xmlserializer.serializeToString(dom);
|
||||
* };
|
||||
*
|
||||
* console.log(html2xhtml('<br>'));
|
||||
*
|
||||
* @param node the DOM element to be serialized to XML/XHTML
|
||||
*/
|
||||
export function serializeToString(node: parse5.Element): string;
|
||||
6
types/xmlserializer/package.json
Normal file
6
types/xmlserializer/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"parse5": "^5.1.0"
|
||||
}
|
||||
}
|
||||
23
types/xmlserializer/tsconfig.json
Normal file
23
types/xmlserializer/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"xmlserializer-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/xmlserializer/tslint.json
Normal file
1
types/xmlserializer/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
8
types/xmlserializer/xmlserializer-tests.ts
Normal file
8
types/xmlserializer/xmlserializer-tests.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as xmlserializer from 'xmlserializer';
|
||||
import * as parse5 from 'parse5';
|
||||
|
||||
const htmlString = '<br>';
|
||||
const dom = parse5.parse(htmlString);
|
||||
|
||||
// $ExpectType string
|
||||
xmlserializer.serializeToString(dom);
|
||||
Loading…
Reference in New Issue
Block a user