From 0b503ea34ba9faad250b052a4b32ebbc8260843e Mon Sep 17 00:00:00 2001 From: Melvin Lee Date: Wed, 28 Jun 2017 00:29:06 +0800 Subject: [PATCH] Update qs to 6.4.0 --- types/qs/index.d.ts | 13 +++++++++---- types/qs/qs-tests.ts | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/types/qs/index.d.ts b/types/qs/index.d.ts index 400cc7a1e4..b4f27c1304 100644 --- a/types/qs/index.d.ts +++ b/types/qs/index.d.ts @@ -1,7 +1,9 @@ -// Type definitions for qs 6.2.0 -// Project: https://github.com/hapijs/qs -// Definitions by: Roman Korneev , Leon Yu , -// Belinda Teh +// Type definitions for qs 6.4.0 +// Project: https://github.com/ljharb/qs +// Definitions by: Roman Korneev +// Leon Yu +// Belinda Teh +// Melvin Lee // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export = QueryString; @@ -18,6 +20,9 @@ declare namespace QueryString { arrayFormat?: 'indices' | 'brackets' | 'repeat'; indices?: boolean; sort?: (a: any, b: any) => number; + serializeDate?: (d: Date) => any; + format?: 'RFC1738' | 'RFC3986'; + encodeValuesOnly?: boolean; } interface IParseOptions { diff --git a/types/qs/qs-tests.ts b/types/qs/qs-tests.ts index f3e5ca3230..3d21daa46c 100644 --- a/types/qs/qs-tests.ts +++ b/types/qs/qs-tests.ts @@ -254,3 +254,27 @@ qs.parse('a=b&c=d', { delimiter: '&' }); var sorted = qs.stringify({ a: 1, c: 3, b: 2 }, { sort: (a, b) => a.localeCompare(b) }) assert.equal(sorted, 'a=1&b=2&c=3') } + +() => { + var date = new Date(7); + assert.equal( + qs.stringify({ a: date }, { serializeDate: function (d) { return d.getTime(); } }), + 'a=7' + ); +} + +() => { + assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c'); +} + +() => { + assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c'); +} + +() => { + var encodedValues = qs.stringify( + { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] }, + { encodeValuesOnly: true } + ); + assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'); +}