From a8f2b8a2a1b398fcfb58a21852ce19f3458f3498 Mon Sep 17 00:00:00 2001 From: mfrantz Date: Tue, 4 Aug 2015 20:12:04 -0700 Subject: [PATCH] xml-parser v1.2.1 --- xml-parser/xml-parser-tests.ts | 20 ++++++++++++++++++++ xml-parser/xml-parser.d.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 xml-parser/xml-parser-tests.ts create mode 100644 xml-parser/xml-parser.d.ts diff --git a/xml-parser/xml-parser-tests.ts b/xml-parser/xml-parser-tests.ts new file mode 100644 index 0000000000..81518cd28e --- /dev/null +++ b/xml-parser/xml-parser-tests.ts @@ -0,0 +1,20 @@ +/// +/// + +import assert = require('assert'); +import parse = require('xml-parser'); + +var doc: parse.Document = parse( + '' + + 'foo'); +var declaration: parse.Declaration = doc.declaration; +assert.equal(declaration.attributes['version'], '1.0'); +assert.equal(declaration.attributes['encoding'], 'utf-8'); +var root: parse.Node = doc.root; +assert.equal(root.name, 'mydoc'); +var children: parse.Node[] = root.children; +assert.equal(children.length, 2); +var child1: parse.Node = children[0]; +assert.equal(child1.name, 'child'); +assert.equal(child1.attributes['a'], '1'); +assert.equal(child1.content, 'foo'); diff --git a/xml-parser/xml-parser.d.ts b/xml-parser/xml-parser.d.ts new file mode 100644 index 0000000000..2bb25fc8f0 --- /dev/null +++ b/xml-parser/xml-parser.d.ts @@ -0,0 +1,33 @@ +// Type definitions for xml-parser 1.2.1 +// Project: https://github.com/segmentio/xml-parser +// Definitions by: Matt Frantz +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'xml-parser' { + + function parse(xml: string): parse.Document; + + module parse { + export interface Document { + declaration: Declaration; + root: Node; + } + + export interface Declaration { + attributes: Attributes; + } + + export interface Node { + name: string; + attributes: Attributes; + children: Node[]; + content?: string; + } + + export interface Attributes { + [name: string]: string; + } + } + + export = parse; +}