From d581cd13ab2425f27373d4e220932ce9b26bd315 Mon Sep 17 00:00:00 2001 From: Belinda Teh Date: Mon, 6 Mar 2017 16:43:00 -0800 Subject: [PATCH] Update qs definitions to include 'sort' in its stringify options --- qs/index.d.ts | 4 +++- qs/qs-tests.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/qs/index.d.ts b/qs/index.d.ts index c23c02f871..400cc7a1e4 100644 --- a/qs/index.d.ts +++ b/qs/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for qs 6.2.0 // Project: https://github.com/hapijs/qs -// Definitions by: Roman Korneev , Leon Yu +// Definitions by: Roman Korneev , Leon Yu , +// Belinda Teh // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export = QueryString; @@ -16,6 +17,7 @@ declare namespace QueryString { filter?: Array | ((prefix: string, value: any) => any); arrayFormat?: 'indices' | 'brackets' | 'repeat'; indices?: boolean; + sort?: (a: any, b: any) => number; } interface IParseOptions { diff --git a/qs/qs-tests.ts b/qs/qs-tests.ts index bcff0a0762..f3d361476e 100644 --- a/qs/qs-tests.ts +++ b/qs/qs-tests.ts @@ -249,3 +249,8 @@ qs.parse('a=b&c=d', { delimiter: '&' }); var obj = qs.parse('a=%82%B1%82%F1%82%C9%82%BF%82%CD%81I', { decoder: decoder }); assert.deepEqual(obj, { a: 'こんにちは!' }); } + +() => { + 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') +}