Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/javve/natural-sort
Natural sort algorithm with unicode support written by Jim Palmer
https://github.com/javve/natural-sort
Last synced: about 1 month ago
JSON representation
Natural sort algorithm with unicode support written by Jim Palmer
- Host: GitHub
- URL: https://github.com/javve/natural-sort
- Owner: javve
- Created: 2013-03-14T10:36:13.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-01-07T10:56:56.000Z (almost 9 years ago)
- Last Synced: 2024-04-14T09:10:12.767Z (7 months ago)
- Language: HTML
- Size: 10.7 KB
- Stars: 39
- Watchers: 5
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
![web component logo](http://i49.tinypic.com/e7nj9v.png)
# Natural sort algorithm with unicode support
The algorithm is written by [Jim Palmer](http://www.linkedin.com/in/jimbob)
and found at [http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/](http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/).I, [javve](http://github.com/javve), only put it into a Component.
## Installation
$ component install javve/natural-sort
## Example
```js
var naturalSort = require('natural-sort');var values = ['B', 'a', 'D', 'c'];
values.sort(naturalSort); // ['B', 'D', 'a', 'c']
values.sort(function(a, b) {
return naturalSort(a, b, { insensitive: true });
}); // ['a', 'B', 'c', 'D']values.sort(function(a, b) {
return naturalSort(a, b, { insensitive: true, desc: true })
}); // ['D', 'c', 'B', 'a']var values = [
{ val: 'B' },
{ val: 'a' },
{ val: 'D' },
{ val: 'c' }
];values.sort(function(a, b) {
return naturalSort(a.val, b.val, { insensitive: true });
}); // ['a', 'B', 'c', 'D']```
Find more examples at [http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/](http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/)
or look at the tests in `/test`. It's quite impressive. Handles dates, etc.## License
MIT