mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-10 09:40:21 +08:00
[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:
committed by
Sheetal Nandi
parent
44252be6ab
commit
7531e4e98e
11
types/natural-sort/index.d.ts
vendored
11
types/natural-sort/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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}));
|
||||
|
||||
Reference in New Issue
Block a user