mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 06:17:04 +00:00
Merge pull request #23671 from petejohanson/parse-xml-types
Add type definition for @rgrove/parse-xml.
This commit is contained in:
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
// Type definitions for @rgrove/parse-xml 1.1
|
||||
// Project: https://github.com/rgrove/parse-xml
|
||||
// Definitions by: Pete Johanson <https://github.com/petejohanson>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
declare function parseXml(name: string, options?: parseXml.ParseOptions): parseXml.Document;
|
||||
|
||||
declare namespace parseXml {
|
||||
interface NodeBase {
|
||||
parent?: NodeBase;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface Document extends NodeBase {
|
||||
type: "document";
|
||||
children: NodeBase[];
|
||||
}
|
||||
|
||||
interface CData extends NodeBase {
|
||||
type: "cdata";
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface Comment extends NodeBase {
|
||||
type: "comment";
|
||||
content: string;
|
||||
}
|
||||
|
||||
interface Text extends NodeBase {
|
||||
type: "text";
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface Element extends NodeBase {
|
||||
type: "element";
|
||||
attributes: { [key: string]: string };
|
||||
children: NodeBase[];
|
||||
name: string;
|
||||
preserveWhitespace?: string;
|
||||
}
|
||||
|
||||
type Node = CData | Comment | Element | Text;
|
||||
|
||||
interface ParseOptions {
|
||||
ignoreUndefinedEntities?: boolean;
|
||||
preserveCdata?: boolean;
|
||||
preserveComments?: boolean;
|
||||
resolveUndefinedEntity?: (ref: string) => string;
|
||||
}
|
||||
}
|
||||
|
||||
export = parseXml;
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference types="node" />
|
||||
import assert = require('assert');
|
||||
import parseXml = require('@rgrove/parse-xml');
|
||||
|
||||
const doc = parseXml('<party></party>');
|
||||
doc.type === "document";
|
||||
assert.equal(doc.children[0].type, "element");
|
||||
assert.equal((doc.children[0] as parseXml.Element).name, "party");
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"paths": {
|
||||
"@rgrove/parse-xml": ["rgrove__parse-xml"]
|
||||
},
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"rgrove__parse-xml-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user