From 7531e4e98e9751f20ceb80f8a25d5d8312cb4d41 Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Thu, 10 May 2018 15:01:14 -0500 Subject: [PATCH] [natural-sort] Make definitions and tests match module (#25670) The module is a function that takes options and returns a sort function. It is not the sort function itself. The sort function also works on any mixture of numbers and strings, as the module's own usage examples show. The tests are just the usage examples verbatim. --- types/natural-sort/index.d.ts | 11 ++++++++++- types/natural-sort/natural-sort-tests.ts | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/types/natural-sort/index.d.ts b/types/natural-sort/index.d.ts index 4e929d4edc..3a88919a25 100644 --- a/types/natural-sort/index.d.ts +++ b/types/natural-sort/index.d.ts @@ -1,9 +1,18 @@ // Type definitions for NaturalSort // Project: https://github.com/studio-b12/natural-sort // Definitions by: Antonio Morales +// Brian Crowell // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export as namespace naturalSort; -declare function naturalSort(a: T, b: T): number; +interface Options { + /** Set to true to make the sort case-sensitive. */ + caseSensitive?: boolean; + + /** Set to 'desc' to sort in reverse. */ + direction?: 'desc' +} + +declare function naturalSort(options?: Options): (a: string | number, b: string | number) => number; export = naturalSort; diff --git a/types/natural-sort/natural-sort-tests.ts b/types/natural-sort/natural-sort-tests.ts index b336542520..6218f4e796 100644 --- a/types/natural-sort/natural-sort-tests.ts +++ b/types/natural-sort/natural-sort-tests.ts @@ -1,5 +1,8 @@ import naturalSort = require("natural-sort"); -[5, 3, 2, 4, 1].sort(naturalSort); -["a", "c", "b", "z", "w", "l"].sort(naturalSort); +['10. tenth', 'odd', 1, '', '2. second'].sort(naturalSort()); +[3, 4, 1, 5, 2].sort(naturalSort({direction: 'desc'})); + +['a', 'B'].sort(naturalSort()); +['a', 'B'].sort(naturalSort({caseSensitive: true}));