Merge pull request #12925 from alejo90/xml2js-processors

[@types/xml2js] Expose provided processors living in xml2js/lib/processors
This commit is contained in:
Paul van Brenk
2016-11-30 10:49:09 -08:00
committed by GitHub
3 changed files with 24 additions and 6 deletions

11
xml2js/index.d.ts vendored
View File

@@ -3,7 +3,7 @@
// Definitions by: Michel Salib <https://github.com/michelsalib>, Jason McNeil <https://github.com/jasonrm>, Christopher Currens <https://github.com/ccurrens>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="./processors.d.ts" />
export = xml2js;
@@ -30,8 +30,8 @@ declare namespace xml2js {
interface Options {
async?: boolean;
attrkey?: string;
attrNameProcessors?: [(name: string) => string];
attrValueProcessors?: [(name: string) => string];
attrNameProcessors?: [(name: string) => any];
attrValueProcessors?: [(name: string) => any];
charkey?: string;
charsAsChildren?: boolean;
childkey?: string;
@@ -46,10 +46,10 @@ declare namespace xml2js {
normalize?: boolean;
normalizeTags?: boolean;
strict?: boolean;
tagNameProcessors?: [(name: string) => string];
tagNameProcessors?: [(name: string) => any];
trim?: boolean;
validator?: Function;
valueProcessors?: [(name: string) => string];
valueProcessors?: [(name: string) => any];
xmlns?: boolean;
}
@@ -76,4 +76,3 @@ declare namespace xml2js {
toString(): string;
}
}

11
xml2js/processors.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
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;
}

View File

@@ -1,6 +1,7 @@
/// <reference types="node"/>
import xml2js = require('xml2js');
import * as processors from 'xml2js/lib/processors';
xml2js.parseString('<root>Hello xml2js!</root>', (err: any, result: any) => { });
@@ -32,6 +33,13 @@ xml2js.parseString('<root>Hello xml2js!</root>', {
valueProcessors: undefined
}, (err: any, result: any) => { });
xml2js.parseString('<root>Hello xml2js!</root>', {
attrNameProcessors: [processors.firstCharLowerCase],
attrValueProcessors: [processors.normalize],
tagNameProcessors: [processors.stripPrefix],
valueProcessors: [processors.parseBooleans, processors.parseNumbers]
}, (err: any, result: any) => { });
var builder = new xml2js.Builder({
renderOpts: {
pretty: false