Expose provided processors living in xml2js/lib/processors

This commit is contained in:
Alejandro Sánchez 2016-11-25 22:52:45 -06:00
parent e7ee7e5060
commit 86e8ab2ca2
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;
@ -29,8 +29,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;
@ -45,10 +45,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;
}
@ -75,4 +75,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