From 86e8ab2ca2ea3deb4d398af960a226d76f80ca35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez?= Date: Fri, 25 Nov 2016 22:52:45 -0600 Subject: [PATCH] Expose provided processors living in xml2js/lib/processors --- xml2js/index.d.ts | 11 +++++------ xml2js/processors.d.ts | 11 +++++++++++ xml2js/xml2js-tests.ts | 8 ++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 xml2js/processors.d.ts diff --git a/xml2js/index.d.ts b/xml2js/index.d.ts index b23ebbbac2..f40aa93cb6 100644 --- a/xml2js/index.d.ts +++ b/xml2js/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Michel Salib , Jason McNeil , Christopher Currens // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - +/// 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; } } - diff --git a/xml2js/processors.d.ts b/xml2js/processors.d.ts new file mode 100644 index 0000000000..008a56964f --- /dev/null +++ b/xml2js/processors.d.ts @@ -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; +} diff --git a/xml2js/xml2js-tests.ts b/xml2js/xml2js-tests.ts index e0bea8cf9b..62324b6908 100644 --- a/xml2js/xml2js-tests.ts +++ b/xml2js/xml2js-tests.ts @@ -1,6 +1,7 @@ /// import xml2js = require('xml2js'); +import * as processors from 'xml2js/lib/processors'; xml2js.parseString('Hello xml2js!', (err: any, result: any) => { }); @@ -32,6 +33,13 @@ xml2js.parseString('Hello xml2js!', { valueProcessors: undefined }, (err: any, result: any) => { }); +xml2js.parseString('Hello xml2js!', { + 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