diff --git a/types/xml2js/index.d.ts b/types/xml2js/index.d.ts index 12d2488cbe..59af909a09 100644 --- a/types/xml2js/index.d.ts +++ b/types/xml2js/index.d.ts @@ -1,80 +1,78 @@ -// Type definitions for node-xml2js +// Type definitions for node-xml2js 0.4 // Project: https://github.com/Leonidas-from-XIV/node-xml2js -// Definitions by: Michel Salib , Jason McNeil , Christopher Currens , Edward Hinkle +// Definitions by: Michel Salib +// Jason McNeil +// Christopher Currens +// Edward Hinkle // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +/// +import { EventEmitter } from 'events'; -export = xml2js; +export function parseString(xml: convertableToString, callback: (err: any, result: any) => void): void; +export function parseString(xml: convertableToString, options: OptionsV2, callback: (err: any, result: any) => void): void; -import * as events from 'events' +export const defaults: { + '0.1': Options; + '0.2': OptionsV2; +}; -declare namespace xml2js { - function parseString(xml: convertableToString, callback: (err: any, result: any) => void): void; - function parseString(xml: convertableToString, options: OptionsV2, callback: (err: any, result: any) => void): void; +export class Builder { + constructor(options?: OptionsV2); + buildObject(rootObj: any): string; +} - var defaults: { - '0.1': Options; - '0.2': OptionsV2; - } +export class Parser extends EventEmitter { + constructor(options?: OptionsV2); + parseString(str: convertableToString, cb?: Function): void; + reset(): void; +} - class Builder { - constructor(options?: OptionsV2); - buildObject(rootObj: any): string; - } +export interface Options { + async?: boolean; + attrkey?: string; + attrNameProcessors?: [(name: string) => any]; + attrValueProcessors?: [(name: string) => any]; + charkey?: string; + charsAsChildren?: boolean; + childkey?: string; + emptyTag?: any; + explicitArray?: boolean; + explicitCharkey?: boolean; + explicitChildren?: boolean; + explicitRoot?: boolean; + ignoreAttrs?: boolean; + includeWhiteChars?: boolean; + mergeAttrs?: boolean; + normalize?: boolean; + normalizeTags?: boolean; + strict?: boolean; + tagNameProcessors?: [(name: string) => any]; + trim?: boolean; + validator?: Function; + valueProcessors?: [(name: string) => any]; + xmlns?: boolean; +} - class Parser extends events.EventEmitter { - constructor(options?: OptionsV2); - parseString(str: convertableToString, cb?: Function): void; - reset(): void; - } +export interface OptionsV2 extends Options { + preserveChildrenOrder?: boolean; + rootName?: string; + xmldec?: { + version: string; + encoding?: string; + standalone?: boolean; + }; + doctype?: any; + renderOpts?: { + pretty?: boolean; + indent?: string; + newline?: string; + }; + headless?: boolean; + chunkSize?: number; + cdata?: boolean; +} - interface Options { - async?: boolean; - attrkey?: string; - attrNameProcessors?: [(name: string) => any]; - attrValueProcessors?: [(name: string) => any]; - charkey?: string; - charsAsChildren?: boolean; - childkey?: string; - emptyTag?: any; - explicitArray?: boolean; - explicitCharkey?: boolean; - explicitChildren?: boolean; - explicitRoot?: boolean; - ignoreAttrs?: boolean; - includeWhiteChars?: boolean; - mergeAttrs?: boolean; - normalize?: boolean; - normalizeTags?: boolean; - strict?: boolean; - tagNameProcessors?: [(name: string) => any]; - trim?: boolean; - validator?: Function; - valueProcessors?: [(name: string) => any]; - xmlns?: boolean; - } - - interface OptionsV2 extends Options { - preserveChildrenOrder?: boolean; - rootName?: string; - xmldec?: { - version: string; - encoding?: string; - standalone?: boolean; - }; - doctype?: any; - renderOpts?: { - pretty?: boolean; - indent?: string; - newline?: string; - }; - headless?: boolean; - chunkSize?: number; - cdata?: boolean; - } - - interface convertableToString { - toString(): string; - } +export interface convertableToString { + toString(): string; } diff --git a/types/xml2js/lib/processors.d.ts b/types/xml2js/lib/processors.d.ts new file mode 100644 index 0000000000..e767cca99d --- /dev/null +++ b/types/xml2js/lib/processors.d.ts @@ -0,0 +1,9 @@ +export function firstCharLowerCase(name: string): string; + +export function normalize(name: string): string; + +export function parseBooleans(name: string): boolean; + +export function parseNumbers(name: string): number; + +export function stripPrefix(name: string): string; diff --git a/types/xml2js/processors.d.ts b/types/xml2js/processors.d.ts deleted file mode 100644 index 008a56964f..0000000000 --- a/types/xml2js/processors.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare module 'xml2js/lib/processors' { - export function firstCharLowerCase(name: string): string; - - export function normalize(name: string): string; - - export function parseBooleans(name: string): boolean; - - export function parseNumbers(name: string): number; - - export function stripPrefix(name: string): string; -} diff --git a/types/xml2js/tsconfig.json b/types/xml2js/tsconfig.json index 0449642c2f..7c5f5d51f5 100644 --- a/types/xml2js/tsconfig.json +++ b/types/xml2js/tsconfig.json @@ -17,6 +17,7 @@ }, "files": [ "index.d.ts", + "lib/processors.d.ts", "xml2js-tests.ts" ] } \ No newline at end of file diff --git a/types/xml2js/tslint.json b/types/xml2js/tslint.json new file mode 100644 index 0000000000..0481faf67d --- /dev/null +++ b/types/xml2js/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + // All TODOs + "ban-types": false + } +} diff --git a/types/xml2js/xml2js-tests.ts b/types/xml2js/xml2js-tests.ts index 8ee7b7ce25..4ee1c04e5a 100644 --- a/types/xml2js/xml2js-tests.ts +++ b/types/xml2js/xml2js-tests.ts @@ -1,7 +1,6 @@ -/// - import xml2js = require('xml2js'); import * as processors from 'xml2js/lib/processors'; +import fs = require('fs'); xml2js.parseString('Hello xml2js!', (err: any, result: any) => { }); @@ -40,13 +39,13 @@ xml2js.parseString('Hello xml2js!', { valueProcessors: [processors.parseBooleans, processors.parseNumbers] }, (err: any, result: any) => { }); -var builder = new xml2js.Builder({ +let builder = new xml2js.Builder({ renderOpts: { pretty: false } }); -var builder = new xml2js.Builder({ +builder = new xml2js.Builder({ rootName: 'root', renderOpts: { pretty: true, @@ -63,29 +62,27 @@ var builder = new xml2js.Builder({ cdata: false }); -var outString = builder.buildObject({ - 'hello': 'xml2js!' +const outString = builder.buildObject({ + hello: 'xml2js!' }); -var parser = new xml2js.Parser(); +const parser = new xml2js.Parser(); parser.on('end', (result: any) => { console.log("Parser Finished"); return; }); -var v1Defaults = xml2js.defaults['0.1']; +const v1Defaults = xml2js.defaults['0.1']; v1Defaults.async = true; -var v2Defaults = xml2js.defaults['0.2']; +const v2Defaults = xml2js.defaults['0.2']; v2Defaults.async = false; v2Defaults.chunkSize = 20000; -import fs = require('fs'); -  -fs.readFile(__dirname + '/foo.xml', function(err, data) { -    parser.parseString(data, function (err: any, result: any) { -        console.dir(result); -        console.log('Done'); -    }); -}); \ No newline at end of file +fs.readFile(__dirname + '/foo.xml', (err, data) => { + parser.parseString(data, (err: any, result: any) => { + console.dir(result); + console.log('Done'); + }); +});