DefinitelyTyped/types/xmljs/index.d.ts
blackshadev d8c0d5c929 xmljs typings. Closes #36202 (#36228)
* added typings for xmljs. Closes #36202

* removed partial interface

* removed I for interface
2019-06-20 14:03:28 -07:00

117 lines
3.0 KiB
TypeScript

// Type definitions for xmljs 0.3
// Project: https://github.com/blackshadev/xmljs
// Definitions by: Vincent Hagen <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*~ Note that ES6 modules cannot directly export class objects.
*~ This file should be imported using the CommonJS-style:
*~ import x = require('someLibrary');
*~
*~ Refer to the documentation to understand common
*~ workarounds for this limitation of ES6 modules.
*/
/*~ If this module is a UMD module that exposes a global variable 'myClassLib' when
*~ loaded outside a module loader environment, declare that global here.
*~ Otherwise, delete this declaration.
*/
export as namespace XmlParser;
/*~ This declaration specifies that the class constructor function
*~ is the exported object from the file
*/
export = XmlParser;
interface ParserParameters {
/**
* Whenever or not to use a strict parser
*/
strict?: boolean;
/**
* Do not trimtext and comment nodes
*/
noTrim?: boolean;
/**
* Do not normalize whitespaces in text
*/
noNormalizeWhitespaces?: boolean;
/**
* Turn the tagsNames to lowercase
*/
lowercaseTagnames?: boolean;
/**
* Disables xml namespaces
*/
noNamespaces?: boolean;
/**
* Disable position tracing of sax
*/
noTracing?: boolean;
/**
* Allow only predefined entities
*/
strictEntities?: boolean;
}
/*~ Write your module's methods and properties in this class */
declare class XmlParser {
constructor(oPar: ParserParameters);
/**
* Parses a xml string
* @param xml XML string to parse
* @param cb Callback function with error and the result (an Node)
* @returns whenever or not there where any errors
*/
parseString(xml: string, cb: (err: null | Error[], xmlNode: Node) => void): boolean;
errors: Error[];
/**
* Returns whenever a node is a XmlNode or not
* @param n
*/
static isXmlNode(n: Node): n is XmlNode;
}
/**
* Attribute
*/
declare class Attribute {
name: string;
text: string;
}
/**
* XML Attribute, an attribute with a namespace
*/
declare class XmlAttribute extends Attribute {
ns: string;
}
declare class Node {
/**
* Gets an node attribute by name
* @param attrName Name of the attribute
* @param ignoreCase whenever or not to ignore the name casing
*/
getAttribute(attrName: string, ignoreCase: boolean): XmlAttribute;
/**
* Traverses the XML Nodes and iterates through specified path
* @param path Node names to traverse down
* @param ignoreCase Ignore the casing of the path / node names
*/
path(path: string[], ignoreCase: boolean): XmlNode[];
/**
* Recursively traverses the nodes and calls the given function in-order
* @param fn Function to call for each node
*/
visit(fn: (n: Node) => void): void;
}
declare class XmlNode extends Node {
name: string;
ns: string;
prefix: string;
localName: string;
text: string;
}