$ cnpm install natural-sort
Sorting with support for numbers, dates, unicode and more.
['10. tenth', 'odd', 1, '', '2. second'].sort(naturalSort())
// [1, '2. second', '10. tenth', 'odd', '']
[3, 4, 1, 5, 2].sort(naturalSort({direction: 'desc'}))
// [5, 4, 3, 2, 1]
['a', 'B'].sort(naturalSort())
// ['a', 'B']
['a', 'B'].sort(naturalSort({caseSensitive: true}))
// ['B', 'a']
npm install natural-sort
bower install natural-sort
<script src="/bower_components/natural-sort/dist/natural-sort.js"></script>
The original version of this algorithm was published by Jim Palmer in this blog post.
Copyright 2013 - present © cnpmjs.org | Home |