diff --git a/node/node-tests.ts b/node/node-tests.ts index 4ca651b333..aa0f55bb69 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -239,16 +239,47 @@ ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error, bytes: numb }); //////////////////////////////////////////////////// -///Querystring tests : https://gist.github.com/musubu/2202583 +///Querystring tests : https://nodejs.org/api/querystring.html //////////////////////////////////////////////////// -var original: string = 'http://example.com/product/abcde.html'; -var escaped: string = querystring.escape(original); -console.log(escaped); -// http%3A%2F%2Fexample.com%2Fproduct%2Fabcde.html -var unescaped: string = querystring.unescape(escaped); -console.log(unescaped); -// http://example.com/product/abcde.html +module querystring_tests { + type SampleObject = {a: string; b: number;} + + { + let obj: SampleObject; + let sep: string; + let eq: string; + let options: querystring.StringifyOptions; + let result: string; + + result = querystring.stringify(obj); + result = querystring.stringify(obj, sep); + result = querystring.stringify(obj, sep, eq); + result = querystring.stringify(obj, sep, eq); + result = querystring.stringify(obj, sep, eq, options); + } + + { + let str: string; + let sep: string; + let eq: string; + let options: querystring.ParseOptions; + let result: SampleObject; + + result = querystring.parse(str); + result = querystring.parse(str, sep); + result = querystring.parse(str, sep, eq); + result = querystring.parse(str, sep, eq, options); + } + + { + let str: string; + let result: string; + + result = querystring.escape(str); + result = querystring.unescape(str); + } +} //////////////////////////////////////////////////// /// path tests : http://nodejs.org/api/path.html diff --git a/node/node.d.ts b/node/node.d.ts index 39be040a49..34e6ffedcd 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -405,8 +405,18 @@ declare module "buffer" { } declare module "querystring" { - export function stringify(obj: any, sep?: string, eq?: string): string; - export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; + export interface StringifyOptions { + encodeURIComponent?: Function; + } + + export interface ParseOptions { + maxKeys?: number; + decodeURIComponent?: Function; + } + + export function stringify(obj: T, sep?: string, eq?: string, options?: StringifyOptions): string; + export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): any; + export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): T; export function escape(str: string): string; export function unescape(str: string): string; }