0
|
1 ### Simple numerics
|
|
2
|
|
3 ```javascript
|
|
4 >>> ['10',9,2,'1','4'].sort(naturalSort)
|
|
5 ['1',2,'4',9,'10']
|
|
6 ```
|
|
7
|
|
8 ### Floats
|
|
9
|
|
10 ```javascript
|
|
11 >>> ['10.0401',10.022,10.042,'10.021999'].sort(naturalSort)
|
|
12 ['10.021999',10.022,'10.0401',10.042]
|
|
13 ```
|
|
14
|
|
15 ### Float & decimal notation
|
|
16
|
|
17 ```javascript
|
|
18 >>> ['10.04f','10.039F','10.038d','10.037D'].sort(naturalSort)
|
|
19 ['10.037D','10.038d','10.039F','10.04f']
|
|
20 ```
|
|
21
|
|
22 ### Scientific notation
|
|
23
|
|
24 ```javascript
|
|
25 >>> ['1.528535047e5','1.528535047e7','1.528535047e3'].sort(naturalSort)
|
|
26 ['1.528535047e3','1.528535047e5','1.528535047e7']
|
|
27 ```
|
|
28
|
|
29 ### IP addresses
|
|
30
|
|
31 ```javascript
|
|
32 >>> ['192.168.0.100','192.168.0.1','192.168.1.1'].sort(naturalSort)
|
|
33 ['192.168.0.1','192.168.0.100','192.168.1.1']
|
|
34 ```
|
|
35
|
|
36 ### Filenames
|
|
37
|
|
38 ```javascript
|
|
39 >>> ['car.mov','01alpha.sgi','001alpha.sgi','my.string_41299.tif'].sort(naturalSort)
|
|
40 ['001alpha.sgi','01alpha.sgi','car.mov','my.string_41299.tif'
|
|
41 ```
|
|
42
|
|
43 ### Dates
|
|
44
|
|
45 ```javascript
|
|
46 >>> ['10/12/2008','10/11/2008','10/11/2007','10/12/2007'].sort(naturalSort)
|
|
47 ['10/11/2007', '10/12/2007', '10/11/2008', '10/12/2008']
|
|
48 ```
|
|
49
|
|
50 ### Money
|
|
51
|
|
52 ```javascript
|
|
53 >>> ['$10002.00','$10001.02','$10001.01'].sort(naturalSort)
|
|
54 ['$10001.01','$10001.02','$10002.00']
|
|
55 ```
|
|
56
|
|
57 ### Movie Titles
|
|
58
|
|
59 ```javascript
|
|
60 >>> ['1 Title - The Big Lebowski','1 Title - Gattaca','1 Title - Last Picture Show'].sort(naturalSort)
|
|
61 ['1 Title - Gattaca','1 Title - Last Picture Show','1 Title - The Big Lebowski']
|
|
62 ```
|
|
63
|
|
64 ### By default - case-sensitive sorting
|
|
65
|
|
66 ```javascript
|
|
67 >>> ['a', 'B'].sort(naturalSort);
|
|
68 ['B', 'a']
|
|
69 ```
|
|
70
|
|
71 ### To enable case-insensitive sorting
|
|
72 ```javascript
|
|
73 >>> naturalSort.insensitive = true;
|
|
74 >>> ['a', 'B'].sort(naturalSort);
|
|
75 ['a', 'B']
|
|
76 ```
|