diff --git a/types/qs/index.d.ts b/types/qs/index.d.ts index 400cc7a1e4..d3574383a5 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) => string; + format?: 'RFC1738' | 'RFC3986'; + encodeValuesOnly?: boolean; } interface IParseOptions { diff --git a/types/qs/qs-tests.ts b/types/qs/qs-tests.ts index f3e5ca3230..d71aa55957 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().toString(); } }), + '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'); +} diff --git a/types/qs/tsconfig.json b/types/qs/tsconfig.json index 13f816338d..624bdc72f2 100644 --- a/types/qs/tsconfig.json +++ b/types/qs/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "qs-tests.ts" ] -} \ No newline at end of file +}