[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.
This commit is contained in:
Brian Crowell
2018-05-10 15:01:14 -05:00
committed by Sheetal Nandi
parent 44252be6ab
commit 7531e4e98e
2 changed files with 15 additions and 3 deletions

View File

@@ -1,9 +1,18 @@
// Type definitions for NaturalSort
// Project: https://github.com/studio-b12/natural-sort
// Definitions by: Antonio Morales <https://github.com/a-morales>
// Brian Crowell <https://github.com/fluggo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export as namespace naturalSort;
declare function naturalSort<T>(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;

View File

@@ -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}));